2019-01-13 19:25:45 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
2019-02-24 15:16:53 +00:00
|
|
|
using System.IO;
|
2019-01-13 19:25:45 +00:00
|
|
|
using System.Linq;
|
2019-01-06 20:50:43 +00:00
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-01-31 19:55:21 +00:00
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2019-01-13 19:25:45 +00:00
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2014-01-28 18:37:01 +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-01-28 18:37:01 +00:00
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
namespace MediaBrowser.LocalMetadata.Images
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Local image provider.
|
|
|
|
/// </summary>
|
2020-03-09 15:10:02 +00:00
|
|
|
public class LocalImageProvider : ILocalImageProvider, IHasOrder
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
private static readonly string[] _commonImageFileNames =
|
|
|
|
{
|
|
|
|
"poster",
|
|
|
|
"folder",
|
|
|
|
"cover",
|
|
|
|
"default"
|
|
|
|
};
|
|
|
|
|
|
|
|
private static readonly string[] _musicImageFileNames =
|
|
|
|
{
|
|
|
|
"folder",
|
|
|
|
"poster",
|
|
|
|
"cover",
|
|
|
|
"default"
|
|
|
|
};
|
|
|
|
|
|
|
|
private static readonly string[] _personImageFileNames =
|
|
|
|
{
|
|
|
|
"folder",
|
|
|
|
"poster"
|
|
|
|
};
|
|
|
|
|
|
|
|
private static readonly string[] _seriesImageFileNames =
|
|
|
|
{
|
|
|
|
"poster",
|
|
|
|
"folder",
|
|
|
|
"cover",
|
|
|
|
"default",
|
|
|
|
"show"
|
|
|
|
};
|
|
|
|
|
|
|
|
private static readonly string[] _videoImageFileNames =
|
|
|
|
{
|
|
|
|
"poster",
|
|
|
|
"folder",
|
|
|
|
"cover",
|
|
|
|
"default",
|
|
|
|
"movie"
|
|
|
|
};
|
|
|
|
|
2014-07-26 17:30:15 +00:00
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="LocalImageProvider"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
2014-07-26 17:30:15 +00:00
|
|
|
public LocalImageProvider(IFileSystem fileSystem)
|
|
|
|
{
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
}
|
2014-10-20 03:04:45 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <inheritdoc />
|
2019-01-13 20:31:14 +00:00
|
|
|
public string Name => "Local Images";
|
2014-01-28 18:37:01 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <inheritdoc />
|
2019-01-13 20:31:14 +00:00
|
|
|
public int Order => 0;
|
2014-01-28 18:37:01 +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-01-28 18:37:01 +00:00
|
|
|
{
|
2014-02-10 20:11:46 +00:00
|
|
|
if (item.SupportsLocalMetadata)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2020-03-09 14:05:03 +00:00
|
|
|
// Episode has its own provider
|
2018-09-12 17:26:21 +00:00
|
|
|
if (item is Episode || item is Audio || item is Photo)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-31 19:55:21 +00:00
|
|
|
|
2014-02-10 20:11:46 +00:00
|
|
|
if (item.LocationType == LocationType.Virtual)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
|
|
|
var season = item as Season;
|
2020-06-14 02:04:53 +00:00
|
|
|
var series = season?.Series;
|
|
|
|
if (series != null && series.IsFileProtocol)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
return true;
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-06 20:50:43 +00:00
|
|
|
private static IEnumerable<FileSystemMetadata> GetFiles(BaseItem item, bool includeDirectories, IDirectoryService directoryService)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
if (!item.IsFileProtocol)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2021-03-09 04:57:38 +00:00
|
|
|
return Enumerable.Empty<FileSystemMetadata>();
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
|
2014-02-06 05:17:00 +00:00
|
|
|
var path = item.ContainingFolderPath;
|
2014-01-28 18:37:01 +00:00
|
|
|
|
2019-02-24 15:16:53 +00:00
|
|
|
// Exit if the cache dir does not exist, alternative solution is to create it, but that's a lot of empty dirs...
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
{
|
2021-03-09 04:57:38 +00:00
|
|
|
return Enumerable.Empty<FileSystemMetadata>();
|
2019-02-24 15:16:53 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 18:37:01 +00:00
|
|
|
if (includeDirectories)
|
|
|
|
{
|
2014-02-08 22:38:02 +00:00
|
|
|
return directoryService.GetFileSystemEntries(path)
|
2015-11-12 20:51:39 +00:00
|
|
|
.Where(i => BaseItem.SupportedImageExtensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase) || i.IsDirectory)
|
2014-12-19 04:20:07 +00:00
|
|
|
|
2018-12-27 21:43:48 +00:00
|
|
|
.OrderBy(i => Array.IndexOf(BaseItem.SupportedImageExtensions, i.Extension ?? string.Empty));
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
2014-02-07 22:40:03 +00:00
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
return directoryService.GetFiles(path)
|
2014-12-19 04:20:07 +00:00
|
|
|
.Where(i => BaseItem.SupportedImageExtensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase))
|
2018-12-27 21:43:48 +00:00
|
|
|
.OrderBy(i => Array.IndexOf(BaseItem.SupportedImageExtensions, i.Extension ?? string.Empty));
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <inheritdoc />
|
2021-03-09 04:57:38 +00:00
|
|
|
public IEnumerable<LocalImageInfo> GetImages(BaseItem item, IDirectoryService directoryService)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2014-02-08 22:38:02 +00:00
|
|
|
var files = GetFiles(item, true, directoryService).ToList();
|
2014-01-28 18:37:01 +00:00
|
|
|
|
|
|
|
var list = new List<LocalImageInfo>();
|
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
PopulateImages(item, list, files, true, directoryService);
|
2014-02-08 20:02:35 +00:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Get images for item.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
/// <param name="path">The images path.</param>
|
|
|
|
/// <param name="directoryService">Instance of the <see cref="IDirectoryService"/> interface.</param>
|
|
|
|
/// <returns>The local image info.</returns>
|
2021-03-09 04:57:38 +00:00
|
|
|
public IEnumerable<LocalImageInfo> GetImages(BaseItem item, string path, IDirectoryService directoryService)
|
2014-02-08 20:02:35 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
return GetImages(item, new[] { path }, directoryService);
|
2014-02-08 20:02:35 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Get images for item from multiple paths.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
/// <param name="paths">The image paths.</param>
|
|
|
|
/// <param name="directoryService">Instance of the <see cref="IDirectoryService"/> interface.</param>
|
|
|
|
/// <returns>The local image info.</returns>
|
2021-03-09 04:57:38 +00:00
|
|
|
public IEnumerable<LocalImageInfo> GetImages(BaseItem item, IEnumerable<string> paths, IDirectoryService directoryService)
|
2014-02-08 20:02:35 +00:00
|
|
|
{
|
2019-01-17 19:24:39 +00:00
|
|
|
IEnumerable<FileSystemMetadata> files = paths.SelectMany(i => _fileSystem.GetFiles(i, BaseItem.SupportedImageExtensions, true, false));
|
2017-03-29 06:26:48 +00:00
|
|
|
|
|
|
|
files = files
|
2018-12-27 21:43:48 +00:00
|
|
|
.OrderBy(i => Array.IndexOf(BaseItem.SupportedImageExtensions, i.Extension ?? string.Empty));
|
2014-02-08 20:02:35 +00:00
|
|
|
|
|
|
|
var list = new List<LocalImageInfo>();
|
|
|
|
|
2017-03-29 06:26:48 +00:00
|
|
|
PopulateImages(item, list, files.ToList(), false, directoryService);
|
2014-01-28 18:37:01 +00:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
private void PopulateImages(BaseItem item, List<LocalImageInfo> images, List<FileSystemMetadata> files, bool supportParentSeriesFiles, IDirectoryService directoryService)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2016-01-22 02:59:07 +00:00
|
|
|
if (supportParentSeriesFiles)
|
|
|
|
{
|
2021-03-09 04:57:38 +00:00
|
|
|
if (item is Season season)
|
2016-01-22 02:59:07 +00:00
|
|
|
{
|
|
|
|
PopulateSeasonImagesFromSeriesFolder(season, images, directoryService);
|
|
|
|
}
|
|
|
|
}
|
2017-03-29 06:26:48 +00:00
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
var imagePrefix = item.FileNameWithoutExtension + "-";
|
2017-07-31 05:16:22 +00:00
|
|
|
var isInMixedFolder = item.IsInMixedFolder;
|
2014-01-28 18:37:01 +00:00
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
PopulatePrimaryImages(item, images, files, imagePrefix, isInMixedFolder);
|
2014-01-28 18:37:01 +00:00
|
|
|
|
2017-11-15 21:33:04 +00:00
|
|
|
var added = false;
|
|
|
|
var isEpisode = item is Episode;
|
|
|
|
var isSong = item.GetType() == typeof(Audio);
|
|
|
|
var isPerson = item is Person;
|
|
|
|
|
|
|
|
// Logo
|
|
|
|
if (!isEpisode && !isSong && !isPerson)
|
|
|
|
{
|
|
|
|
added = AddImage(files, images, "logo", imagePrefix, isInMixedFolder, ImageType.Logo);
|
|
|
|
if (!added)
|
|
|
|
{
|
|
|
|
added = AddImage(files, images, "clearlogo", imagePrefix, isInMixedFolder, ImageType.Logo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Art
|
|
|
|
if (!isEpisode && !isSong && !isPerson)
|
|
|
|
{
|
|
|
|
AddImage(files, images, "clearart", imagePrefix, isInMixedFolder, ImageType.Art);
|
|
|
|
}
|
2016-01-22 02:29:00 +00:00
|
|
|
|
|
|
|
// For music albums, prefer cdart before disc
|
|
|
|
if (item is MusicAlbum)
|
|
|
|
{
|
2017-11-15 21:33:04 +00:00
|
|
|
added = AddImage(files, images, "cdart", imagePrefix, isInMixedFolder, ImageType.Disc);
|
|
|
|
|
|
|
|
if (!added)
|
|
|
|
{
|
|
|
|
added = AddImage(files, images, "disc", imagePrefix, isInMixedFolder, ImageType.Disc);
|
|
|
|
}
|
2016-01-22 02:29:00 +00:00
|
|
|
}
|
2019-01-28 17:49:25 +00:00
|
|
|
else if (item is Video || item is BoxSet)
|
2016-01-22 02:29:00 +00:00
|
|
|
{
|
2017-11-15 21:33:04 +00:00
|
|
|
added = AddImage(files, images, "disc", imagePrefix, isInMixedFolder, ImageType.Disc);
|
|
|
|
|
|
|
|
if (!added)
|
|
|
|
{
|
|
|
|
added = AddImage(files, images, "cdart", imagePrefix, isInMixedFolder, ImageType.Disc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!added)
|
|
|
|
{
|
|
|
|
added = AddImage(files, images, "discart", imagePrefix, isInMixedFolder, ImageType.Disc);
|
|
|
|
}
|
|
|
|
}
|
2014-01-28 18:37:01 +00:00
|
|
|
|
|
|
|
// Banner
|
2017-11-15 21:33:04 +00:00
|
|
|
if (!isEpisode && !isSong && !isPerson)
|
|
|
|
{
|
|
|
|
AddImage(files, images, "banner", imagePrefix, isInMixedFolder, ImageType.Banner);
|
|
|
|
}
|
2014-01-28 18:37:01 +00:00
|
|
|
|
|
|
|
// Thumb
|
2017-11-15 21:33:04 +00:00
|
|
|
if (!isEpisode && !isSong && !isPerson)
|
|
|
|
{
|
|
|
|
added = AddImage(files, images, "landscape", imagePrefix, isInMixedFolder, ImageType.Thumb);
|
|
|
|
if (!added)
|
|
|
|
{
|
|
|
|
added = AddImage(files, images, "thumb", imagePrefix, isInMixedFolder, ImageType.Thumb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isEpisode && !isSong && !isPerson)
|
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
PopulateBackdrops(item, images, files, imagePrefix, isInMixedFolder);
|
2017-11-15 21:33:04 +00:00
|
|
|
}
|
2014-12-09 04:57:18 +00:00
|
|
|
|
2017-11-15 21:33:04 +00:00
|
|
|
if (item is IHasScreenshots)
|
|
|
|
{
|
|
|
|
PopulateScreenshots(images, files, imagePrefix, isInMixedFolder);
|
|
|
|
}
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
private void PopulatePrimaryImages(BaseItem item, List<LocalImageInfo> images, List<FileSystemMetadata> files, string imagePrefix, bool isInMixedFolder)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
string[] imageFileNames;
|
2014-01-28 18:37:01 +00:00
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
if (item is MusicAlbum || item is MusicArtist || item is PhotoAlbum)
|
2016-01-22 02:59:07 +00:00
|
|
|
{
|
|
|
|
// these prefer folder
|
2020-06-14 02:04:53 +00:00
|
|
|
imageFileNames = _musicImageFileNames;
|
2016-01-22 02:59:07 +00:00
|
|
|
}
|
2017-08-19 19:43:35 +00:00
|
|
|
else if (item is Person)
|
2016-01-22 02:59:07 +00:00
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
// these prefer folder
|
2020-06-14 02:04:53 +00:00
|
|
|
imageFileNames = _personImageFileNames;
|
2016-01-22 02:59:07 +00:00
|
|
|
}
|
2017-08-19 19:43:35 +00:00
|
|
|
else if (item is Series)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
imageFileNames = _seriesImageFileNames;
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
2017-08-19 19:43:35 +00:00
|
|
|
else if (item is Video && !(item is Episode))
|
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
imageFileNames = _videoImageFileNames;
|
2017-08-19 19:43:35 +00:00
|
|
|
}
|
|
|
|
else
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
imageFileNames = _commonImageFileNames;
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
var fileNameWithoutExtension = item.FileNameWithoutExtension;
|
|
|
|
if (!string.IsNullOrEmpty(fileNameWithoutExtension))
|
|
|
|
{
|
2017-11-15 21:33:04 +00:00
|
|
|
if (AddImage(files, images, fileNameWithoutExtension, ImageType.Primary))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-12-09 04:57:18 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
foreach (var name in imageFileNames)
|
2015-03-27 04:17:04 +00:00
|
|
|
{
|
2017-11-15 21:33:04 +00:00
|
|
|
if (AddImage(files, images, imagePrefix + name, ImageType.Primary))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-03-27 04:17:04 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
if (!isInMixedFolder)
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
foreach (var name in imageFileNames)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2017-11-15 21:33:04 +00:00
|
|
|
if (AddImage(files, images, name, ImageType.Primary))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
private void PopulateBackdrops(BaseItem item, List<LocalImageInfo> images, List<FileSystemMetadata> files, string imagePrefix, bool isInMixedFolder)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2014-02-27 16:25:04 +00:00
|
|
|
if (!string.IsNullOrEmpty(item.Path))
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2014-12-09 04:57:18 +00:00
|
|
|
var name = item.FileNameWithoutExtension;
|
2014-01-28 18:37:01 +00:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(name))
|
|
|
|
{
|
|
|
|
AddImage(files, images, imagePrefix + name + "-fanart", ImageType.Backdrop);
|
2014-12-09 04:57:18 +00:00
|
|
|
|
|
|
|
// Support without the prefix if it's in it's own folder
|
|
|
|
if (!isInMixedFolder)
|
|
|
|
{
|
|
|
|
AddImage(files, images, name + "-fanart", ImageType.Backdrop);
|
|
|
|
}
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
PopulateBackdrops(images, files, imagePrefix, "fanart", "fanart-", isInMixedFolder, ImageType.Backdrop);
|
|
|
|
PopulateBackdrops(images, files, imagePrefix, "background", "background-", isInMixedFolder, ImageType.Backdrop);
|
|
|
|
PopulateBackdrops(images, files, imagePrefix, "art", "art-", isInMixedFolder, ImageType.Backdrop);
|
2014-01-28 18:37:01 +00:00
|
|
|
|
2014-03-12 19:56:12 +00:00
|
|
|
var extraFanartFolder = files
|
2014-02-07 22:40:03 +00:00
|
|
|
.FirstOrDefault(i => string.Equals(i.Name, "extrafanart", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
if (extraFanartFolder != null)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
PopulateBackdropsFromExtraFanart(extraFanartFolder.FullName, images);
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
2016-01-22 02:59:07 +00:00
|
|
|
|
|
|
|
PopulateBackdrops(images, files, imagePrefix, "backdrop", "backdrop", isInMixedFolder, ImageType.Backdrop);
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
private void PopulateBackdropsFromExtraFanart(string path, List<LocalImageInfo> images)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2017-03-29 06:26:48 +00:00
|
|
|
var imageFiles = _fileSystem.GetFiles(path, BaseItem.SupportedImageExtensions, false, false);
|
2014-01-28 18:37:01 +00:00
|
|
|
|
2017-03-29 19:16:18 +00:00
|
|
|
images.AddRange(imageFiles.Where(i => i.Length > 0).Select(i => new LocalImageInfo
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2014-02-07 22:40:03 +00:00
|
|
|
FileInfo = i,
|
2014-01-28 18:37:01 +00:00
|
|
|
Type = ImageType.Backdrop
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2015-10-04 03:38:46 +00:00
|
|
|
private void PopulateScreenshots(List<LocalImageInfo> images, List<FileSystemMetadata> files, string imagePrefix, bool isInMixedFolder)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2014-12-09 04:57:18 +00:00
|
|
|
PopulateBackdrops(images, files, imagePrefix, "screenshot", "screenshot", isInMixedFolder, ImageType.Screenshot);
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
|
2015-10-04 03:38:46 +00:00
|
|
|
private void PopulateBackdrops(List<LocalImageInfo> images, List<FileSystemMetadata> files, string imagePrefix, string firstFileName, string subsequentFileNamePrefix, bool isInMixedFolder, ImageType type)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
|
|
|
AddImage(files, images, imagePrefix + firstFileName, type);
|
|
|
|
|
|
|
|
var unfound = 0;
|
|
|
|
for (var i = 1; i <= 20; i++)
|
|
|
|
{
|
|
|
|
// Screenshot Image
|
|
|
|
var found = AddImage(files, images, imagePrefix + subsequentFileNamePrefix + i, type);
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
unfound++;
|
|
|
|
|
|
|
|
if (unfound >= 3)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-09 04:57:18 +00:00
|
|
|
|
|
|
|
// Support without the prefix
|
|
|
|
if (!isInMixedFolder)
|
|
|
|
{
|
|
|
|
AddImage(files, images, firstFileName, type);
|
|
|
|
|
|
|
|
unfound = 0;
|
|
|
|
for (var i = 1; i <= 20; i++)
|
|
|
|
{
|
|
|
|
// Screenshot Image
|
|
|
|
var found = AddImage(files, images, subsequentFileNamePrefix + i, type);
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
unfound++;
|
|
|
|
|
|
|
|
if (unfound >= 3)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 18:39:41 +00:00
|
|
|
private void PopulateSeasonImagesFromSeriesFolder(Season season, List<LocalImageInfo> images, IDirectoryService directoryService)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
|
|
|
var seasonNumber = season.IndexNumber;
|
|
|
|
|
|
|
|
var series = season.Series;
|
2018-09-12 17:26:21 +00:00
|
|
|
if (!seasonNumber.HasValue || !series.IsFileProtocol)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-08 22:38:02 +00:00
|
|
|
var seriesFiles = GetFiles(series, false, directoryService).ToList();
|
2014-01-28 18:37:01 +00:00
|
|
|
|
|
|
|
// Try using the season name
|
2020-06-14 02:04:53 +00:00
|
|
|
var prefix = season.Name.Replace(" ", string.Empty, StringComparison.Ordinal).ToLowerInvariant();
|
2014-01-28 18:37:01 +00:00
|
|
|
|
|
|
|
var filenamePrefixes = new List<string> { prefix };
|
|
|
|
|
|
|
|
var seasonMarker = seasonNumber.Value == 0
|
|
|
|
? "-specials"
|
|
|
|
: seasonNumber.Value.ToString("00", _usCulture);
|
|
|
|
|
|
|
|
// Get this one directly from the file system since we have to go up a level
|
|
|
|
if (!string.Equals(prefix, seasonMarker, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
filenamePrefixes.Add("season" + seasonMarker);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var filename in filenamePrefixes)
|
|
|
|
{
|
2014-02-07 22:40:03 +00:00
|
|
|
AddImage(seriesFiles, images, filename + "-poster", ImageType.Primary);
|
|
|
|
AddImage(seriesFiles, images, filename + "-fanart", ImageType.Backdrop);
|
|
|
|
AddImage(seriesFiles, images, filename + "-banner", ImageType.Banner);
|
|
|
|
AddImage(seriesFiles, images, filename + "-landscape", ImageType.Thumb);
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 03:38:46 +00:00
|
|
|
private bool AddImage(List<FileSystemMetadata> files, List<LocalImageInfo> images, string name, string imagePrefix, bool isInMixedFolder, ImageType type)
|
2014-12-09 04:57:18 +00:00
|
|
|
{
|
|
|
|
var added = AddImage(files, images, imagePrefix + name, type);
|
|
|
|
|
|
|
|
if (!isInMixedFolder)
|
|
|
|
{
|
|
|
|
if (AddImage(files, images, name, type))
|
|
|
|
{
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return added;
|
|
|
|
}
|
|
|
|
|
2021-05-16 12:49:11 +00:00
|
|
|
private bool AddImage(List<FileSystemMetadata> files, List<LocalImageInfo> images, string name, ImageType type)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2015-10-04 03:38:46 +00:00
|
|
|
var image = GetImage(files, name);
|
2014-01-28 18:37:01 +00:00
|
|
|
|
|
|
|
if (image != null)
|
|
|
|
{
|
|
|
|
images.Add(new LocalImageInfo
|
|
|
|
{
|
2014-02-07 22:40:03 +00:00
|
|
|
FileInfo = image,
|
2014-01-28 18:37:01 +00:00
|
|
|
Type = type
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-16 12:49:11 +00:00
|
|
|
private static FileSystemMetadata? GetImage(IReadOnlyList<FileSystemMetadata> files, string name)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2021-05-16 12:49:11 +00:00
|
|
|
for (var i = 0; i < files.Count; i++)
|
|
|
|
{
|
|
|
|
var file = files[i];
|
|
|
|
if (!file.IsDirectory
|
|
|
|
&& file.Length > 0
|
|
|
|
&& Path.GetFileNameWithoutExtension(file.FullName.AsSpan()).Equals(name, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|