mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-17 02:49:05 -07:00
62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
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; }
|
|
}
|
|
|
|
public override Task FetchAsync(BaseEntity item, ItemResolveEventArgs args)
|
|
{
|
|
return Fetch(item, args);
|
|
}
|
|
|
|
private Task Fetch(BaseEntity item, ItemResolveEventArgs args)
|
|
{
|
|
string metadataFolder = Path.Combine(args.Parent.Path, "metadata");
|
|
|
|
string metadataFile = Path.Combine(metadataFolder, Path.ChangeExtension(Path.GetFileName(args.Path), ".xml"));
|
|
|
|
return FetchMetadata(item as Episode, args.Parent as Season, metadataFile);
|
|
}
|
|
|
|
private async 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))
|
|
{
|
|
await Task.FromResult<object>(null).ConfigureAwait(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!season.ContainsMetadataFile(metadataFile))
|
|
{
|
|
await Task.FromResult<object>(null).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
await Task.Run(() => { new EpisodeXmlParser().Fetch(item, metadataFile); }).ConfigureAwait(false);
|
|
}
|
|
}
|
|
}
|