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