2012-08-19 15:58:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.Composition;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediaBrowser.Controller.Events;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers
|
|
|
|
|
{
|
|
|
|
|
[Export(typeof(BaseMetadataProvider))]
|
|
|
|
|
public class ImageFromMediaLocationProvider : BaseMetadataProvider
|
|
|
|
|
{
|
2012-08-19 20:38:31 +00:00
|
|
|
|
public override bool Supports(BaseEntity item)
|
|
|
|
|
{
|
2012-08-20 12:59:21 +00:00
|
|
|
|
return true;
|
2012-08-19 20:38:31 +00:00
|
|
|
|
}
|
2012-08-20 15:55:05 +00:00
|
|
|
|
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.First; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 20:38:31 +00:00
|
|
|
|
public override Task Fetch(BaseEntity item, ItemResolveEventArgs args)
|
2012-08-19 15:58:35 +00:00
|
|
|
|
{
|
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2012-08-21 14:42:40 +00:00
|
|
|
|
if (args.IsDirectory)
|
2012-08-19 15:58:35 +00:00
|
|
|
|
{
|
2012-08-20 12:59:21 +00:00
|
|
|
|
var baseItem = item as BaseItem;
|
|
|
|
|
|
|
|
|
|
if (baseItem != null)
|
|
|
|
|
{
|
|
|
|
|
PopulateImages(baseItem, args);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PopulateImages(item, args);
|
|
|
|
|
}
|
2012-08-19 15:58:35 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fills in image paths based on files win the folder
|
|
|
|
|
/// </summary>
|
2012-08-20 12:59:21 +00:00
|
|
|
|
private void PopulateImages(BaseEntity item, ItemResolveEventArgs args)
|
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
for (int i = 0; i < args.FileSystemChildren.Length; i++)
|
2012-08-20 12:59:21 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
var file = args.FileSystemChildren[i];
|
|
|
|
|
|
2012-08-21 03:56:28 +00:00
|
|
|
|
string filePath = file.Path;
|
2012-08-20 12:59:21 +00:00
|
|
|
|
|
|
|
|
|
string ext = Path.GetExtension(filePath);
|
|
|
|
|
|
|
|
|
|
// Only support png and jpg files
|
|
|
|
|
if (!ext.EndsWith("png", StringComparison.OrdinalIgnoreCase) && !ext.EndsWith("jpg", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string name = Path.GetFileNameWithoutExtension(filePath);
|
|
|
|
|
|
|
|
|
|
if (name.Equals("folder", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item.PrimaryImagePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fills in image paths based on files win the folder
|
|
|
|
|
/// </summary>
|
2012-08-19 15:58:35 +00:00
|
|
|
|
private void PopulateImages(BaseItem item, ItemResolveEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
List<string> backdropFiles = new List<string>();
|
|
|
|
|
|
2012-08-21 01:51:00 +00:00
|
|
|
|
for (int i = 0; i < args.FileSystemChildren.Length; i++)
|
2012-08-19 15:58:35 +00:00
|
|
|
|
{
|
2012-08-21 01:51:00 +00:00
|
|
|
|
var file = args.FileSystemChildren[i];
|
|
|
|
|
|
2012-08-21 03:56:28 +00:00
|
|
|
|
string filePath = file.Path;
|
2012-08-19 15:58:35 +00:00
|
|
|
|
|
|
|
|
|
string ext = Path.GetExtension(filePath);
|
|
|
|
|
|
|
|
|
|
// Only support png and jpg files
|
|
|
|
|
if (!ext.EndsWith("png", StringComparison.OrdinalIgnoreCase) && !ext.EndsWith("jpg", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string name = Path.GetFileNameWithoutExtension(filePath);
|
|
|
|
|
|
|
|
|
|
if (name.Equals("folder", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item.PrimaryImagePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
else if (name.StartsWith("backdrop", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
backdropFiles.Add(filePath);
|
|
|
|
|
}
|
|
|
|
|
if (name.Equals("logo", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item.LogoImagePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
if (name.Equals("banner", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item.BannerImagePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
if (name.Equals("art", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item.ArtImagePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
if (name.Equals("thumb", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
item.ThumbnailImagePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-21 01:51:00 +00:00
|
|
|
|
if (backdropFiles.Count > 0)
|
2012-08-19 15:58:35 +00:00
|
|
|
|
{
|
|
|
|
|
item.BackdropImagePaths = backdropFiles;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|