2013-11-07 15:56:35 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
2013-05-02 22:32:15 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-06-25 01:22:21 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-06-09 16:47:28 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-04-28 00:44:38 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2013-06-09 16:47:28 +00:00
|
|
|
|
namespace MediaBrowser.Providers
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides images for generic types by looking for standard images in the IBN
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ImagesByNameProvider : ImageFromMediaLocationProvider
|
|
|
|
|
{
|
2013-10-30 14:40:14 +00:00
|
|
|
|
public ImagesByNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem)
|
2013-11-07 15:56:35 +00:00
|
|
|
|
: base(logManager, configurationManager, fileSystem)
|
2013-03-02 17:59:15 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supportses the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
2013-11-07 15:56:35 +00:00
|
|
|
|
// Only run for these generic types since we are expensive in file i/o
|
|
|
|
|
return item is BasePluginFolder || item is CollectionFolder;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return MetadataProviderPriority.Last;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the location.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
protected string GetLocation(BaseItem item)
|
|
|
|
|
{
|
2013-11-07 15:56:35 +00:00
|
|
|
|
var name = FileSystem.GetValidFilename(item.Name);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-03-04 05:43:06 +00:00
|
|
|
|
return Path.Combine(ConfigurationManager.ApplicationPaths.GeneralPath, name);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the image.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
2013-08-15 19:09:52 +00:00
|
|
|
|
/// <param name="args">The args.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <param name="filenameWithoutExtension">The filename without extension.</param>
|
2013-04-30 17:21:21 +00:00
|
|
|
|
/// <returns>FileSystemInfo.</returns>
|
2013-08-15 19:09:52 +00:00
|
|
|
|
protected override FileSystemInfo GetImage(BaseItem item, ItemResolveArgs args, string filenameWithoutExtension)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
var location = GetLocation(item);
|
|
|
|
|
|
2013-11-07 15:56:35 +00:00
|
|
|
|
return GetImageFromLocation(location, filenameWithoutExtension);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-11-07 15:56:35 +00:00
|
|
|
|
protected override Guid GetFileSystemStamp(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
var location = GetLocation(item);
|
2013-04-28 05:29:27 +00:00
|
|
|
|
|
2013-11-07 15:56:35 +00:00
|
|
|
|
try
|
2013-04-28 05:29:27 +00:00
|
|
|
|
{
|
2013-11-07 15:56:35 +00:00
|
|
|
|
var files = new DirectoryInfo(location)
|
|
|
|
|
.EnumerateFiles("*", SearchOption.TopDirectoryOnly)
|
|
|
|
|
.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var ext = i.Extension;
|
|
|
|
|
|
|
|
|
|
return !string.IsNullOrEmpty(ext) &&
|
|
|
|
|
BaseItem.SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
return GetFileSystemStamp(files);
|
2013-05-25 15:16:50 +00:00
|
|
|
|
}
|
2013-11-07 15:56:35 +00:00
|
|
|
|
catch (DirectoryNotFoundException)
|
2013-05-25 15:16:50 +00:00
|
|
|
|
{
|
2013-11-07 15:56:35 +00:00
|
|
|
|
// User doesn't have the folder. No need to log or blow up
|
2013-04-28 05:29:27 +00:00
|
|
|
|
|
2013-11-07 15:56:35 +00:00
|
|
|
|
return Guid.Empty;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|