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)
|
|
|
|
|
{
|
2012-08-21 03:56:28 +00:00
|
|
|
|
string[] allFiles = Directory.GetFileSystemEntries(trailerPath.Value.Path, "*", SearchOption.TopDirectoryOnly);
|
2012-08-19 15:58:35 +00:00
|
|
|
|
|
|
|
|
|
List<Video> localTrailers = new List<Video>();
|
|
|
|
|
|
2012-08-21 01:51:00 +00:00
|
|
|
|
for (int i = 0; i < allFiles.Length; i++)
|
2012-08-19 15:58:35 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
string file = allFiles[i];
|
|
|
|
|
|
2012-08-21 01:21:03 +00:00
|
|
|
|
BaseItem child = await Kernel.Instance.ItemController.GetItem(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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|