2019-01-13 21:02:23 +01:00
|
|
|
using System;
|
2019-01-13 20:25:45 +01:00
|
|
|
using System.Collections.Generic;
|
2019-01-26 21:47:11 +01:00
|
|
|
using System.IO;
|
2019-01-13 20:25:45 +01:00
|
|
|
using System.Linq;
|
2021-06-19 18:02:33 +02:00
|
|
|
using Jellyfin.Extensions;
|
2019-01-13 20:25:45 +01:00
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-06-30 05:04:50 +02:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2016-10-25 21:02:04 +02:00
|
|
|
using MediaBrowser.Model.IO;
|
2014-02-04 21:19:29 +01:00
|
|
|
|
2014-06-30 05:04:50 +02:00
|
|
|
namespace MediaBrowser.LocalMetadata.Images
|
2014-02-04 21:19:29 +01:00
|
|
|
{
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <summary>
|
2020-06-17 17:53:02 +02:00
|
|
|
/// Episode local image provider.
|
2020-06-14 04:04:53 +02:00
|
|
|
/// </summary>
|
|
|
|
public class EpisodeLocalImageProvider : ILocalImageProvider, IHasOrder
|
2014-02-04 21:19:29 +01:00
|
|
|
{
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <inheritdoc />
|
2019-01-13 21:31:14 +01:00
|
|
|
public string Name => "Local Images";
|
2014-02-04 21:19:29 +01:00
|
|
|
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <inheritdoc />
|
2019-01-13 21:31:14 +01:00
|
|
|
public int Order => 0;
|
2015-04-11 03:42:37 +02:00
|
|
|
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <inheritdoc />
|
2018-09-12 19:26:21 +02:00
|
|
|
public bool Supports(BaseItem item)
|
2014-02-04 21:19:29 +01:00
|
|
|
{
|
2014-02-10 21:11:46 +01:00
|
|
|
return item is Episode && item.SupportsLocalMetadata;
|
2014-02-04 21:19:29 +01:00
|
|
|
}
|
|
|
|
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <inheritdoc />
|
2021-03-09 05:57:38 +01:00
|
|
|
public IEnumerable<LocalImageInfo> GetImages(BaseItem item, IDirectoryService directoryService)
|
2014-02-08 21:02:35 +01:00
|
|
|
{
|
2019-01-26 21:47:11 +01:00
|
|
|
var parentPath = Path.GetDirectoryName(item.Path);
|
2022-12-05 15:00:20 +01:00
|
|
|
if (parentPath is null)
|
2021-05-07 00:39:20 +02:00
|
|
|
{
|
|
|
|
return Enumerable.Empty<LocalImageInfo>();
|
|
|
|
}
|
2014-02-08 23:38:02 +01:00
|
|
|
|
2017-08-24 21:52:19 +02:00
|
|
|
var parentPathFiles = directoryService.GetFiles(parentPath);
|
2014-02-08 23:38:02 +01:00
|
|
|
|
2021-05-24 00:30:41 +02:00
|
|
|
var nameWithoutExtension = Path.GetFileNameWithoutExtension(item.Path.AsSpan());
|
2014-02-08 23:38:02 +01:00
|
|
|
|
2017-06-04 22:24:45 +02:00
|
|
|
return GetFilesFromParentFolder(nameWithoutExtension, parentPathFiles);
|
2014-02-08 21:02:35 +01:00
|
|
|
}
|
|
|
|
|
2021-05-24 00:30:41 +02:00
|
|
|
private List<LocalImageInfo> GetFilesFromParentFolder(ReadOnlySpan<char> filenameWithoutExtension, List<FileSystemMetadata> parentPathFiles)
|
2014-02-04 21:19:29 +01:00
|
|
|
{
|
2021-05-24 00:30:41 +02:00
|
|
|
var thumbName = string.Concat(filenameWithoutExtension, "-thumb");
|
2014-02-04 21:19:29 +01:00
|
|
|
|
2017-08-24 21:52:19 +02:00
|
|
|
var list = new List<LocalImageInfo>(1);
|
|
|
|
|
|
|
|
foreach (var i in parentPathFiles)
|
|
|
|
{
|
|
|
|
if (i.IsDirectory)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-24 00:30:41 +02:00
|
|
|
if (BaseItem.SupportedImageExtensions.Contains(i.Extension.AsSpan(), StringComparison.OrdinalIgnoreCase))
|
2017-08-24 21:52:19 +02:00
|
|
|
{
|
2021-05-24 00:30:41 +02:00
|
|
|
var currentNameWithoutExtension = Path.GetFileNameWithoutExtension(i.FullName.AsSpan());
|
2017-08-24 21:52:19 +02:00
|
|
|
|
2021-05-24 00:30:41 +02:00
|
|
|
if (filenameWithoutExtension.Equals(currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
|
2017-08-24 21:52:19 +02:00
|
|
|
{
|
2020-06-14 04:04:53 +02:00
|
|
|
list.Add(new LocalImageInfo { FileInfo = i, Type = ImageType.Primary });
|
2017-08-24 21:52:19 +02:00
|
|
|
}
|
2021-05-24 00:30:41 +02:00
|
|
|
else if (currentNameWithoutExtension.Equals(thumbName, StringComparison.OrdinalIgnoreCase))
|
2017-08-24 21:52:19 +02:00
|
|
|
{
|
2020-06-14 04:04:53 +02:00
|
|
|
list.Add(new LocalImageInfo { FileInfo = i, Type = ImageType.Primary });
|
2017-08-24 21:52:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-14 04:04:53 +02:00
|
|
|
|
2017-08-24 21:52:19 +02:00
|
|
|
return list;
|
2014-02-08 23:38:02 +01:00
|
|
|
}
|
2014-02-04 21:19:29 +01:00
|
|
|
}
|
|
|
|
}
|