using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Images
{
///
/// Internal metadata folder image provider.
///
public class InternalMetadataFolderImageProvider : ILocalImageProvider, IHasOrder
{
private readonly IFileSystem _fileSystem;
private readonly ILogger _logger;
///
/// Initializes a new instance of the class.
///
/// Instance of the interface.
/// Instance of the interface.
public InternalMetadataFolderImageProvider(
IFileSystem fileSystem,
ILogger logger)
{
_fileSystem = fileSystem;
_logger = logger;
}
/// Make sure this is last so that all other locations are scanned first
///
public int Order => 1000;
///
public string Name => "Internal Images";
///
public bool Supports(BaseItem item)
{
if (item is Photo)
{
return false;
}
if (!item.IsSaveLocalMetadataEnabled())
{
return true;
}
// Extracted images will be saved in here
if (item is Audio)
{
return true;
}
if (item.SupportsLocalMetadata && !item.AlwaysScanInternalMetadataPath)
{
return false;
}
return true;
}
///
public IEnumerable GetImages(BaseItem item, IDirectoryService directoryService)
{
var path = item.GetInternalMetadataPath();
if (!Directory.Exists(path))
{
return Enumerable.Empty();
}
try
{
return new LocalImageProvider(_fileSystem).GetImages(item, path, directoryService);
}
catch (IOException ex)
{
_logger.LogError(ex, "Error while getting images for {Library}", item.Name);
return Enumerable.Empty();
}
}
}
}