The Free Software Media System - Server Backend & API
Backport pull request #18255 from jellyfin/release-12.z
HaraldNordgrenebbd61a88c18
diff --git a/Emby.Naming/Video/ExtraRuleResolver.cs b/Emby.Naming/Video/ExtraRuleResolver.csindex 2e0caa612f..7b0ef411e9 100644--- a/Emby.Naming/Video/ExtraRuleResolver.cs+++ b/Emby.Naming/Video/ExtraRuleResolver.cs@@ -30,7 +30,7 @@ namespace Emby.Naming.VideoReadOnlySpan<char> pathSpan = path.AsSpan();ReadOnlySpan<char> fileName = Path.GetFileName(pathSpan);ReadOnlySpan<char> fileNameWithoutExtension = Path.GetFileNameWithoutExtension(pathSpan);- // Trim the digits from the end of the filename so we can recognize things like -trailer2+ // Trim the digits from the end of the filename so we can recognize things like -trailer2 or sample1ReadOnlySpan<char> trimmedFileNameWithoutExtension = fileNameWithoutExtension.TrimEnd(_digits);ReadOnlySpan<char> directoryName = Path.GetFileName(Path.GetDirectoryName(pathSpan));string fullDirectory = Path.GetDirectoryName(pathSpan).ToString();@@ -45,7 +45,7 @@ namespace Emby.Naming.Videobool isMatch = rule.RuleType switch{- ExtraRuleType.Filename => fileNameWithoutExtension.Equals(rule.Token, StringComparison.OrdinalIgnoreCase),+ ExtraRuleType.Filename => trimmedFileNameWithoutExtension.Equals(rule.Token, StringComparison.OrdinalIgnoreCase),ExtraRuleType.Suffix => trimmedFileNameWithoutExtension.EndsWith(rule.Token, StringComparison.OrdinalIgnoreCase),ExtraRuleType.Regex => Regex.IsMatch(fileName, rule.Token, RegexOptions.IgnoreCase | RegexOptions.Compiled),ExtraRuleType.DirectoryName => directoryName.Equals(rule.Token, StringComparison.OrdinalIgnoreCase)diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.csindex 6d887c5771..fd93532ba6 100644--- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs+++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs@@ -32,6 +32,7 @@ namespace Jellyfin.Naming.Tests.Videopublic void TestExpandedExtras(){Test("trailer.mp4", ExtraType.Trailer);+ Test("trailer2.mp4", ExtraType.Trailer);Test("trailer.mp3", null);Test("300-trailer.mp4", ExtraType.Trailer);Test("stuff trailerthings.mkv", null);@@ -133,6 +134,8 @@ namespace Jellyfin.Naming.Tests.VideoTest("300.sample.mp4", ExtraType.Sample);Test("300_sample.mp4", ExtraType.Sample);Test("300 - sample.mp4", ExtraType.Sample);+ Test("sample1.mp4", ExtraType.Sample);+ Test("Sample2.mkv", ExtraType.Sample);}[Fact]diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/MovieResolverTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/MovieResolverTests.csindex 3aac3cdc43..743ac6055b 100644--- a/tests/Jellyfin.Server.Implementations.Tests/Library/MovieResolverTests.cs+++ b/tests/Jellyfin.Server.Implementations.Tests/Library/MovieResolverTests.cs@@ -91,6 +91,27 @@ public class MovieResolverTestsAssert.Single(((Video)result.Items[0]).LocalAlternateVersions);}+ [Fact]+ public void ResolveMultiple_GivenNumberedSampleFiles_IgnoresSamples()+ {+ var movieResolver = new MovieResolver(Mock.Of<IImageProcessor>(), Mock.Of<ILogger<MovieResolver>>(), _namingOptions, Mock.Of<IDirectoryService>(), _videoListResolver);++ var parent = new Folder { Path = "/movies/La Chimera (2023)" };+ var files = new List<FileSystemMetadata>+ {+ new() { FullName = "/movies/La Chimera (2023)/La Chimera (2023).mkv", Name = "La Chimera (2023).mkv", IsDirectory = false },+ new() { FullName = "/movies/La Chimera (2023)/Sample1.mkv", Name = "Sample1.mkv", IsDirectory = false },+ new() { FullName = "/movies/La Chimera (2023)/Sample2.mkv", Name = "Sample2.mkv", IsDirectory = false }+ };++ var result = movieResolver.ResolveMultiple(parent, files, CollectionType.movies, Mock.Of<IDirectoryService>());++ Assert.NotNull(result);+ var movie = Assert.Single(result.Items);+ Assert.IsType<Movie>(movie);+ Assert.Equal(files[0].FullName, movie.Path);+ }+[Fact]public void AllExtrasTypesFolderNames_ContainsSampleSingularAndPlural(){