2012-08-20 18:51:00 -07:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-08-19 09:41:47 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediaBrowser.Controller.Events;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.TV.Entities;
|
|
|
|
|
using MediaBrowser.TV.Metadata;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.TV.Providers
|
|
|
|
|
{
|
|
|
|
|
[Export(typeof(BaseMetadataProvider))]
|
|
|
|
|
public class EpisodeProviderFromXml : BaseMetadataProvider
|
|
|
|
|
{
|
2012-08-19 13:38:31 -07:00
|
|
|
|
public override bool Supports(BaseEntity item)
|
2012-08-19 09:41:47 -07:00
|
|
|
|
{
|
|
|
|
|
return item is Episode;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 08:55:05 -07:00
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.First; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-21 19:50:59 -07:00
|
|
|
|
public override Task FetchAsync(BaseEntity item, ItemResolveEventArgs args)
|
2012-08-19 09:41:47 -07:00
|
|
|
|
{
|
2012-08-21 19:50:59 -07:00
|
|
|
|
return Fetch(item, args);
|
|
|
|
|
}
|
2012-08-19 13:38:31 -07:00
|
|
|
|
|
2012-08-21 19:50:59 -07:00
|
|
|
|
private Task Fetch(BaseEntity item, ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
string metadataFolder = Path.Combine(args.Parent.Path, "metadata");
|
2012-08-19 09:41:47 -07:00
|
|
|
|
|
2012-08-21 19:50:59 -07:00
|
|
|
|
string metadataFile = Path.Combine(metadataFolder, Path.ChangeExtension(Path.GetFileName(args.Path), ".xml"));
|
2012-08-19 09:41:47 -07:00
|
|
|
|
|
2012-08-21 19:50:59 -07:00
|
|
|
|
return FetchMetadata(item as Episode, args.Parent as Season, metadataFile);
|
2012-08-19 09:41:47 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 05:26:08 -07:00
|
|
|
|
private async Task FetchMetadata(Episode item, Season season, string metadataFile)
|
2012-08-19 09:41:47 -07:00
|
|
|
|
{
|
|
|
|
|
if (season == null)
|
|
|
|
|
{
|
|
|
|
|
// Episode directly in Series folder
|
|
|
|
|
// Need to validate it the slow way
|
|
|
|
|
if (!File.Exists(metadataFile))
|
|
|
|
|
{
|
2012-08-23 05:26:08 -07:00
|
|
|
|
await Task.FromResult<object>(null).ConfigureAwait(false);
|
2012-08-19 09:41:47 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-08-20 18:51:00 -07:00
|
|
|
|
if (!season.ContainsMetadataFile(metadataFile))
|
2012-08-19 09:41:47 -07:00
|
|
|
|
{
|
2012-08-23 05:26:08 -07:00
|
|
|
|
await Task.FromResult<object>(null).ConfigureAwait(false);
|
2012-08-19 09:41:47 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 05:26:08 -07:00
|
|
|
|
await Task.Run(() => { new EpisodeXmlParser().Fetch(item, metadataFile); }).ConfigureAwait(false);
|
2012-08-19 09:41:47 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|