2012-08-19 15:58:35 +00: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 20:38:31 +00:00
|
|
|
|
public override bool Supports(BaseEntity item)
|
2012-08-19 15:58:35 +00:00
|
|
|
|
{
|
2012-08-19 20:38:31 +00:00
|
|
|
|
return item is BaseItem;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 15:55:05 +00:00
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.First; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 20:38:31 +00:00
|
|
|
|
public async override Task Fetch(BaseEntity item, ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
BaseItem baseItem = item as BaseItem;
|
|
|
|
|
|
2012-08-20 23:53:32 +00:00
|
|
|
|
var trailerPath = args.GetFileSystemEntryByName("trailers", true);
|
2012-08-19 15:58:35 +00: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 21:48:11 +00:00
|
|
|
|
BaseItem child = await Kernel.Instance.ItemController.GetItem(null, file).ConfigureAwait(false);
|
2012-08-19 15:58:35 +00:00
|
|
|
|
|
|
|
|
|
Video video = child as Video;
|
|
|
|
|
|
|
|
|
|
if (video != null)
|
|
|
|
|
{
|
|
|
|
|
localTrailers.Add(video);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 20:38:31 +00:00
|
|
|
|
baseItem.LocalTrailers = localTrailers;
|
2012-08-19 15:58:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|