jellyfin/MediaBrowser.Providers/ImagesByNameProvider.cs

100 lines
3.2 KiB
C#
Raw Normal View History

using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration;
2013-03-03 22:43:06 -07:00
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
2013-06-09 09:47:28 -07:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
2013-02-20 18:33:05 -07:00
using System;
using System.IO;
using System.Linq;
2013-06-09 09:47:28 -07:00
namespace MediaBrowser.Providers
2013-02-20 18:33:05 -07:00
{
/// <summary>
/// Provides images for generic types by looking for standard images in the IBN
/// </summary>
public class ImagesByNameProvider : ImageFromMediaLocationProvider
{
public ImagesByNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem)
: base(logManager, configurationManager, fileSystem)
2013-03-02 10:59:15 -07:00
{
}
2013-02-20 18:33:05 -07: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)
{
// Only run for these generic types since we are expensive in file i/o
return item is BasePluginFolder || item is CollectionFolder;
2013-02-20 18:33:05 -07: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)
{
var name = FileSystem.GetValidFilename(item.Name);
2013-02-20 18:33:05 -07:00
2013-03-03 22:43:06 -07:00
return Path.Combine(ConfigurationManager.ApplicationPaths.GeneralPath, name);
2013-02-20 18:33:05 -07:00
}
/// <summary>
/// Gets the image.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
2013-02-20 18:33:05 -07:00
/// <param name="filenameWithoutExtension">The filename without extension.</param>
2013-04-30 10:21:21 -07:00
/// <returns>FileSystemInfo.</returns>
protected override FileSystemInfo GetImage(BaseItem item, ItemResolveArgs args, string filenameWithoutExtension)
2013-02-20 18:33:05 -07:00
{
var location = GetLocation(item);
return GetImageFromLocation(location, filenameWithoutExtension);
}
2013-02-20 18:33:05 -07:00
protected override Guid GetFileSystemStamp(BaseItem item)
{
var location = GetLocation(item);
try
{
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);
}
catch (DirectoryNotFoundException)
{
// User doesn't have the folder. No need to log or blow up
return Guid.Empty;
}
2013-02-20 18:33:05 -07:00
}
}
}