2012-08-19 11:58:35 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel.Composition;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using MediaBrowser.Controller.Events;
|
2012-08-23 01:45:26 -04:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
2012-08-19 11:58:35 -04:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers
|
|
|
|
|
|
{
|
|
|
|
|
|
[Export(typeof(BaseMetadataProvider))]
|
|
|
|
|
|
public class LocalTrailerProvider : BaseMetadataProvider
|
|
|
|
|
|
{
|
2012-08-19 16:38:31 -04:00
|
|
|
|
public override bool Supports(BaseEntity item)
|
2012-08-19 11:58:35 -04:00
|
|
|
|
{
|
2012-08-19 16:38:31 -04:00
|
|
|
|
return item is BaseItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-08-20 11:55:05 -04:00
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return MetadataProviderPriority.First; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-08-21 22:50:59 -04:00
|
|
|
|
public async override Task FetchAsync(BaseEntity item, ItemResolveEventArgs args)
|
2012-08-19 16:38:31 -04:00
|
|
|
|
{
|
2012-08-23 01:45:26 -04:00
|
|
|
|
if (args.ContainsFolder("trailers"))
|
2012-08-19 11:58:35 -04:00
|
|
|
|
{
|
2012-08-23 01:45:26 -04:00
|
|
|
|
List<Video> items = new List<Video>();
|
2012-08-19 11:58:35 -04:00
|
|
|
|
|
2012-08-23 01:45:26 -04:00
|
|
|
|
foreach (WIN32_FIND_DATA file in FileData.GetFileSystemEntries(Path.Combine(args.Path, "trailers"), "*"))
|
2012-08-19 11:58:35 -04:00
|
|
|
|
{
|
2012-08-23 01:45:26 -04:00
|
|
|
|
Video video = await Kernel.Instance.ItemController.GetItem(file.Path, fileInfo: file).ConfigureAwait(false) as Video;
|
2012-08-19 11:58:35 -04:00
|
|
|
|
|
|
|
|
|
|
if (video != null)
|
|
|
|
|
|
{
|
2012-08-23 01:45:26 -04:00
|
|
|
|
items.Add(video);
|
2012-08-19 11:58:35 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-08-23 01:45:26 -04:00
|
|
|
|
(item as BaseItem).LocalTrailers = items;
|
2012-08-19 11:58:35 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|