jellyfin/MediaBrowser.Controller/Providers/LocalTrailerProvider.cs

48 lines
1.5 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Threading.Tasks;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Providers
{
/// <summary>
/// Provides local trailers by checking the trailers subfolder
/// </summary>
[Export(typeof(BaseMetadataProvider))]
public class LocalTrailerProvider : BaseMetadataProvider
{
public override bool Supports(BaseEntity item)
{
return item is BaseItem;
}
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.First; }
}
2012-08-22 02:50:59 +00:00
public async override Task FetchAsync(BaseEntity item, ItemResolveEventArgs args)
{
if (args.ContainsFolder("trailers"))
{
List<Video> items = new List<Video>();
foreach (WIN32_FIND_DATA file in FileData.GetFileSystemEntries(Path.Combine(args.Path, "trailers"), "*"))
{
Video video = await Kernel.Instance.ItemController.GetItem(file.Path, fileInfo: file).ConfigureAwait(false) as Video;
if (video != null)
{
items.Add(video);
}
}
(item as BaseItem).LocalTrailers = items;
}
}
}
}