2012-08-19 09:41:47 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel.Composition;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
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-19 13:38:31 -07:00
|
|
|
|
public async override Task Fetch(BaseEntity item, ItemResolveEventArgs args)
|
2012-08-19 09:41:47 -07:00
|
|
|
|
{
|
2012-08-19 09:54:41 -07:00
|
|
|
|
string metadataFolder = Path.Combine(args.Parent.Path, "metadata");
|
2012-08-19 09:41:47 -07:00
|
|
|
|
|
2012-08-19 13:38:31 -07:00
|
|
|
|
Episode episode = item as Episode;
|
|
|
|
|
|
|
|
|
|
string episodeFileName = Path.GetFileName(episode.Path);
|
2012-08-19 09:41:47 -07:00
|
|
|
|
|
2012-08-19 09:54:41 -07:00
|
|
|
|
string metadataFile = Path.Combine(metadataFolder, Path.ChangeExtension(episodeFileName, ".xml"));
|
2012-08-19 09:41:47 -07:00
|
|
|
|
|
2012-08-20 14:48:11 -07:00
|
|
|
|
await FetchMetadata(episode, args.Parent as Season, metadataFile).ConfigureAwait(false);
|
2012-08-19 09:41:47 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 09:54:41 -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))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!season.MetadataFiles.Any(s => s.Equals(metadataFile, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 14:48:11 -07:00
|
|
|
|
await Task.Run(() => { new EpisodeXmlParser().Fetch(item, metadataFile); }).ConfigureAwait(false);
|
2012-08-19 09:41:47 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|