ImageSaver.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using Jellyfin.Extensions;
  11. using MediaBrowser.Common.Configuration;
  12. using MediaBrowser.Controller.Configuration;
  13. using MediaBrowser.Controller.Entities;
  14. using MediaBrowser.Controller.Entities.Audio;
  15. using MediaBrowser.Controller.Library;
  16. using MediaBrowser.Model.Configuration;
  17. using MediaBrowser.Model.Entities;
  18. using MediaBrowser.Model.IO;
  19. using MediaBrowser.Model.Net;
  20. using Microsoft.Extensions.Logging;
  21. using Episode = MediaBrowser.Controller.Entities.TV.Episode;
  22. using MusicAlbum = MediaBrowser.Controller.Entities.Audio.MusicAlbum;
  23. using Person = MediaBrowser.Controller.Entities.Person;
  24. using Season = MediaBrowser.Controller.Entities.TV.Season;
  25. namespace MediaBrowser.Providers.Manager
  26. {
  27. /// <summary>
  28. /// Class ImageSaver.
  29. /// </summary>
  30. public class ImageSaver
  31. {
  32. /// <summary>
  33. /// The _config.
  34. /// </summary>
  35. private readonly IServerConfigurationManager _config;
  36. /// <summary>
  37. /// The _directory watchers.
  38. /// </summary>
  39. private readonly ILibraryMonitor _libraryMonitor;
  40. private readonly IFileSystem _fileSystem;
  41. private readonly ILogger _logger;
  42. /// <summary>
  43. /// Initializes a new instance of the <see cref="ImageSaver" /> class.
  44. /// </summary>
  45. /// <param name="config">The config.</param>
  46. /// <param name="libraryMonitor">The directory watchers.</param>
  47. /// <param name="fileSystem">The file system.</param>
  48. /// <param name="logger">The logger.</param>
  49. public ImageSaver(IServerConfigurationManager config, ILibraryMonitor libraryMonitor, IFileSystem fileSystem, ILogger logger)
  50. {
  51. _config = config;
  52. _libraryMonitor = libraryMonitor;
  53. _fileSystem = fileSystem;
  54. _logger = logger;
  55. }
  56. private bool EnableExtraThumbsDuplication
  57. {
  58. get
  59. {
  60. var config = _config.GetConfiguration<XbmcMetadataOptions>("xbmcmetadata");
  61. return config.EnableExtraThumbsDuplication;
  62. }
  63. }
  64. /// <summary>
  65. /// Saves the image.
  66. /// </summary>
  67. /// <param name="item">The item.</param>
  68. /// <param name="source">The source.</param>
  69. /// <param name="mimeType">Type of the MIME.</param>
  70. /// <param name="type">The type.</param>
  71. /// <param name="imageIndex">Index of the image.</param>
  72. /// <param name="cancellationToken">The cancellation token.</param>
  73. /// <returns>Task.</returns>
  74. /// <exception cref="ArgumentNullException">mimeType.</exception>
  75. public Task SaveImage(BaseItem item, Stream source, string mimeType, ImageType type, int? imageIndex, CancellationToken cancellationToken)
  76. {
  77. return SaveImage(item, source, mimeType, type, imageIndex, null, cancellationToken);
  78. }
  79. public async Task SaveImage(BaseItem item, Stream source, string mimeType, ImageType type, int? imageIndex, bool? saveLocallyWithMedia, CancellationToken cancellationToken)
  80. {
  81. ArgumentException.ThrowIfNullOrEmpty(mimeType);
  82. var saveLocally = item.SupportsLocalMetadata && item.IsSaveLocalMetadataEnabled() && !item.ExtraType.HasValue && item is not Audio;
  83. if (type != ImageType.Primary && item is Episode)
  84. {
  85. saveLocally = false;
  86. }
  87. if (!item.IsFileProtocol)
  88. {
  89. saveLocally = false;
  90. // If season is virtual under a physical series, save locally
  91. if (item is Season season)
  92. {
  93. var series = season.Series;
  94. if (series is not null && series.SupportsLocalMetadata && series.IsSaveLocalMetadataEnabled())
  95. {
  96. saveLocally = true;
  97. }
  98. }
  99. }
  100. if (saveLocallyWithMedia.HasValue && !saveLocallyWithMedia.Value)
  101. {
  102. saveLocally = saveLocallyWithMedia.Value;
  103. }
  104. if (!imageIndex.HasValue && item.AllowsMultipleImages(type))
  105. {
  106. imageIndex = item.GetImages(type).Count();
  107. }
  108. var index = imageIndex ?? 0;
  109. var paths = GetSavePaths(item, type, imageIndex, mimeType, saveLocally);
  110. string[] retryPaths = [];
  111. if (saveLocally)
  112. {
  113. retryPaths = GetSavePaths(item, type, imageIndex, mimeType, false);
  114. }
  115. // If there are more than one output paths, the stream will need to be seekable
  116. if (paths.Length > 1 && !source.CanSeek)
  117. {
  118. var memoryStream = new MemoryStream();
  119. await using (source.ConfigureAwait(false))
  120. {
  121. await source.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false);
  122. }
  123. source = memoryStream;
  124. }
  125. var currentImage = GetCurrentImage(item, type, index);
  126. var currentImageIsLocalFile = currentImage is not null && currentImage.IsLocalFile;
  127. var currentImagePath = currentImage?.Path;
  128. var savedPaths = new List<string>();
  129. await using (source.ConfigureAwait(false))
  130. {
  131. for (int i = 0; i < paths.Length; i++)
  132. {
  133. if (i != 0)
  134. {
  135. source.Position = 0;
  136. }
  137. string retryPath = null;
  138. if (paths.Length == retryPaths.Length)
  139. {
  140. retryPath = retryPaths[i];
  141. }
  142. var savedPath = await SaveImageToLocation(source, paths[i], retryPath, cancellationToken).ConfigureAwait(false);
  143. savedPaths.Add(savedPath);
  144. }
  145. }
  146. // Set the path into the item
  147. SetImagePath(item, type, imageIndex, savedPaths[0]);
  148. // Delete the current path
  149. if (currentImageIsLocalFile
  150. && !savedPaths.Contains(currentImagePath, StringComparison.OrdinalIgnoreCase)
  151. && (saveLocally || currentImagePath.Contains(_config.ApplicationPaths.InternalMetadataPath, StringComparison.OrdinalIgnoreCase)))
  152. {
  153. var currentPath = currentImagePath;
  154. _logger.LogInformation("Deleting previous image {0}", currentPath);
  155. _libraryMonitor.ReportFileSystemChangeBeginning(currentPath);
  156. try
  157. {
  158. _fileSystem.DeleteFile(currentPath);
  159. // Remove containing directory if empty
  160. var folder = Path.GetDirectoryName(currentPath);
  161. if (!_fileSystem.GetFiles(folder).Any())
  162. {
  163. Directory.Delete(folder);
  164. }
  165. }
  166. catch (FileNotFoundException)
  167. {
  168. }
  169. finally
  170. {
  171. _libraryMonitor.ReportFileSystemChangeComplete(currentPath, false);
  172. }
  173. }
  174. }
  175. public async Task SaveImage(Stream source, string path)
  176. {
  177. await SaveImageToLocation(source, path, path, CancellationToken.None).ConfigureAwait(false);
  178. }
  179. private async Task<string> SaveImageToLocation(Stream source, string path, string retryPath, CancellationToken cancellationToken)
  180. {
  181. try
  182. {
  183. await SaveImageToLocation(source, path, cancellationToken).ConfigureAwait(false);
  184. return path;
  185. }
  186. catch (UnauthorizedAccessException)
  187. {
  188. var retry = !string.IsNullOrWhiteSpace(retryPath) &&
  189. !string.Equals(path, retryPath, StringComparison.OrdinalIgnoreCase);
  190. if (retry)
  191. {
  192. _logger.LogError("UnauthorizedAccessException - Access to path {0} is denied. Will retry saving to {1}", path, retryPath);
  193. }
  194. else
  195. {
  196. throw;
  197. }
  198. }
  199. catch (IOException ex)
  200. {
  201. var retry = !string.IsNullOrWhiteSpace(retryPath) &&
  202. !string.Equals(path, retryPath, StringComparison.OrdinalIgnoreCase);
  203. if (retry)
  204. {
  205. _logger.LogError(ex, "IOException saving to {0}. Will retry saving to {1}", path, retryPath);
  206. }
  207. else
  208. {
  209. throw;
  210. }
  211. }
  212. await SaveImageToLocation(source, retryPath, cancellationToken).ConfigureAwait(false);
  213. return retryPath;
  214. }
  215. /// <summary>
  216. /// Saves the image to location.
  217. /// </summary>
  218. /// <param name="source">The source.</param>
  219. /// <param name="path">The path.</param>
  220. /// <param name="cancellationToken">The cancellation token.</param>
  221. /// <returns>Task.</returns>
  222. private async Task SaveImageToLocation(Stream source, string path, CancellationToken cancellationToken)
  223. {
  224. _logger.LogDebug("Saving image to {0}", path);
  225. var parentFolder = Path.GetDirectoryName(path);
  226. try
  227. {
  228. _libraryMonitor.ReportFileSystemChangeBeginning(path);
  229. _libraryMonitor.ReportFileSystemChangeBeginning(parentFolder);
  230. Directory.CreateDirectory(Path.GetDirectoryName(path));
  231. _fileSystem.SetAttributes(path, false, false);
  232. var fileStreamOptions = AsyncFile.WriteOptions;
  233. fileStreamOptions.Mode = FileMode.Create;
  234. if (source.CanSeek)
  235. {
  236. fileStreamOptions.PreallocationSize = source.Length;
  237. }
  238. var fs = new FileStream(path, fileStreamOptions);
  239. await using (fs.ConfigureAwait(false))
  240. {
  241. await source.CopyToAsync(fs, cancellationToken).ConfigureAwait(false);
  242. }
  243. if (_config.Configuration.SaveMetadataHidden)
  244. {
  245. SetHidden(path, true);
  246. }
  247. }
  248. finally
  249. {
  250. _libraryMonitor.ReportFileSystemChangeComplete(path, false);
  251. _libraryMonitor.ReportFileSystemChangeComplete(parentFolder, false);
  252. }
  253. }
  254. private void SetHidden(string path, bool hidden)
  255. {
  256. try
  257. {
  258. _fileSystem.SetHidden(path, hidden);
  259. }
  260. catch (Exception ex)
  261. {
  262. _logger.LogError(ex, "Error setting hidden attribute on {0}", path);
  263. }
  264. }
  265. /// <summary>
  266. /// Gets the save paths.
  267. /// </summary>
  268. /// <param name="item">The item.</param>
  269. /// <param name="type">The type.</param>
  270. /// <param name="imageIndex">Index of the image.</param>
  271. /// <param name="mimeType">Type of the MIME.</param>
  272. /// <param name="saveLocally">if set to <c>true</c> [save locally].</param>
  273. /// <returns>IEnumerable{System.String}.</returns>
  274. private string[] GetSavePaths(BaseItem item, ImageType type, int? imageIndex, string mimeType, bool saveLocally)
  275. {
  276. if (!saveLocally || (_config.Configuration.ImageSavingConvention == ImageSavingConvention.Legacy))
  277. {
  278. return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, saveLocally) };
  279. }
  280. return GetCompatibleSavePaths(item, type, imageIndex, mimeType);
  281. }
  282. /// <summary>
  283. /// Gets the current image path.
  284. /// </summary>
  285. /// <param name="item">The item.</param>
  286. /// <param name="type">The type.</param>
  287. /// <param name="imageIndex">Index of the image.</param>
  288. /// <returns>System.String.</returns>
  289. /// <exception cref="ArgumentNullException">
  290. /// imageIndex
  291. /// or
  292. /// imageIndex.
  293. /// </exception>
  294. private ItemImageInfo GetCurrentImage(BaseItem item, ImageType type, int imageIndex)
  295. {
  296. return item.GetImageInfo(type, imageIndex);
  297. }
  298. /// <summary>
  299. /// Sets the image path.
  300. /// </summary>
  301. /// <param name="item">The item.</param>
  302. /// <param name="type">The type.</param>
  303. /// <param name="imageIndex">Index of the image.</param>
  304. /// <param name="path">The path.</param>
  305. /// <exception cref="ArgumentNullException">imageIndex
  306. /// or
  307. /// imageIndex.
  308. /// </exception>
  309. private void SetImagePath(BaseItem item, ImageType type, int? imageIndex, string path)
  310. {
  311. item.SetImagePath(type, imageIndex ?? 0, _fileSystem.GetFileInfo(path));
  312. }
  313. /// <summary>
  314. /// Gets the save path.
  315. /// </summary>
  316. /// <param name="item">The item.</param>
  317. /// <param name="type">The type.</param>
  318. /// <param name="imageIndex">Index of the image.</param>
  319. /// <param name="mimeType">Type of the MIME.</param>
  320. /// <param name="saveLocally">if set to <c>true</c> [save locally].</param>
  321. /// <returns>System.String.</returns>
  322. /// <exception cref="ArgumentNullException">
  323. /// imageIndex
  324. /// or
  325. /// imageIndex.
  326. /// </exception>
  327. private string GetStandardSavePath(BaseItem item, ImageType type, int? imageIndex, string mimeType, bool saveLocally)
  328. {
  329. var season = item as Season;
  330. var extension = MimeTypes.ToExtension(mimeType);
  331. if (string.IsNullOrWhiteSpace(extension))
  332. {
  333. throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Unable to determine image file extension from mime type {0}", mimeType));
  334. }
  335. if (string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase))
  336. {
  337. extension = ".jpg";
  338. }
  339. extension = extension.ToLowerInvariant();
  340. if (type == ImageType.Primary && saveLocally)
  341. {
  342. if (season is not null && season.IndexNumber.HasValue)
  343. {
  344. var seriesFolder = season.SeriesPath;
  345. var seasonMarker = season.IndexNumber.Value == 0
  346. ? "-specials"
  347. : season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
  348. var imageFilename = "season" + seasonMarker + "-poster" + extension;
  349. return Path.Combine(seriesFolder, imageFilename);
  350. }
  351. }
  352. if (type == ImageType.Backdrop && saveLocally)
  353. {
  354. if (season is not null
  355. && season.IndexNumber.HasValue
  356. && (imageIndex is null || imageIndex == 0))
  357. {
  358. var seriesFolder = season.SeriesPath;
  359. var seasonMarker = season.IndexNumber.Value == 0
  360. ? "-specials"
  361. : season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
  362. var imageFilename = "season" + seasonMarker + "-fanart" + extension;
  363. return Path.Combine(seriesFolder, imageFilename);
  364. }
  365. }
  366. if (type == ImageType.Thumb && saveLocally)
  367. {
  368. if (season is not null && season.IndexNumber.HasValue)
  369. {
  370. var seriesFolder = season.SeriesPath;
  371. var seasonMarker = season.IndexNumber.Value == 0
  372. ? "-specials"
  373. : season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
  374. var imageFilename = "season" + seasonMarker + "-landscape" + extension;
  375. return Path.Combine(seriesFolder, imageFilename);
  376. }
  377. if (item.IsInMixedFolder)
  378. {
  379. return GetSavePathForItemInMixedFolder(item, type, "landscape", extension);
  380. }
  381. return Path.Combine(item.ContainingFolderPath, "landscape" + extension);
  382. }
  383. if (type == ImageType.Banner && saveLocally)
  384. {
  385. if (season is not null && season.IndexNumber.HasValue)
  386. {
  387. var seriesFolder = season.SeriesPath;
  388. var seasonMarker = season.IndexNumber.Value == 0
  389. ? "-specials"
  390. : season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
  391. var imageFilename = "season" + seasonMarker + "-banner" + extension;
  392. return Path.Combine(seriesFolder, imageFilename);
  393. }
  394. }
  395. string filename;
  396. var folderName = item is MusicAlbum ||
  397. item is MusicArtist ||
  398. item is PhotoAlbum ||
  399. item is Person ||
  400. (saveLocally && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Legacy) ?
  401. "folder" :
  402. "poster";
  403. switch (type)
  404. {
  405. case ImageType.Art:
  406. filename = "clearart";
  407. break;
  408. case ImageType.BoxRear:
  409. filename = "back";
  410. break;
  411. case ImageType.Thumb:
  412. filename = "landscape";
  413. break;
  414. case ImageType.Disc:
  415. filename = item is MusicAlbum ? "cdart" : "disc";
  416. break;
  417. case ImageType.Primary:
  418. filename = saveLocally && item is Episode ? Path.GetFileNameWithoutExtension(item.Path) : folderName;
  419. break;
  420. case ImageType.Backdrop:
  421. filename = GetBackdropSaveFilename(item.GetImages(type), "backdrop", "backdrop", imageIndex);
  422. break;
  423. default:
  424. filename = type.ToString().ToLowerInvariant();
  425. break;
  426. }
  427. string path = null;
  428. if (saveLocally)
  429. {
  430. if (type == ImageType.Primary && item is Episode)
  431. {
  432. path = Path.Combine(Path.GetDirectoryName(item.Path), filename + "-thumb" + extension);
  433. }
  434. else if (item.IsInMixedFolder)
  435. {
  436. path = GetSavePathForItemInMixedFolder(item, type, filename, extension);
  437. }
  438. if (string.IsNullOrEmpty(path))
  439. {
  440. path = Path.Combine(item.ContainingFolderPath, filename + extension);
  441. }
  442. }
  443. // None of the save local conditions passed, so store it in our internal folders
  444. if (string.IsNullOrEmpty(path))
  445. {
  446. if (string.IsNullOrEmpty(filename))
  447. {
  448. filename = folderName;
  449. }
  450. path = Path.Combine(item.GetInternalMetadataPath(), filename + extension);
  451. }
  452. return path;
  453. }
  454. private string GetBackdropSaveFilename(IEnumerable<ItemImageInfo> images, string zeroIndexFilename, string numberedIndexPrefix, int? index)
  455. {
  456. if (index.HasValue && index.Value == 0)
  457. {
  458. return zeroIndexFilename;
  459. }
  460. var filenames = images.Select(i => Path.GetFileNameWithoutExtension(i.Path)).ToList();
  461. var current = 1;
  462. while (filenames.Contains(numberedIndexPrefix + current.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase))
  463. {
  464. current++;
  465. }
  466. return numberedIndexPrefix + current.ToString(CultureInfo.InvariantCulture);
  467. }
  468. /// <summary>
  469. /// Gets the compatible save paths.
  470. /// </summary>
  471. /// <param name="item">The item.</param>
  472. /// <param name="type">The type.</param>
  473. /// <param name="imageIndex">Index of the image.</param>
  474. /// <param name="mimeType">Type of the MIME.</param>
  475. /// <returns>IEnumerable{System.String}.</returns>
  476. /// <exception cref="ArgumentNullException">imageIndex.</exception>
  477. private string[] GetCompatibleSavePaths(BaseItem item, ImageType type, int? imageIndex, string mimeType)
  478. {
  479. var season = item as Season;
  480. var extension = MimeTypes.ToExtension(mimeType);
  481. // Backdrop paths
  482. if (type == ImageType.Backdrop)
  483. {
  484. if (!imageIndex.HasValue)
  485. {
  486. throw new ArgumentNullException(nameof(imageIndex));
  487. }
  488. if (imageIndex.Value == 0)
  489. {
  490. if (item.IsInMixedFolder)
  491. {
  492. return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) };
  493. }
  494. if (season is not null && season.IndexNumber.HasValue)
  495. {
  496. var seriesFolder = season.SeriesPath;
  497. var seasonMarker = season.IndexNumber.Value == 0
  498. ? "-specials"
  499. : season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
  500. var imageFilename = "season" + seasonMarker + "-fanart" + extension;
  501. return new[] { Path.Combine(seriesFolder, imageFilename) };
  502. }
  503. return new[]
  504. {
  505. Path.Combine(item.ContainingFolderPath, "fanart" + extension)
  506. };
  507. }
  508. var outputIndex = imageIndex.Value;
  509. if (item.IsInMixedFolder)
  510. {
  511. return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + outputIndex.ToString(CultureInfo.InvariantCulture), extension) };
  512. }
  513. var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", outputIndex);
  514. var list = new List<string>
  515. {
  516. Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension)
  517. };
  518. if (EnableExtraThumbsDuplication)
  519. {
  520. list.Add(Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + outputIndex.ToString(CultureInfo.InvariantCulture) + extension));
  521. }
  522. return list.ToArray();
  523. }
  524. if (type == ImageType.Primary)
  525. {
  526. if (season is not null && season.IndexNumber.HasValue)
  527. {
  528. var seriesFolder = season.SeriesPath;
  529. var seasonMarker = season.IndexNumber.Value == 0
  530. ? "-specials"
  531. : season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);
  532. var imageFilename = "season" + seasonMarker + "-poster" + extension;
  533. return new[] { Path.Combine(seriesFolder, imageFilename) };
  534. }
  535. if (item is Episode)
  536. {
  537. var seasonFolder = Path.GetDirectoryName(item.Path);
  538. var imageFilename = Path.GetFileNameWithoutExtension(item.Path) + "-thumb" + extension;
  539. return new[] { Path.Combine(seasonFolder, imageFilename) };
  540. }
  541. if (item.IsInMixedFolder || item is MusicVideo)
  542. {
  543. return new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) };
  544. }
  545. if (item is MusicAlbum || item is MusicArtist)
  546. {
  547. return new[] { Path.Combine(item.ContainingFolderPath, "folder" + extension) };
  548. }
  549. return new[] { Path.Combine(item.ContainingFolderPath, "poster" + extension) };
  550. }
  551. // All other paths are the same
  552. return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, true) };
  553. }
  554. /// <summary>
  555. /// Gets the save path for item in mixed folder.
  556. /// </summary>
  557. /// <param name="item">The item.</param>
  558. /// <param name="type">The type.</param>
  559. /// <param name="imageFilename">The image filename.</param>
  560. /// <param name="extension">The extension.</param>
  561. /// <returns>System.String.</returns>
  562. private string GetSavePathForItemInMixedFolder(BaseItem item, ImageType type, string imageFilename, string extension)
  563. {
  564. if (type == ImageType.Primary)
  565. {
  566. imageFilename = "poster";
  567. }
  568. var folder = Path.GetDirectoryName(item.Path);
  569. return Path.Combine(folder, Path.GetFileNameWithoutExtension(item.Path) + "-" + imageFilename + extension);
  570. }
  571. }
  572. }