2012-09-11 01:34:02 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2012-09-08 19:05:18 +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-09-08 19:05:18 +00:00
|
|
|
|
namespace MediaBrowser.Controller.Providers.TV
|
2012-08-19 16:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
[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-09-11 19:37:14 +00:00
|
|
|
|
var episode = item as Episode;
|
2012-08-19 20:38:31 +00:00
|
|
|
|
|
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
|
|
|
|
|
2012-09-11 19:37:14 +00:00
|
|
|
|
var season = args.Parent as Season;
|
2012-08-19 16:41:47 +00:00
|
|
|
|
|
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-09-11 19:37:14 +00:00
|
|
|
|
var imageFiles = new string[] {
|
2012-08-19 16:41:47 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|