Backport pull request #18255 from jellyfin/release-12.z

Recognize numbered sample and trailer files as extras

Original-merge: b69a535788

Merged-by: crobibero <cody@robibe.ro>

Backported-by: Cody Robibero <cody@robibe.ro>
This commit is contained in:
HaraldNordgren authored and Cody Robibero committed 2026-10-05 19:18:55 -04:00
1 parent f9613056ce
commit ebbd61a88c
3 files changed
+26 -2

No files matched your search

+2 -2
View File
@@ -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)
@@ -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]
@@ -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<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()
{