jellyfin/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs

62 lines
2.0 KiB
C#
Raw Normal View History

2014-07-26 17:30:15 +00:00
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities;
2013-02-21 01:33:05 +00:00
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
2014-09-22 21:56:54 +00:00
using MediaBrowser.Model.Entities;
2013-02-21 01:33:05 +00:00
using System;
using System.IO;
2014-09-22 21:56:54 +00:00
using System.Linq;
2013-02-21 01:33:05 +00:00
namespace MediaBrowser.Server.Implementations.Library.Resolvers
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Class LocalTrailerResolver
/// </summary>
public class LocalTrailerResolver : BaseVideoResolver<Trailer>
2013-02-21 01:33:05 +00:00
{
2014-07-26 17:30:15 +00:00
private readonly IFileSystem _fileSystem;
public LocalTrailerResolver(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Resolves the specified args.
/// </summary>
/// <param name="args">The args.</param>
/// <returns>Trailer.</returns>
protected override Trailer Resolve(ItemResolveArgs args)
{
// Trailers are not Children, therefore this can never happen
if (args.Parent != null)
{
return null;
}
// If the file is within a trailers folder, see if the VideoResolver returns something
if (!args.IsDirectory)
{
if (string.Equals(Path.GetFileName(Path.GetDirectoryName(args.Path)), BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase))
{
return base.Resolve(args);
}
2013-05-20 17:04:39 +00:00
// Support xbmc local trailer convention, but only when looking for local trailers (hence the parent == null check)
2014-09-22 21:56:54 +00:00
if (args.Parent == null)
2013-05-20 17:04:39 +00:00
{
2014-09-22 21:56:54 +00:00
var nameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(args.Path);
var suffix = BaseItem.ExtraSuffixes.First(i => i.Value == ExtraType.Trailer);
if (nameWithoutExtension.EndsWith(suffix.Key, StringComparison.OrdinalIgnoreCase))
{
return base.Resolve(args);
}
2013-05-20 17:04:39 +00:00
}
2013-02-21 01:33:05 +00:00
}
return null;
}
}
}