2019-01-13 15:02:23 -05:00
|
|
|
using System;
|
2019-01-13 14:25:45 -05:00
|
|
|
using System.Collections.Generic;
|
2019-01-26 15:47:11 -05:00
|
|
|
using System.IO;
|
2019-01-13 14:25:45 -05:00
|
|
|
using System.Linq;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-06-29 23:04:50 -04:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2016-10-25 15:02:04 -04:00
|
|
|
using MediaBrowser.Model.IO;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
2014-06-29 23:04:50 -04:00
|
|
|
namespace MediaBrowser.LocalMetadata.Images
|
2014-02-04 15:19:29 -05:00
|
|
|
{
|
2020-03-09 11:10:02 -04:00
|
|
|
public class EpisodeLocalLocalImageProvider : ILocalImageProvider, IHasOrder
|
2014-02-04 15:19:29 -05:00
|
|
|
{
|
2014-07-26 13:30:15 -04:00
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
|
|
|
public EpisodeLocalLocalImageProvider(IFileSystem fileSystem)
|
|
|
|
{
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
}
|
|
|
|
|
2019-01-13 15:31:14 -05:00
|
|
|
public string Name => "Local Images";
|
2014-02-04 15:19:29 -05:00
|
|
|
|
2019-01-13 15:31:14 -05:00
|
|
|
public int Order => 0;
|
2015-04-10 21:42:37 -04:00
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
public bool Supports(BaseItem item)
|
2014-02-04 15:19:29 -05:00
|
|
|
{
|
2014-02-10 15:11:46 -05:00
|
|
|
return item is Episode && item.SupportsLocalMetadata;
|
2014-02-04 15:19:29 -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
|
|
|
{
|
2019-01-26 15:47:11 -05:00
|
|
|
var parentPath = Path.GetDirectoryName(item.Path);
|
2014-02-08 17:38:02 -05:00
|
|
|
|
2017-08-24 15:52:19 -04:00
|
|
|
var parentPathFiles = directoryService.GetFiles(parentPath);
|
2014-02-08 17:38:02 -05:00
|
|
|
|
2019-01-26 17:23:43 -05:00
|
|
|
var nameWithoutExtension = Path.GetFileNameWithoutExtension(item.Path);
|
2014-02-08 17:38:02 -05:00
|
|
|
|
2017-06-04 16:24:45 -04:00
|
|
|
return GetFilesFromParentFolder(nameWithoutExtension, parentPathFiles);
|
2014-02-08 15:02:35 -05:00
|
|
|
}
|
|
|
|
|
2017-08-24 15:52:19 -04:00
|
|
|
private List<LocalImageInfo> GetFilesFromParentFolder(string filenameWithoutExtension, List<FileSystemMetadata> parentPathFiles)
|
2014-02-04 15:19:29 -05:00
|
|
|
{
|
2014-02-08 17:38:02 -05:00
|
|
|
var thumbName = filenameWithoutExtension + "-thumb";
|
2014-02-04 15:19:29 -05:00
|
|
|
|
2017-08-24 15:52:19 -04: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))
|
|
|
|
{
|
|
|
|
list.Add(new LocalImageInfo
|
|
|
|
{
|
|
|
|
FileInfo = i,
|
|
|
|
Type = ImageType.Primary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (string.Equals(thumbName, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
list.Add(new LocalImageInfo
|
|
|
|
{
|
|
|
|
FileInfo = i,
|
|
|
|
Type = ImageType.Primary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
2014-02-08 17:38:02 -05:00
|
|
|
}
|
2014-02-04 15:19:29 -05:00
|
|
|
}
|
|
|
|
}
|