jellyfin-server/MediaBrowser.TV/Providers/EpisodeProviderFromXml.cs

62 lines
1.9 KiB
C#
Raw Normal View History

using System.ComponentModel.Composition;
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
{
public override bool Supports(BaseEntity item)
{
return item is Episode;
}
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.First; }
}
2012-08-22 02:50:59 +00:00
public override Task FetchAsync(BaseEntity item, ItemResolveEventArgs args)
{
2012-08-22 02:50:59 +00:00
return Fetch(item, args);
}
2012-08-22 02:50:59 +00:00
private Task Fetch(BaseEntity item, ItemResolveEventArgs args)
{
string metadataFolder = Path.Combine(args.Parent.Path, "metadata");
2012-08-22 02:50:59 +00:00
string metadataFile = Path.Combine(metadataFolder, Path.ChangeExtension(Path.GetFileName(args.Path), ".xml"));
2012-08-22 02:50:59 +00:00
return FetchMetadata(item as Episode, args.Parent as Season, metadataFile);
}
2012-08-22 02:50:59 +00:00
private Task FetchMetadata(Episode item, Season season, string metadataFile)
{
if (season == null)
{
// Episode directly in Series folder
// Need to validate it the slow way
if (!File.Exists(metadataFile))
{
2012-08-22 02:50:59 +00:00
return Task.FromResult<object>(null);
}
}
else
{
if (!season.ContainsMetadataFile(metadataFile))
{
2012-08-22 02:50:59 +00:00
return Task.FromResult<object>(null);
}
}
2012-08-22 02:50:59 +00:00
return Task.Run(() => { new EpisodeXmlParser().Fetch(item, metadataFile); });
}
}
}