2019-01-13 15:02:23 -05:00
|
|
|
using System.Collections.Generic;
|
2019-01-13 14:25:45 -05:00
|
|
|
using System.IO;
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-02-08 15:02:35 -05:00
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-02-08 23:52:52 -05:00
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-02-08 15:02:35 -05:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2016-10-25 15:02:04 -04:00
|
|
|
using MediaBrowser.Model.IO;
|
2019-02-24 09:47:59 -05:00
|
|
|
using Microsoft.Extensions.Logging;
|
2014-02-08 15:02:35 -05:00
|
|
|
|
2014-06-29 23:04:50 -04:00
|
|
|
namespace MediaBrowser.LocalMetadata.Images
|
2014-02-08 15:02:35 -05:00
|
|
|
{
|
2020-03-09 11:10:02 -04:00
|
|
|
public class InternalMetadataFolderImageProvider : ILocalImageProvider, IHasOrder
|
2014-02-08 15:02:35 -05:00
|
|
|
{
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2014-07-26 13:30:15 -04:00
|
|
|
private readonly IFileSystem _fileSystem;
|
2020-06-05 20:15:56 -04:00
|
|
|
private readonly ILogger<InternalMetadataFolderImageProvider> _logger;
|
2014-02-08 15:02:35 -05:00
|
|
|
|
2019-02-24 09:47:59 -05:00
|
|
|
public InternalMetadataFolderImageProvider(
|
|
|
|
IServerConfigurationManager config,
|
|
|
|
IFileSystem fileSystem,
|
|
|
|
ILogger<InternalMetadataFolderImageProvider> logger)
|
2014-02-08 15:02:35 -05:00
|
|
|
{
|
|
|
|
_config = config;
|
2014-07-26 13:30:15 -04:00
|
|
|
_fileSystem = fileSystem;
|
2019-02-24 09:47:59 -05:00
|
|
|
_logger = logger;
|
2014-02-08 15:02:35 -05:00
|
|
|
}
|
|
|
|
|
2019-01-13 15:31:14 -05:00
|
|
|
public string Name => "Internal Images";
|
2014-02-08 15:02:35 -05:00
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
public bool Supports(BaseItem item)
|
2014-02-08 15:02:35 -05:00
|
|
|
{
|
2015-04-10 21:42:37 -04:00
|
|
|
if (item is Photo)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-08 15:02:35 -05:00
|
|
|
if (!item.IsSaveLocalMetadataEnabled())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-08 23:52:52 -05:00
|
|
|
// Extracted images will be saved in here
|
|
|
|
if (item is Audio)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-19 23:04:45 -04:00
|
|
|
if (item.SupportsLocalMetadata && !item.AlwaysScanInternalMetadataPath)
|
2014-02-08 15:02:35 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-30 12:45:22 -04:00
|
|
|
|
2014-02-08 15:02:35 -05:00
|
|
|
return true;
|
|
|
|
}
|
2019-01-17 14:24:39 -05:00
|
|
|
// Make sure this is last so that all other locations are scanned first
|
2019-01-13 15:31:14 -05:00
|
|
|
public int Order => 1000;
|
2014-02-08 15:02:35 -05:00
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
public List<LocalImageInfo> GetImages(BaseItem item, IDirectoryService directoryService)
|
2014-02-08 15:02:35 -05:00
|
|
|
{
|
2014-09-28 11:27:26 -04:00
|
|
|
var path = item.GetInternalMetadataPath();
|
|
|
|
|
2019-02-24 09:47:59 -05:00
|
|
|
if (!Directory.Exists(path))
|
|
|
|
{
|
|
|
|
return new List<LocalImageInfo>();
|
|
|
|
}
|
|
|
|
|
2014-02-08 15:02:35 -05:00
|
|
|
try
|
|
|
|
{
|
2017-03-29 02:26:48 -04:00
|
|
|
return new LocalImageProvider(_fileSystem).GetImages(item, path, false, directoryService);
|
2014-02-08 15:02:35 -05:00
|
|
|
}
|
2019-02-24 09:47:59 -05:00
|
|
|
catch (IOException ex)
|
2014-02-08 15:02:35 -05:00
|
|
|
{
|
2019-02-24 09:47:59 -05:00
|
|
|
_logger.LogError(ex, "Error while getting images for {Library}", item.Name);
|
2014-02-08 15:02:35 -05:00
|
|
|
return new List<LocalImageInfo>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|