Merge pull request #7044 from 1337joe/fix-trailers-v2

Fix trailers v2
This commit is contained in:
Cody Robibero 2021-12-25 23:31:46 +00:00 committed by GitHub
commit a615f87680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 23 deletions

View File

@ -470,6 +470,12 @@ namespace Emby.Naming.Common
" sample",
MediaType.Video),
new ExtraRule(
ExtraType.ThemeVideo,
ExtraRuleType.DirectoryName,
"backdrops",
MediaType.Video),
new ExtraRule(
ExtraType.ThemeSong,
ExtraRuleType.Filename,

View File

@ -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)
{
}
}
}

View File

@ -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))

View File

@ -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;
}
}
}

View File

@ -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)
{

View File

@ -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);