From ebbd61a88c1828e5bc2f4c2c111a550e9602a46c Mon Sep 17 00:00:00 2001 From: HaraldNordgren Date: Mon, 5 Oct 2026 19:18:55 -0400 Subject: Backport pull request #18255 from jellyfin/release-12.z Recognize numbered sample and trailer files as extras Original-merge: b69a53578821e4e8136892615d5d62b7095e8b21 Merged-by: crobibero Backported-by: Cody Robibero --- Emby.Naming/Video/ExtraRuleResolver.cs | 4 ++-- tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs | 3 +++ .../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 pathSpan = path.AsSpan(); ReadOnlySpan fileName = Path.GetFileName(pathSpan); ReadOnlySpan 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 trimmedFileNameWithoutExtension = fileNameWithoutExtension.TrimEnd(_digits); ReadOnlySpan 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 @@ -91,6 +91,27 @@ public class MovieResolverTests Assert.Single(((Video)result.Items[0]).LocalAlternateVersions); } + [Fact] + public void ResolveMultiple_GivenNumberedSampleFiles_IgnoresSamples() + { + var movieResolver = new MovieResolver(Mock.Of(), Mock.Of>(), _namingOptions, Mock.Of(), _videoListResolver); + + var parent = new Folder { Path = "/movies/La Chimera (2023)" }; + var files = new List + { + 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()); + + Assert.NotNull(result); + var movie = Assert.Single(result.Items); + Assert.IsType(movie); + Assert.Equal(files[0].FullName, movie.Path); + } + [Fact] public void AllExtrasTypesFolderNames_ContainsSampleSingularAndPlural() { -- cgit v1.2.3