jellyfin/MediaBrowser.Providers/Manager/ImageSaver.cs

641 lines
24 KiB
C#
Raw Normal View History

#nullable disable
#pragma warning disable CS1591
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2021-12-20 07:31:07 -05:00
using Jellyfin.Extensions;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
2016-10-25 15:02:04 -04:00
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using Microsoft.Extensions.Logging;
2020-05-12 22:10:35 -04:00
using Episode = MediaBrowser.Controller.Entities.TV.Episode;
using MusicAlbum = MediaBrowser.Controller.Entities.Audio.MusicAlbum;
using Person = MediaBrowser.Controller.Entities.Person;
using Season = MediaBrowser.Controller.Entities.TV.Season;
namespace MediaBrowser.Providers.Manager
{
/// <summary>
/// Class ImageSaver.
/// </summary>
public class ImageSaver
{
/// <summary>
/// The _config.
/// </summary>
private readonly IServerConfigurationManager _config;
/// <summary>
/// The _directory watchers.
/// </summary>
private readonly ILibraryMonitor _libraryMonitor;
private readonly IFileSystem _fileSystem;
2013-11-08 10:35:11 -05:00
private readonly ILogger _logger;
/// <summary>
2014-02-08 15:02:35 -05:00
/// Initializes a new instance of the <see cref="ImageSaver" /> class.
/// </summary>
/// <param name="config">The config.</param>
/// <param name="libraryMonitor">The directory watchers.</param>
2014-02-08 15:02:35 -05:00
/// <param name="fileSystem">The file system.</param>
/// <param name="logger">The logger.</param>
2018-09-12 13:26:21 -04:00
public ImageSaver(IServerConfigurationManager config, ILibraryMonitor libraryMonitor, IFileSystem fileSystem, ILogger logger)
{
_config = config;
_libraryMonitor = libraryMonitor;
_fileSystem = fileSystem;
2013-11-08 10:35:11 -05:00
_logger = logger;
}
2020-09-07 07:20:39 -04:00
private bool EnableExtraThumbsDuplication
{
get
{
var config = _config.GetConfiguration<XbmcMetadataOptions>("xbmcmetadata");
return config.EnableExtraThumbsDuplication;
}
}
/// <summary>
/// Saves the image.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="source">The source.</param>
/// <param name="mimeType">Type of the MIME.</param>
/// <param name="type">The type.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
2020-09-07 07:20:39 -04:00
/// <exception cref="ArgumentNullException">mimeType.</exception>
2018-09-12 13:26:21 -04:00
public Task SaveImage(BaseItem item, Stream source, string mimeType, ImageType type, int? imageIndex, CancellationToken cancellationToken)
2014-10-19 23:04:45 -04:00
{
return SaveImage(item, source, mimeType, type, imageIndex, null, cancellationToken);
}
2018-09-12 13:26:21 -04:00
public async Task SaveImage(BaseItem item, Stream source, string mimeType, ImageType type, int? imageIndex, bool? saveLocallyWithMedia, CancellationToken cancellationToken)
{
ArgumentException.ThrowIfNullOrEmpty(mimeType);
2021-08-28 18:32:50 -04:00
var saveLocally = item.SupportsLocalMetadata && item.IsSaveLocalMetadataEnabled() && !item.ExtraType.HasValue && item is not Audio;
2013-10-25 16:58:31 -04:00
if (type != ImageType.Primary && item is Episode)
{
2013-10-25 16:58:31 -04:00
saveLocally = false;
}
2018-09-12 13:26:21 -04:00
if (!item.IsFileProtocol)
{
saveLocally = false;
// If season is virtual under a physical series, save locally if using compatible convention
2021-02-15 08:19:08 -05:00
if (item is Season season && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Compatible)
{
var series = season.Series;
2022-12-05 09:01:13 -05:00
if (series is not null && series.SupportsLocalMetadata && series.IsSaveLocalMetadataEnabled())
{
2014-02-10 15:11:46 -05:00
saveLocally = true;
}
}
}
2020-06-15 17:43:52 -04:00
2016-10-17 12:35:29 -04:00
if (saveLocallyWithMedia.HasValue && !saveLocallyWithMedia.Value)
2014-10-19 23:04:45 -04:00
{
2016-10-17 12:35:29 -04:00
saveLocally = saveLocallyWithMedia.Value;
2014-10-19 23:04:45 -04:00
}
2014-02-07 15:30:41 -05:00
if (!imageIndex.HasValue && item.AllowsMultipleImages(type))
{
2014-02-07 15:30:41 -05:00
imageIndex = item.GetImages(type).Count();
}
2013-12-19 16:51:32 -05:00
var index = imageIndex ?? 0;
2015-10-30 12:45:22 -04:00
var paths = GetSavePaths(item, type, imageIndex, mimeType, saveLocally);
2015-10-30 12:45:22 -04:00
var retryPaths = GetSavePaths(item, type, imageIndex, mimeType, false);
// If there are more than one output paths, the stream will need to be seekable
2020-08-07 11:38:01 -04:00
if (paths.Length > 1 && !source.CanSeek)
{
2020-08-07 11:38:01 -04:00
var memoryStream = new MemoryStream();
await using (source.ConfigureAwait(false))
{
2021-02-15 08:19:08 -05:00
await source.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false);
2020-08-07 11:38:01 -04:00
}
2020-08-07 11:38:01 -04:00
source = memoryStream;
}
2015-10-16 13:06:31 -04:00
var currentImage = GetCurrentImage(item, type, index);
2022-12-05 09:01:13 -05:00
var currentImageIsLocalFile = currentImage is not null && currentImage.IsLocalFile;
var currentImagePath = currentImage?.Path;
2016-01-16 22:23:59 -05:00
var savedPaths = new List<string>();
await using (source.ConfigureAwait(false))
{
2020-08-07 11:38:01 -04:00
for (int i = 0; i < paths.Length; i++)
{
2020-08-07 11:38:01 -04:00
if (i != 0)
{
source.Position = 0;
}
2015-10-10 20:39:30 -04:00
string retryPath = null;
if (paths.Length == retryPaths.Length)
{
2020-08-07 11:38:01 -04:00
retryPath = retryPaths[i];
2015-10-10 20:39:30 -04:00
}
2020-06-15 17:43:52 -04:00
2020-08-07 11:38:01 -04:00
var savedPath = await SaveImageToLocation(source, paths[i], retryPath, cancellationToken).ConfigureAwait(false);
2016-01-16 22:23:59 -05:00
savedPaths.Add(savedPath);
}
}
2013-12-19 16:51:32 -05:00
// Set the path into the item
2016-01-16 22:23:59 -05:00
SetImagePath(item, type, imageIndex, savedPaths[0]);
// Delete the current path
if (currentImageIsLocalFile
2021-12-20 07:31:07 -05:00
&& !savedPaths.Contains(currentImagePath, StringComparison.OrdinalIgnoreCase)
&& (saveLocally || currentImagePath.Contains(_config.ApplicationPaths.InternalMetadataPath, StringComparison.OrdinalIgnoreCase)))
{
var currentPath = currentImagePath;
2015-10-16 13:06:31 -04:00
_logger.LogInformation("Deleting previous image {0}", currentPath);
2016-06-27 00:19:10 -04:00
_libraryMonitor.ReportFileSystemChangeBeginning(currentPath);
try
{
2017-03-24 11:03:49 -04:00
_fileSystem.DeleteFile(currentPath);
}
catch (FileNotFoundException)
{
}
finally
{
_libraryMonitor.ReportFileSystemChangeComplete(currentPath, false);
}
}
}
2020-08-07 13:26:28 -04:00
public async Task SaveImage(Stream source, string path)
2020-05-12 22:10:35 -04:00
{
await SaveImageToLocation(source, path, path, CancellationToken.None).ConfigureAwait(false);
}
2016-01-16 22:23:59 -05:00
private async Task<string> SaveImageToLocation(Stream source, string path, string retryPath, CancellationToken cancellationToken)
{
try
{
await SaveImageToLocation(source, path, cancellationToken).ConfigureAwait(false);
2016-01-16 22:23:59 -05:00
return path;
}
catch (UnauthorizedAccessException)
{
2015-10-30 12:45:22 -04:00
var retry = !string.IsNullOrWhiteSpace(retryPath) &&
2015-10-10 20:39:30 -04:00
!string.Equals(path, retryPath, StringComparison.OrdinalIgnoreCase);
if (retry)
{
_logger.LogError("UnauthorizedAccessException - Access to path {0} is denied. Will retry saving to {1}", path, retryPath);
}
else
{
throw;
}
}
2016-10-03 02:28:45 -04:00
catch (IOException ex)
{
var retry = !string.IsNullOrWhiteSpace(retryPath) &&
!string.Equals(path, retryPath, StringComparison.OrdinalIgnoreCase);
if (retry)
{
2018-12-20 07:11:26 -05:00
_logger.LogError(ex, "IOException saving to {0}. Will retry saving to {1}", path, retryPath);
2016-10-03 02:28:45 -04:00
}
else
{
throw;
}
}
await SaveImageToLocation(source, retryPath, cancellationToken).ConfigureAwait(false);
2016-01-16 22:23:59 -05:00
return retryPath;
}
/// <summary>
/// Saves the image to location.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="path">The path.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
private async Task SaveImageToLocation(Stream source, string path, CancellationToken cancellationToken)
{
_logger.LogDebug("Saving image to {0}", path);
2013-11-08 10:35:11 -05:00
var parentFolder = Path.GetDirectoryName(path);
2013-11-08 10:35:11 -05:00
try
{
2017-02-04 16:22:55 -05:00
_libraryMonitor.ReportFileSystemChangeBeginning(path);
_libraryMonitor.ReportFileSystemChangeBeginning(parentFolder);
Directory.CreateDirectory(Path.GetDirectoryName(path));
2017-05-12 00:54:19 -04:00
_fileSystem.SetAttributes(path, false, false);
var fileStreamOptions = AsyncFile.WriteOptions;
fileStreamOptions.Mode = FileMode.Create;
if (source.CanSeek)
{
fileStreamOptions.PreallocationSize = source.Length;
}
var fs = new FileStream(path, fileStreamOptions);
await using (fs.ConfigureAwait(false))
{
2020-08-07 11:38:01 -04:00
await source.CopyToAsync(fs, cancellationToken).ConfigureAwait(false);
}
if (_config.Configuration.SaveMetadataHidden)
{
2017-11-15 16:33:04 -05:00
SetHidden(path, true);
}
}
finally
{
_libraryMonitor.ReportFileSystemChangeComplete(path, false);
_libraryMonitor.ReportFileSystemChangeComplete(parentFolder, false);
}
}
2017-11-15 16:33:04 -05:00
private void SetHidden(string path, bool hidden)
{
try
{
_fileSystem.SetHidden(path, hidden);
}
catch (Exception ex)
{
2018-12-20 07:11:26 -05:00
_logger.LogError(ex, "Error setting hidden attribute on {0}", path);
2017-11-15 16:33:04 -05:00
}
}
/// <summary>
/// Gets the save paths.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <param name="mimeType">Type of the MIME.</param>
/// <param name="saveLocally">if set to <c>true</c> [save locally].</param>
/// <returns>IEnumerable{System.String}.</returns>
2018-09-12 13:26:21 -04:00
private string[] GetSavePaths(BaseItem item, ImageType type, int? imageIndex, string mimeType, bool saveLocally)
{
2016-06-28 00:47:30 -04:00
if (!saveLocally || (_config.Configuration.ImageSavingConvention == ImageSavingConvention.Legacy))
{
2013-10-17 11:35:39 -04:00
return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, saveLocally) };
}
return GetCompatibleSavePaths(item, type, imageIndex, mimeType);
}
/// <summary>
/// Gets the current image path.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <returns>System.String.</returns>
2019-01-13 15:37:13 -05:00
/// <exception cref="ArgumentNullException">
/// imageIndex
/// or
2020-09-07 07:20:39 -04:00
/// imageIndex.
/// </exception>
2018-09-12 13:26:21 -04:00
private ItemImageInfo GetCurrentImage(BaseItem item, ImageType type, int imageIndex)
{
2015-10-16 13:06:31 -04:00
return item.GetImageInfo(type, imageIndex);
}
/// <summary>
/// Sets the image path.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <param name="path">The path.</param>
2019-01-13 15:37:13 -05:00
/// <exception cref="ArgumentNullException">imageIndex
/// or
2020-09-07 07:20:39 -04:00
/// imageIndex.
/// </exception>
2018-09-12 13:26:21 -04:00
private void SetImagePath(BaseItem item, ImageType type, int? imageIndex, string path)
{
2015-10-03 23:38:46 -04:00
item.SetImagePath(type, imageIndex ?? 0, _fileSystem.GetFileInfo(path));
}
/// <summary>
/// Gets the save path.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <param name="mimeType">Type of the MIME.</param>
/// <param name="saveLocally">if set to <c>true</c> [save locally].</param>
/// <returns>System.String.</returns>
2019-01-13 15:37:13 -05:00
/// <exception cref="ArgumentNullException">
/// imageIndex
/// or
2020-09-07 07:20:39 -04:00
/// imageIndex.
/// </exception>
2018-09-12 13:26:21 -04:00
private string GetStandardSavePath(BaseItem item, ImageType type, int? imageIndex, string mimeType, bool saveLocally)
{
2016-01-21 21:59:07 -05:00
var season = item as Season;
var extension = MimeTypes.ToExtension(mimeType);
2016-10-19 02:29:00 -04:00
if (string.IsNullOrWhiteSpace(extension))
{
2020-08-07 13:26:28 -04:00
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Unable to determine image file extension from mime type {0}", mimeType));
2016-10-19 02:29:00 -04:00
}
2016-01-21 21:59:07 -05:00
if (type == ImageType.Thumb && saveLocally)
{
2022-12-05 09:01:13 -05:00
if (season is not null && season.IndexNumber.HasValue)
2016-01-21 21:59:07 -05:00
{
var seriesFolder = season.SeriesPath;
var seasonMarker = season.IndexNumber.Value == 0
? "-specials"
2021-09-26 10:14:36 -04:00
: season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
2016-01-21 21:59:07 -05:00
var imageFilename = "season" + seasonMarker + "-landscape" + extension;
return Path.Combine(seriesFolder, imageFilename);
}
2017-07-31 01:16:22 -04:00
if (item.IsInMixedFolder)
2016-01-21 21:59:07 -05:00
{
return GetSavePathForItemInMixedFolder(item, type, "landscape", extension);
}
return Path.Combine(item.ContainingFolderPath, "landscape" + extension);
}
if (type == ImageType.Banner && saveLocally)
{
2022-12-05 09:01:13 -05:00
if (season is not null && season.IndexNumber.HasValue)
2016-01-21 21:59:07 -05:00
{
var seriesFolder = season.SeriesPath;
var seasonMarker = season.IndexNumber.Value == 0
? "-specials"
2021-09-26 10:14:36 -04:00
: season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
2016-01-21 21:59:07 -05:00
var imageFilename = "season" + seasonMarker + "-banner" + extension;
return Path.Combine(seriesFolder, imageFilename);
}
}
string filename;
2016-06-27 00:19:10 -04:00
var folderName = item is MusicAlbum ||
item is MusicArtist ||
item is PhotoAlbum ||
2017-03-05 10:38:17 -05:00
item is Person ||
2016-06-27 00:19:10 -04:00
(saveLocally && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Legacy) ?
"folder" :
2016-02-05 21:13:36 -05:00
"poster";
2014-10-19 23:04:45 -04:00
switch (type)
{
case ImageType.Art:
filename = "clearart";
break;
2014-01-28 20:47:47 -05:00
case ImageType.BoxRear:
filename = "back";
break;
2016-01-21 21:59:07 -05:00
case ImageType.Thumb:
filename = "landscape";
break;
2013-11-19 11:44:53 -05:00
case ImageType.Disc:
filename = item is MusicAlbum ? "cdart" : "disc";
break;
case ImageType.Primary:
filename = saveLocally && item is Episode ? Path.GetFileNameWithoutExtension(item.Path) : folderName;
break;
case ImageType.Backdrop:
2014-02-07 15:30:41 -05:00
filename = GetBackdropSaveFilename(item.GetImages(type), "backdrop", "backdrop", imageIndex);
break;
default:
2019-01-27 06:03:43 -05:00
filename = type.ToString().ToLowerInvariant();
break;
}
2016-01-23 12:12:11 -05:00
if (string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase))
{
2016-01-23 12:12:11 -05:00
extension = ".jpg";
}
2019-01-27 06:03:43 -05:00
extension = extension.ToLowerInvariant();
string path = null;
if (saveLocally)
{
2016-03-21 16:15:18 -04:00
if (type == ImageType.Primary && item is Episode)
{
path = Path.Combine(Path.GetDirectoryName(item.Path), "metadata", filename + extension);
}
2017-07-31 01:16:22 -04:00
else if (item.IsInMixedFolder)
{
path = GetSavePathForItemInMixedFolder(item, type, filename, extension);
}
2013-10-25 16:58:31 -04:00
if (string.IsNullOrEmpty(path))
{
path = Path.Combine(item.ContainingFolderPath, filename + extension);
}
}
// None of the save local conditions passed, so store it in our internal folders
if (string.IsNullOrEmpty(path))
{
2014-02-08 23:52:52 -05:00
if (string.IsNullOrEmpty(filename))
{
2016-01-21 21:59:07 -05:00
filename = folderName;
2014-02-08 23:52:52 -05:00
}
2020-06-15 17:43:52 -04:00
2014-09-28 11:27:26 -04:00
path = Path.Combine(item.GetInternalMetadataPath(), filename + extension);
}
return path;
}
2014-02-07 15:30:41 -05:00
private string GetBackdropSaveFilename(IEnumerable<ItemImageInfo> images, string zeroIndexFilename, string numberedIndexPrefix, int? index)
{
2014-02-07 15:30:41 -05:00
if (index.HasValue && index.Value == 0)
{
return zeroIndexFilename;
}
var filenames = images.Select(i => Path.GetFileNameWithoutExtension(i.Path)).ToList();
2013-11-02 21:58:56 -04:00
2014-02-07 15:30:41 -05:00
var current = 1;
2021-12-20 07:31:07 -05:00
while (filenames.Contains(numberedIndexPrefix + current.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase))
{
current++;
}
2021-09-26 10:14:36 -04:00
return numberedIndexPrefix + current.ToString(CultureInfo.InvariantCulture);
}
/// <summary>
/// Gets the compatible save paths.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <param name="mimeType">Type of the MIME.</param>
/// <returns>IEnumerable{System.String}.</returns>
2020-09-07 07:20:39 -04:00
/// <exception cref="ArgumentNullException">imageIndex.</exception>
2018-09-12 13:26:21 -04:00
private string[] GetCompatibleSavePaths(BaseItem item, ImageType type, int? imageIndex, string mimeType)
{
var season = item as Season;
2014-10-19 23:04:45 -04:00
var extension = MimeTypes.ToExtension(mimeType);
// Backdrop paths
if (type == ImageType.Backdrop)
{
if (!imageIndex.HasValue)
{
throw new ArgumentNullException(nameof(imageIndex));
}
if (imageIndex.Value == 0)
{
2017-07-31 01:16:22 -04:00
if (item.IsInMixedFolder)
2013-12-11 18:30:41 -05:00
{
return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) };
}
2022-12-05 09:01:13 -05:00
if (season is not null && season.IndexNumber.HasValue)
2013-10-15 21:44:23 -04:00
{
var seriesFolder = season.SeriesPath;
2013-10-15 21:44:23 -04:00
2014-02-15 17:42:06 -05:00
var seasonMarker = season.IndexNumber.Value == 0
2013-10-15 21:44:23 -04:00
? "-specials"
2021-09-26 10:14:36 -04:00
: season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
2013-10-15 21:44:23 -04:00
var imageFilename = "season" + seasonMarker + "-fanart" + extension;
return new[] { Path.Combine(seriesFolder, imageFilename) };
}
return new[]
{
Path.Combine(item.ContainingFolderPath, "fanart" + extension)
};
}
var outputIndex = imageIndex.Value;
2017-07-31 01:16:22 -04:00
if (item.IsInMixedFolder)
2013-12-11 18:30:41 -05:00
{
2021-09-26 10:14:36 -04:00
return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + outputIndex.ToString(CultureInfo.InvariantCulture), extension) };
2013-12-11 18:30:41 -05:00
}
2014-02-07 15:30:41 -05:00
var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", outputIndex);
2013-11-02 21:58:56 -04:00
var list = new List<string>
{
Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension)
};
if (EnableExtraThumbsDuplication)
{
2021-09-26 10:14:36 -04:00
list.Add(Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + outputIndex.ToString(CultureInfo.InvariantCulture) + extension));
}
2020-06-15 17:43:52 -04:00
2018-12-28 10:48:26 -05:00
return list.ToArray();
}
if (type == ImageType.Primary)
{
2022-12-05 09:01:13 -05:00
if (season is not null && season.IndexNumber.HasValue)
{
var seriesFolder = season.SeriesPath;
2014-02-15 17:42:06 -05:00
var seasonMarker = season.IndexNumber.Value == 0
? "-specials"
2021-09-26 10:14:36 -04:00
: season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
var imageFilename = "season" + seasonMarker + "-poster" + extension;
return new[] { Path.Combine(seriesFolder, imageFilename) };
}
if (item is Episode)
{
var seasonFolder = Path.GetDirectoryName(item.Path);
var imageFilename = Path.GetFileNameWithoutExtension(item.Path) + "-thumb" + extension;
return new[] { Path.Combine(seasonFolder, imageFilename) };
}
2017-07-31 01:16:22 -04:00
if (item.IsInMixedFolder || item is MusicVideo)
{
return new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) };
}
2013-11-21 15:48:26 -05:00
if (item is MusicAlbum || item is MusicArtist)
{
return new[] { Path.Combine(item.ContainingFolderPath, "folder" + extension) };
}
return new[] { Path.Combine(item.ContainingFolderPath, "poster" + extension) };
}
// All other paths are the same
2013-10-17 11:35:39 -04:00
return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, true) };
}
/// <summary>
/// Gets the save path for item in mixed folder.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="imageFilename">The image filename.</param>
/// <param name="extension">The extension.</param>
/// <returns>System.String.</returns>
2018-09-12 13:26:21 -04:00
private string GetSavePathForItemInMixedFolder(BaseItem item, ImageType type, string imageFilename, string extension)
{
if (type == ImageType.Primary)
{
imageFilename = "poster";
}
2020-06-15 17:43:52 -04:00
var folder = Path.GetDirectoryName(item.Path);
return Path.Combine(folder, Path.GetFileNameWithoutExtension(item.Path) + "-" + imageFilename + extension);
}
}
}