diff options
6 files changed, 72 insertions, 23 deletions
diff --git a/Emby.Naming/Common/NamingOptions.cs b/Emby.Naming/Common/NamingOptions.cs index aa62a47f1..c0be0b7c6 100644 --- a/Emby.Naming/Common/NamingOptions.cs +++ b/Emby.Naming/Common/NamingOptions.cs @@ -471,6 +471,12 @@ namespace Emby.Naming.Common MediaType.Video), new ExtraRule( + ExtraType.ThemeVideo, + ExtraRuleType.DirectoryName, + "backdrops", + MediaType.Video), + + new ExtraRule( ExtraType.ThemeSong, ExtraRuleType.Filename, "theme", diff --git a/Emby.Server.Implementations/Library/Resolvers/GenericVideoResolver.cs b/Emby.Server.Implementations/Library/Resolvers/GenericVideoResolver.cs deleted file mode 100644 index 72341d9db..000000000 --- a/Emby.Server.Implementations/Library/Resolvers/GenericVideoResolver.cs +++ /dev/null @@ -1,18 +0,0 @@ -#nullable disable - -#pragma warning disable CS1591 - -using Emby.Naming.Common; -using MediaBrowser.Controller.Entities; - -namespace Emby.Server.Implementations.Library.Resolvers -{ - public class GenericVideoResolver<T> : BaseVideoResolver<T> - where T : Video, new() - { - public GenericVideoResolver(NamingOptions namingOptions) - : base(namingOptions) - { - } - } -} diff --git a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 4feaf3fb4..1a9295dc8 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -105,10 +105,9 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies if (string.IsNullOrEmpty(collectionType)) { - // Owned items will be caught by the plain video resolver + // Owned items will be caught by the video extra resolver if (args.Parent == null) { - // return FindMovie<Video>(args.Path, args.Parent, files, args.DirectoryService, collectionType); return null; } @@ -129,10 +128,10 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies return movie?.ExtraType == null ? movie : null; } - // Handle owned items + // Owned items will be caught by the video extra resolver if (args.Parent == null) { - return base.Resolve(args); + return null; } if (IsInvalid(args.Parent, collectionType)) diff --git a/Emby.Server.Implementations/Library/Resolvers/VideoExtraResolver.cs b/Emby.Server.Implementations/Library/Resolvers/VideoExtraResolver.cs new file mode 100644 index 000000000..9aadce88c --- /dev/null +++ b/Emby.Server.Implementations/Library/Resolvers/VideoExtraResolver.cs @@ -0,0 +1,55 @@ +#nullable disable + +using Emby.Naming.Common; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Resolvers; +using MediaBrowser.Model.Entities; + +namespace Emby.Server.Implementations.Library.Resolvers +{ + /// <summary> + /// Resolves a Path into a Video or Video subclass. + /// </summary> + public class VideoExtraResolver : BaseVideoResolver<Video> + { + /// <summary> + /// Initializes a new instance of the <see cref="VideoExtraResolver"/> class. + /// </summary> + /// <param name="namingOptions">The naming options.</param> + public VideoExtraResolver(NamingOptions namingOptions) + : base(namingOptions) + { + } + + /// <summary> + /// Gets the priority. + /// </summary> + /// <value>The priority.</value> + public override ResolverPriority Priority => ResolverPriority.Last; + + /// <summary> + /// Resolves the specified args. + /// </summary> + /// <param name="args">The args.</param> + /// <returns>The video extra or null if not handled by this resolver.</returns> + public override Video Resolve(ItemResolveArgs args) + { + // Only handle owned items + if (args.Parent != null) + { + return null; + } + + var ownedItem = base.Resolve(args); + + // Re-resolve items that have their own type + if (ownedItem.ExtraType == ExtraType.Trailer) + { + ownedItem = ResolveVideo<Trailer>(args, false); + } + + return ownedItem; + } + } +} diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs index 8dd637559..24f9bf98d 100644 --- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs @@ -53,6 +53,7 @@ namespace Jellyfin.Naming.Tests.Video [InlineData(ExtraType.Sample, "samples")] [InlineData(ExtraType.Clip, "shorts")] [InlineData(ExtraType.Clip, "featurettes")] + [InlineData(ExtraType.ThemeVideo, "backdrops")] [InlineData(ExtraType.Unknown, "extras")] public void TestDirectories(ExtraType type, string dirName) { diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs index ccff95313..3ce29f28c 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs @@ -36,7 +36,7 @@ public class FindExtrasTests _fileSystemMock.Setup(f => f.GetFileInfo(It.IsAny<string>())).Returns<string>(path => new FileSystemMetadata { FullName = path }); _libraryManager = fixture.Build<Emby.Server.Implementations.Library.LibraryManager>().Do(s => s.AddParts( fixture.Create<IEnumerable<IResolverIgnoreRule>>(), - new List<IItemResolver> { new GenericVideoResolver<Video>(fixture.Create<NamingOptions>()), new AudioResolver(fixture.Create<NamingOptions>()) }, + new List<IItemResolver> { new VideoExtraResolver(fixture.Create<NamingOptions>()), new AudioResolver(fixture.Create<NamingOptions>()) }, fixture.Create<IEnumerable<IIntroProvider>>(), fixture.Create<IEnumerable<IBaseItemComparer>>(), fixture.Create<IEnumerable<ILibraryPostScanTask>>())) @@ -69,6 +69,7 @@ public class FindExtrasTests Assert.Equal(2, extras.Count); Assert.Equal(ExtraType.Trailer, extras[0].ExtraType); + Assert.Equal(typeof(Trailer), extras[0].GetType()); Assert.Equal(ExtraType.Sample, extras[1].ExtraType); } @@ -146,7 +147,9 @@ public class FindExtrasTests Assert.Equal(6, extras.Count); Assert.Equal(ExtraType.Trailer, extras[0].ExtraType); + Assert.Equal(typeof(Trailer), extras[0].GetType()); Assert.Equal(ExtraType.Trailer, extras[1].ExtraType); + Assert.Equal(typeof(Trailer), extras[1].GetType()); Assert.Equal(ExtraType.BehindTheScenes, extras[2].ExtraType); Assert.Equal(ExtraType.Sample, extras[3].ExtraType); Assert.Equal(ExtraType.ThemeSong, extras[4].ExtraType); @@ -174,6 +177,7 @@ public class FindExtrasTests Assert.Single(extras); Assert.Equal(ExtraType.Trailer, extras[0].ExtraType); + Assert.Equal(typeof(Trailer), extras[0].GetType()); Assert.Equal("trailer", extras[0].FileNameWithoutExtension); Assert.Equal("/movies/Up/trailer.mkv", extras[0].Path); } @@ -200,6 +204,7 @@ public class FindExtrasTests Assert.Single(extras); Assert.Equal(ExtraType.Trailer, extras[0].ExtraType); + Assert.Equal(typeof(Trailer), extras[0].GetType()); Assert.Equal("trailer", extras[0].FileNameWithoutExtension); Assert.Equal("/movies/Up/trailer.mkv", extras[0].Path); } @@ -225,6 +230,7 @@ public class FindExtrasTests Assert.Equal(2, extras.Count); Assert.Equal(ExtraType.Trailer, extras[0].ExtraType); + Assert.Equal(typeof(Trailer), extras[0].GetType()); Assert.Equal("trailer", extras[0].FileNameWithoutExtension); Assert.Equal("/series/Dexter/trailer.mkv", extras[0].Path); Assert.Equal("/series/Dexter/trailers/trailer2.mkv", extras[1].Path); |
