2016-03-27 14:11:27 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-07-12 12:05:35 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2017-05-25 23:48:54 -07:00
|
|
|
|
|
2016-10-25 12:02:04 -07:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
|
namespace MediaBrowser.LocalMetadata.Images
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
2015-04-10 18:42:37 -07:00
|
|
|
|
public class EpisodeLocalLocalImageProvider : ILocalImageFileProvider, IHasOrder
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
2014-07-26 10:30:15 -07:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
|
|
|
|
|
public EpisodeLocalLocalImageProvider(IFileSystem fileSystem)
|
|
|
|
|
{
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 13:19:29 -07:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Local Images"; }
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-10 18:42:37 -07:00
|
|
|
|
public int Order
|
|
|
|
|
{
|
|
|
|
|
get { return 0; }
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
|
public bool Supports(BaseItem item)
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
2014-02-10 13:11:46 -07:00
|
|
|
|
return item is Episode && item.SupportsLocalMetadata;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
|
public List<LocalImageInfo> GetImages(BaseItem item, IDirectoryService directoryService)
|
2014-02-08 13:02:35 -07:00
|
|
|
|
{
|
2017-05-04 11:14:45 -07:00
|
|
|
|
var parentPath = _fileSystem.GetDirectoryName(item.Path);
|
2014-02-08 15:38:02 -07:00
|
|
|
|
|
2017-08-24 12:52:19 -07:00
|
|
|
|
var parentPathFiles = directoryService.GetFiles(parentPath);
|
2014-02-08 15:38:02 -07:00
|
|
|
|
|
2014-07-26 10:30:15 -07:00
|
|
|
|
var nameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(item.Path);
|
2014-02-08 15:38:02 -07:00
|
|
|
|
|
2017-06-04 13:24:45 -07:00
|
|
|
|
return GetFilesFromParentFolder(nameWithoutExtension, parentPathFiles);
|
2014-02-08 13:02:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 12:52:19 -07:00
|
|
|
|
private List<LocalImageInfo> GetFilesFromParentFolder(string filenameWithoutExtension, List<FileSystemMetadata> parentPathFiles)
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
2014-02-08 15:38:02 -07:00
|
|
|
|
var thumbName = filenameWithoutExtension + "-thumb";
|
2014-02-04 13:19:29 -07:00
|
|
|
|
|
2017-08-24 12:52:19 -07: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 15:38:02 -07:00
|
|
|
|
}
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
|
|
|
|
}
|