jellyfin/MediaBrowser.LocalMetadata/Images/EpisodeLocalImageProvider.cs

88 lines
2.7 KiB
C#
Raw Normal View History

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