diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 388695cee5..a067eb640a 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -2649,6 +2649,7 @@ namespace Emby.Server.Implementations.Library if (dashIndexValue >= 0) { prefix = current.Name.Substring(0, dashIndexValue); // possible episode name + prefix = ParseName(prefix).Name; // clean name - remove all things in brackets etc string path = current.FullName; path = string.Concat(path.AsSpan(0, path.LastIndexOf('-')), current.Extension); var episodeInfo = resolver.Resolve(path, false); @@ -2686,8 +2687,8 @@ namespace Emby.Server.Implementations.Library } } - // if owner is Episode, only suffix type matches will be allowed, episode file name must match exactly - if (owner is not Episode || (prefix is not null && prefix.Equals(Path.GetFileNameWithoutExtension(ownerVideoInfo.Path), StringComparison.OrdinalIgnoreCase))) + // if owner is Episode, only suffix type matches will be allowed, episode file cleaned name must match + if (owner is not Episode || (prefix is not null && prefix.Equals(ownerVideoInfo.Name, StringComparison.OrdinalIgnoreCase))) { var extra = GetExtra(current, extraType.Value); if (extra is not null) diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs index 028c970aa4..347311a10c 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs @@ -311,6 +311,7 @@ public class FindExtrasTests { "/series/Dexter/Season 1/Dexter - S01E01.mkv", "/series/Dexter/Season 1/Dexter - S01E01-deleted.mkv", + "/series/Dexter/Season 1/Dexter - S01E01 [WEBDL-1080p AVC][AAC 2.0][YouTube]-deleted.mkv", "/series/Dexter/Season 1/Dexter - S01E02 - Second Epi.mkv", "/series/Dexter/Season 1/Dexter - S01E02 - Second Epi-interview.mkv", "/series/Dexter/Season 1/Dexter - S01E02 - Second Epi-scene.mkv", @@ -348,8 +349,10 @@ public class FindExtrasTests var owner = new Season { Name = "Season 1", SeriesName = "Dexter", Path = "/series/Dexter/Season 1" }; var paths = new List { - "/series/Dexter/Season 1/Dexter - S01E01.mkv", - "/series/Dexter/Season 1/Dexter - S01E01-deleted.mkv", + "/series/Dexter/Season 1/Dexter 1x01 [Bluray-1080p x264][AC3 5.1][-reward] - Northwest Passage.mkv", + "/series/Dexter/Season 1/Dexter 1x01-deleted.mkv", + "/series/Dexter/Season 1/Dexter 1x01 [WEBDL-1080p AVC][AAC 2.0][YouTube]-deleted.mkv", + "/series/Dexter/Season 1/Dexter 1x01 [WEBDL-1080p AVC][AAC 2.0][YouTube][-MrC] - Log Lady Introduction 1-extra.mkv", "/series/Dexter/Season 1/Dexter - S01E02 - Second Epi.mkv", "/series/Dexter/Season 1/Dexter - S01E02 - Second Epi-interview.mkv", "/series/Dexter/Season 1/Dexter - S01E02 - Second Epi-scene.mkv", @@ -484,4 +487,31 @@ public class FindExtrasTests Assert.Equal("/series/Dexter/Dexter - S03E05/Dexter - S03E05 - Fifth-featurette.mkv", extras[1].Path); Assert.Equal("/series/Dexter/Dexter - S03E05/Dexter - S03E05 - Fifth-featurette2.mkv", extras[2].Path); } + + [Fact] + public void FindExtras_EpisodeWithExtras_CleanNameTest() + { + var paths = new List + { + "/series/Dexter/Season 1/Dexter - S01E01[Bluray-1080p x264][AC3 5.1].mkv", + "/series/Dexter/Season 1/Dexter - S01E01 [WEBDL-1080p AVC][AAC 2.0][YouTube]-deleted.mkv", + "/series/Dexter/Season 1/Dexter - S01E01[Bluray-1080p x264][AC3 5.1] - Some crazy deleted scene -deleted.mkv" + }; + + var files = paths.Select(p => new FileSystemMetadata + { + FullName = p, + Name = Path.GetFileName(p), + Extension = Path.GetExtension(p), + IsDirectory = string.IsNullOrEmpty(Path.GetExtension(p)) + }).ToList(); + + var owner = new Episode { Name = "Dexter - S01E01", Path = "/series/Dexter/Season 1/Dexter - S01E01[Bluray-1080p x264][AC3 5.1].mkv", IsInMixedFolder = true }; + var extras = _libraryManager.FindExtras(owner, files, new DirectoryService(_fileSystemMock.Object)).OrderBy(e => e.ExtraType).ToList(); + + Assert.Equal(2, extras.Count); + Assert.Equal(ExtraType.DeletedScene, extras[0].ExtraType); + Assert.Equal(typeof(Video), extras[0].GetType()); + Assert.Equal("/series/Dexter/Season 1/Dexter - S01E01 [WEBDL-1080p AVC][AAC 2.0][YouTube]-deleted.mkv", extras[0].Path); + } }