diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2025-08-03 17:29:04 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-03 17:29:04 -0400 |
| commit | 0f5bb5cf767e8c5a767be32e26016cae17ae341c (patch) | |
| tree | eec847f0f735ecff7a4301a79e8e34023ccfe8b8 /tests | |
| parent | ce78af2ed4f203690a0f9ef87b08b27a6bd43f63 (diff) | |
| parent | 7785b51f572cf48a62dfc2ee60fc1db0ccedf1a2 (diff) | |
Merge pull request #14540 from TokerX/issue-8641
Improve extra rule resolution and file handling
Diffstat (limited to 'tests')
4 files changed, 140 insertions, 4 deletions
diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs index 51eb99f49..6d887c577 100644 --- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs @@ -23,7 +23,7 @@ namespace Jellyfin.Naming.Tests.Video Test("300-trailer.mp4", ExtraType.Trailer); Test("300.trailer.mp4", ExtraType.Trailer); Test("300_trailer.mp4", ExtraType.Trailer); - Test("300 trailer.mp4", ExtraType.Trailer); + Test("300 - trailer.mp4", ExtraType.Trailer); Test("theme.mp3", ExtraType.ThemeSong); } @@ -132,7 +132,14 @@ namespace Jellyfin.Naming.Tests.Video Test("300-sample.mp4", ExtraType.Sample); Test("300.sample.mp4", ExtraType.Sample); Test("300_sample.mp4", ExtraType.Sample); - Test("300 sample.mp4", ExtraType.Sample); + Test("300 - sample.mp4", ExtraType.Sample); + } + + [Fact] + public void TestSuffixPartOfTitle() + { + Test("I Live In A Trailer.mp4", null); + Test("The DNA Sample.mp4", null); } private void Test(string input, ExtraType? expectedType) diff --git a/tests/Jellyfin.Naming.Tests/Video/VideoListResolverTests.cs b/tests/Jellyfin.Naming.Tests/Video/VideoListResolverTests.cs index 377f82eac..d3164ba9c 100644 --- a/tests/Jellyfin.Naming.Tests/Video/VideoListResolverTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/VideoListResolverTests.cs @@ -87,7 +87,7 @@ namespace Jellyfin.Naming.Tests.Video var files = new[] { "300.mkv", - "300 trailer.mkv" + "300 - trailer.mkv" }; var result = VideoListResolver.Resolve( diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/CoreResolutionIgnoreRuleTest.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/CoreResolutionIgnoreRuleTest.cs new file mode 100644 index 000000000..0495c209d --- /dev/null +++ b/tests/Jellyfin.Server.Implementations.Tests/Library/CoreResolutionIgnoreRuleTest.cs @@ -0,0 +1,129 @@ +using System; +using System.IO; +using Emby.Naming.Common; +using Emby.Naming.Video; +using Emby.Server.Implementations.Library; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.IO; +using Moq; +using Xunit; + +namespace Jellyfin.Server.Implementations.Tests.Library; + +public class CoreResolutionIgnoreRuleTest +{ + private readonly CoreResolutionIgnoreRule _rule; + private readonly NamingOptions _namingOptions; + private readonly Mock<IServerApplicationPaths> _appPathsMock; + + public CoreResolutionIgnoreRuleTest() + { + _namingOptions = new NamingOptions(); + + _namingOptions.AllExtrasTypesFolderNames.TryAdd("extras", ExtraType.Trailer); + + _appPathsMock = new Mock<IServerApplicationPaths>(); + _appPathsMock.SetupGet(x => x.RootFolderPath).Returns("/server/root"); + + _rule = new CoreResolutionIgnoreRule(_namingOptions, _appPathsMock.Object); + } + + private FileSystemMetadata MakeFileSystemMetadata(string fullName, bool isDirectory = false) + => new FileSystemMetadata { FullName = fullName, Name = Path.GetFileName(fullName), IsDirectory = isDirectory }; + + private BaseItem MakeParent(string name = "Parent", bool isTopParent = false, Type? type = null) + { + return type switch + { + Type t when t == typeof(Folder) => CreateMock<Folder>(name, isTopParent).Object, + Type t when t == typeof(AggregateFolder) => CreateMock<AggregateFolder>(name, isTopParent).Object, + Type t when t == typeof(UserRootFolder) => CreateMock<UserRootFolder>(name, isTopParent).Object, + _ => CreateMock<BaseItem>(name, isTopParent).Object + }; + } + + private static Mock<T> CreateMock<T>(string name, bool isTopParent) + where T : BaseItem + { + var mock = new Mock<T>(); + mock.SetupGet(p => p.Name).Returns(name); + mock.SetupGet(p => p.IsTopParent).Returns(isTopParent); + return mock; + } + + [Fact] + public void TestApplicationFolder() + { + Assert.False(_rule.ShouldIgnore( + MakeFileSystemMetadata("/server/root/extras", isDirectory: true), + null)); + + Assert.False(_rule.ShouldIgnore( + MakeFileSystemMetadata("/server/root/small.jpg"), + null)); + } + + [Fact] + public void TestTopLevelDirectory() + { + Assert.False(_rule.ShouldIgnore( + MakeFileSystemMetadata("Series/Extras", true), + MakeParent(type: typeof(AggregateFolder)))); + + Assert.False(_rule.ShouldIgnore( + MakeFileSystemMetadata("Series/Extras/Extras", true), + MakeParent(isTopParent: true))); + } + + [Fact] + public void TestIgnorePatterns() + { + Assert.False(_rule.ShouldIgnore( + MakeFileSystemMetadata("/Media/big.jpg"), + MakeParent())); + + Assert.True(_rule.ShouldIgnore( + MakeFileSystemMetadata("/Media/small.jpg"), + MakeParent())); + } + + [Fact] + public void TestExtrasTypesFolderNames() + { + FileSystemMetadata fileSystemMetadata = MakeFileSystemMetadata("/Movies/Up/extras", true); + + Assert.False(_rule.ShouldIgnore( + fileSystemMetadata, + MakeParent(type: typeof(AggregateFolder)))); + + Assert.False(_rule.ShouldIgnore( + fileSystemMetadata, + MakeParent(type: typeof(UserRootFolder)))); + + Assert.False(_rule.ShouldIgnore( + fileSystemMetadata, + null)); + + Assert.True(_rule.ShouldIgnore( + fileSystemMetadata, + MakeParent())); + + Assert.True(_rule.ShouldIgnore( + fileSystemMetadata, + MakeParent(type: typeof(Folder)))); + } + + [Fact] + public void TestThemeSong() + { + Assert.False(_rule.ShouldIgnore( + MakeFileSystemMetadata("/Movies/Up/intro.mp3"), + MakeParent())); + + Assert.True(_rule.ShouldIgnore( + MakeFileSystemMetadata("/Movies/Up/theme.mp3"), + MakeParent())); + } +} diff --git a/tests/Jellyfin.Server.Implementations.Tests/Plugins/PluginManagerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Plugins/PluginManagerTests.cs index 6964c920b..3d8ea15a3 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Plugins/PluginManagerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Plugins/PluginManagerTests.cs @@ -301,7 +301,7 @@ namespace Jellyfin.Server.Implementations.Tests.Plugins var versionInfo = fixture.Create<VersionInfo>(); versionInfo.Version = new Version(1, 0).ToString(); - versionInfo.Timestamp = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture); + versionInfo.Timestamp = DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture); var packageInfo = fixture.Create<PackageInfo>(); packageInfo.Versions = new[] { versionInfo }; |
