diff options
| author | HaraldNordgren <haraldnordgren@gmail.com> | 2026-10-05 19:18:55 -0400 |
|---|---|---|
| committer | Cody Robibero <cody@robibe.ro> | 2026-10-05 19:18:55 -0400 |
| commit | ebbd61a88c1828e5bc2f4c2c111a550e9602a46c (patch) | |
| tree | 46c343478cad6124328646a5dc3ef6f6176e9f95 | |
| parent | f9613056ceed70d8c8d8c98f90cde5ac75097cb6 (diff) | |
Backport pull request #18255 from jellyfin/release-12.z
Recognize numbered sample and trailer files as extras
Original-merge: b69a53578821e4e8136892615d5d62b7095e8b21
Merged-by: crobibero <cody@robibe.ro>
Backported-by: Cody Robibero <cody@robibe.ro>
| -rw-r--r-- | Emby.Naming/Video/ExtraRuleResolver.cs | 4 | ||||
| -rw-r--r-- | tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs | 3 | ||||
| -rw-r--r-- | tests/Jellyfin.Server.Implementations.Tests/Library/MovieResolverTests.cs | 21 |
3 files changed, 26 insertions, 2 deletions
diff --git a/Emby.Naming/Video/ExtraRuleResolver.cs b/Emby.Naming/Video/ExtraRuleResolver.cs index 2e0caa612f..7b0ef411e9 100644 --- a/Emby.Naming/Video/ExtraRuleResolver.cs +++ b/Emby.Naming/Video/ExtraRuleResolver.cs @@ -30,7 +30,7 @@ namespace Emby.Naming.Video ReadOnlySpan<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 sample1 ReadOnlySpan<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.Video bool 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.cs index 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.Video public 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.Video Test("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.cs index 3aac3cdc43..743ac6055b 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Library/MovieResolverTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Library/MovieResolverTests.cs @@ -92,6 +92,27 @@ public class MovieResolverTests } [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() { Assert.True(_namingOptions.AllExtrasTypesFolderNames.ContainsKey("sample")); |
