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