jellyfin/MediaBrowser.Providers/ImagesByNameProvider.cs

101 lines
3.3 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration;
2013-03-04 06:43:06 +01:00
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
2013-06-09 18:47:28 +02:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
2013-02-21 02:33:05 +01:00
using System;
using System.IO;
using System.Linq;
2013-06-09 18:47:28 +02:00
namespace MediaBrowser.Providers
2013-02-21 02:33:05 +01: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 18:59:15 +01:00
{
}
2013-02-21 02:33:05 +01: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
2014-01-30 22:23:54 +01:00
return item is ICollectionFolder;
2013-02-21 02:33:05 +01: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-21 02:33:05 +01:00
2013-03-04 06:43:06 +01:00
return Path.Combine(ConfigurationManager.ApplicationPaths.GeneralPath, name);
2013-02-21 02:33:05 +01:00
}
/// <summary>
/// Gets the image.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="args">The args.</param>
2013-02-21 02:33:05 +01:00
/// <param name="filenameWithoutExtension">The filename without extension.</param>
2013-04-30 19:21:21 +02:00
/// <returns>FileSystemInfo.</returns>
protected override FileSystemInfo GetImage(BaseItem item, ItemResolveArgs args, string filenameWithoutExtension)
2013-02-21 02:33:05 +01:00
{
var location = GetLocation(item);
return GetImageFromLocation(location, filenameWithoutExtension);
}
2013-02-21 02:33:05 +01:00
protected override Guid GetFileSystemStamp(IEnumerable<BaseItem> items)
{
var location = GetLocation(items.First());
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-21 02:33:05 +01:00
}
}
}