2019-01-13 20:02:23 +00:00
|
|
|
using System;
|
2019-01-13 19:25:45 +00:00
|
|
|
using System.Collections.Generic;
|
2019-01-26 20:47:11 +00:00
|
|
|
using System.IO;
|
2019-01-13 19:25:45 +00:00
|
|
|
using System.Linq;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-06-30 03:04:50 +00:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2016-10-25 19:02:04 +00:00
|
|
|
using MediaBrowser.Model.IO;
|
2014-02-04 20:19:29 +00:00
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
namespace MediaBrowser.LocalMetadata.Images
|
2014-02-04 20:19:29 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <summary>
|
2020-06-17 15:53:02 +00:00
|
|
|
/// Episode local image provider.
|
2020-06-14 02:04:53 +00:00
|
|
|
/// </summary>
|
|
|
|
public class EpisodeLocalImageProvider : ILocalImageProvider, IHasOrder
|
2014-02-04 20:19:29 +00:00
|
|
|
{
|
2014-07-26 17:30:15 +00:00
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="EpisodeLocalImageProvider"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
|
|
|
public EpisodeLocalImageProvider(IFileSystem fileSystem)
|
2014-07-26 17:30:15 +00:00
|
|
|
{
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <inheritdoc />
|
2019-01-13 20:31:14 +00:00
|
|
|
public string Name => "Local Images";
|
2014-02-04 20:19:29 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <inheritdoc />
|
2019-01-13 20:31:14 +00:00
|
|
|
public int Order => 0;
|
2015-04-11 01:42:37 +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-04 20:19:29 +00:00
|
|
|
{
|
2014-02-10 20:11:46 +00:00
|
|
|
return item is Episode && item.SupportsLocalMetadata;
|
2014-02-04 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
public List<LocalImageInfo> GetImages(BaseItem item, IDirectoryService directoryService)
|
2014-02-08 20:02:35 +00:00
|
|
|
{
|
2019-01-26 20:47:11 +00:00
|
|
|
var parentPath = Path.GetDirectoryName(item.Path);
|
2014-02-08 22:38:02 +00:00
|
|
|
|
2017-08-24 19:52:19 +00:00
|
|
|
var parentPathFiles = directoryService.GetFiles(parentPath);
|
2014-02-08 22:38:02 +00:00
|
|
|
|
2019-01-26 22:23:43 +00:00
|
|
|
var nameWithoutExtension = Path.GetFileNameWithoutExtension(item.Path);
|
2014-02-08 22:38:02 +00:00
|
|
|
|
2017-06-04 20:24:45 +00:00
|
|
|
return GetFilesFromParentFolder(nameWithoutExtension, parentPathFiles);
|
2014-02-08 20:02:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 19:52:19 +00:00
|
|
|
private List<LocalImageInfo> GetFilesFromParentFolder(string filenameWithoutExtension, List<FileSystemMetadata> parentPathFiles)
|
2014-02-04 20:19:29 +00:00
|
|
|
{
|
2014-02-08 22:38:02 +00:00
|
|
|
var thumbName = filenameWithoutExtension + "-thumb";
|
2014-02-04 20:19:29 +00:00
|
|
|
|
2017-08-24 19:52:19 +00:00
|
|
|
var list = new List<LocalImageInfo>(1);
|
|
|
|
|
|
|
|
foreach (var i in parentPathFiles)
|
|
|
|
{
|
|
|
|
if (i.IsDirectory)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BaseItem.SupportedImageExtensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
var currentNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(i);
|
|
|
|
|
|
|
|
if (string.Equals(filenameWithoutExtension, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
list.Add(new LocalImageInfo { FileInfo = i, Type = ImageType.Primary });
|
2017-08-24 19:52:19 +00:00
|
|
|
}
|
|
|
|
else if (string.Equals(thumbName, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
list.Add(new LocalImageInfo { FileInfo = i, Type = ImageType.Primary });
|
2017-08-24 19:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
2017-08-24 19:52:19 +00:00
|
|
|
return list;
|
2014-02-08 22:38:02 +00:00
|
|
|
}
|
2014-02-04 20:19:29 +00:00
|
|
|
}
|
|
|
|
}
|