ImageSaver.cs 25 KB

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