2012-08-19 08:58:35 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.Composition;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediaBrowser.Controller.Events;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers
|
|
|
|
|
{
|
|
|
|
|
[Export(typeof(BaseMetadataProvider))]
|
|
|
|
|
public class LocalTrailerProvider : BaseMetadataProvider
|
|
|
|
|
{
|
2012-08-19 13:38:31 -07:00
|
|
|
|
public override bool Supports(BaseEntity item)
|
2012-08-19 08:58:35 -07:00
|
|
|
|
{
|
2012-08-19 13:38:31 -07:00
|
|
|
|
return item is BaseItem;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 08:55:05 -07:00
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.First; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 13:38:31 -07:00
|
|
|
|
public async override Task Fetch(BaseEntity item, ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
BaseItem baseItem = item as BaseItem;
|
|
|
|
|
|
2012-08-20 16:53:32 -07:00
|
|
|
|
var trailerPath = args.GetFileSystemEntryByName("trailers", true);
|
2012-08-19 08:58:35 -07:00
|
|
|
|
|
|
|
|
|
if (trailerPath.HasValue)
|
|
|
|
|
{
|
|
|
|
|
string[] allFiles = Directory.GetFileSystemEntries(trailerPath.Value.Key, "*", SearchOption.TopDirectoryOnly);
|
|
|
|
|
|
|
|
|
|
List<Video> localTrailers = new List<Video>();
|
|
|
|
|
|
|
|
|
|
foreach (string file in allFiles)
|
|
|
|
|
{
|
2012-08-20 14:48:11 -07:00
|
|
|
|
BaseItem child = await Kernel.Instance.ItemController.GetItem(null, file).ConfigureAwait(false);
|
2012-08-19 08:58:35 -07:00
|
|
|
|
|
|
|
|
|
Video video = child as Video;
|
|
|
|
|
|
|
|
|
|
if (video != null)
|
|
|
|
|
{
|
|
|
|
|
localTrailers.Add(video);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 13:38:31 -07:00
|
|
|
|
baseItem.LocalTrailers = localTrailers;
|
2012-08-19 08:58:35 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|