2012-09-11 03:34:02 +02:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2012-09-08 21:05:18 +02:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-08-19 18:41:47 +02:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2012-09-08 21:05:18 +02:00
|
|
|
|
namespace MediaBrowser.Controller.Providers.TV
|
2012-08-19 18:41:47 +02:00
|
|
|
|
{
|
|
|
|
|
[Export(typeof(BaseMetadataProvider))]
|
|
|
|
|
public class EpisodeImageFromMediaLocationProvider : BaseMetadataProvider
|
|
|
|
|
{
|
2012-08-19 22:38:31 +02:00
|
|
|
|
public override bool Supports(BaseEntity item)
|
2012-08-19 18:41:47 +02:00
|
|
|
|
{
|
|
|
|
|
return item is Episode;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 17:55:05 +02:00
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.First; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 04:50:59 +02:00
|
|
|
|
public override Task FetchAsync(BaseEntity item, ItemResolveEventArgs args)
|
2012-08-19 18:41:47 +02:00
|
|
|
|
{
|
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2012-09-11 21:37:14 +02:00
|
|
|
|
var episode = item as Episode;
|
2012-08-19 22:38:31 +02:00
|
|
|
|
|
2012-08-19 18:41:47 +02:00
|
|
|
|
string metadataFolder = Path.Combine(args.Parent.Path, "metadata");
|
|
|
|
|
|
2012-08-19 22:38:31 +02:00
|
|
|
|
string episodeFileName = Path.GetFileName(episode.Path);
|
2012-08-19 18:41:47 +02:00
|
|
|
|
|
2012-09-11 21:37:14 +02:00
|
|
|
|
var season = args.Parent as Season;
|
2012-08-19 18:41:47 +02:00
|
|
|
|
|
2012-08-19 22:38:31 +02:00
|
|
|
|
SetPrimaryImagePath(episode, season, metadataFolder, episodeFileName);
|
2012-08-19 18:41:47 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetPrimaryImagePath(Episode item, Season season, string metadataFolder, string episodeFileName)
|
|
|
|
|
{
|
2012-08-23 20:35:44 +02:00
|
|
|
|
// Look for the image file in the metadata folder, and if found, set PrimaryImagePath
|
2012-09-11 21:37:14 +02:00
|
|
|
|
var imageFiles = new string[] {
|
2012-08-19 18:41:47 +02:00
|
|
|
|
Path.Combine(metadataFolder, Path.ChangeExtension(episodeFileName, ".jpg")),
|
|
|
|
|
Path.Combine(metadataFolder, Path.ChangeExtension(episodeFileName, ".png"))
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-21 18:33:38 +02:00
|
|
|
|
string image;
|
|
|
|
|
|
2012-08-19 18:41:47 +02:00
|
|
|
|
if (season == null)
|
|
|
|
|
{
|
2012-08-23 20:35:44 +02:00
|
|
|
|
// Epsiode directly in Series folder. Gotta do this the slow way
|
2012-08-21 18:33:38 +02:00
|
|
|
|
image = imageFiles.FirstOrDefault(f => File.Exists(f));
|
2012-08-19 18:41:47 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-08-21 18:33:38 +02:00
|
|
|
|
image = imageFiles.FirstOrDefault(f => season.ContainsMetadataFile(f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we found something, set PrimaryImagePath
|
|
|
|
|
if (!string.IsNullOrEmpty(image))
|
|
|
|
|
{
|
|
|
|
|
item.PrimaryImagePath = image;
|
2012-08-19 18:41:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|