using System.Collections.Generic; using MediaBrowser.Common.IO; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Logging; using System; using System.IO; using System.Linq; namespace MediaBrowser.Providers { /// /// Provides images for generic types by looking for standard images in the IBN /// public class ImagesByNameProvider : ImageFromMediaLocationProvider { public ImagesByNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem) : base(logManager, configurationManager, fileSystem) { } /// /// Supportses the specified item. /// /// The item. /// true if XXXX, false otherwise public override bool Supports(BaseItem item) { // Only run for these generic types since we are expensive in file i/o return item is ICollectionFolder; } /// /// Gets the priority. /// /// The priority. public override MetadataProviderPriority Priority { get { return MetadataProviderPriority.Last; } } /// /// Gets the location. /// /// The item. /// System.String. protected string GetLocation(BaseItem item) { var name = FileSystem.GetValidFilename(item.Name); return Path.Combine(ConfigurationManager.ApplicationPaths.GeneralPath, name); } /// /// Gets the image. /// /// The item. /// The args. /// The filename without extension. /// FileSystemInfo. protected override FileSystemInfo GetImage(BaseItem item, ItemResolveArgs args, string filenameWithoutExtension) { var location = GetLocation(item); return GetImageFromLocation(location, filenameWithoutExtension); } protected override Guid GetFileSystemStamp(IEnumerable 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; } } } }