Fix resolved type for Trailers

pull/7044/head
Joe Rogers 2 years ago committed by Cody Robibero (Rebase PR Action)
parent 60e75f7b70
commit c0ab54f0bd

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

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

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

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

Loading…
Cancel
Save