private async Task DownloadBackdrops(IHasImages item, ImageType imageType, int limit, IRemoteImageProvider provider, RefreshResult result, IEnumerable <RemoteImageInfo> images, int minWidth, CancellationToken cancellationToken) { foreach (var image in images.Where(i => i.Type == imageType)) { if (item.GetImages(imageType).Count() >= limit) { break; } if (image.Width.HasValue && image.Width.Value < minWidth) { continue; } var url = image.Url; if (EnableImageStub(item, imageType)) { SaveImageStub(item, imageType, url); result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate; return; } try { var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false); // If there's already an image of the same size, skip it if (response.ContentLength.HasValue) { try { if (item.GetImages(imageType).Any(i => new FileInfo(i.Path).Length == response.ContentLength.Value)) { response.Content.Dispose(); continue; } } catch (IOException ex) { _logger.ErrorException("Error examining images", ex); } } await _providerManager.SaveImage(item, response.Content, response.ContentType, imageType, null, cancellationToken).ConfigureAwait(false); result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate; } catch (HttpException ex) { // Sometimes providers send back bad url's. Just move onto the next image if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound) { continue; } break; } } }
private void ClearImages(IHasImages item, ImageType type) { var deleted = false; foreach (var image in item.GetImages(type).ToList()) { // Delete the source file var currentFile = new FileInfo(image.Path); // Deletion will fail if the file is hidden so remove the attribute first if (currentFile.Exists) { if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { currentFile.Attributes &= ~FileAttributes.Hidden; } currentFile.Delete(); deleted = true; } } if (deleted) { item.ValidateImages(new DirectoryService(_logger)); } }
private void ClearImages(IHasImages item, ImageType type) { var deleted = false; foreach (var image in item.GetImages(type).ToList()) { if (!image.IsLocalFile) { // TODO: Need to get this image removed continue; } // Delete the source file var currentFile = new FileInfo(image.Path); // Deletion will fail if the file is hidden so remove the attribute first if (currentFile.Exists) { if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { currentFile.Attributes &= ~FileAttributes.Hidden; } _fileSystem.DeleteFile(currentFile.FullName); deleted = true; } } if (deleted) { item.ValidateImages(new DirectoryService(_logger, _fileSystem)); } }
private void ClearImages(IHasImages item, ImageType type) { var deleted = false; var deletedImages = new List <ItemImageInfo>(); foreach (var image in item.GetImages(type).ToList()) { if (!image.IsLocalFile) { deletedImages.Add(image); continue; } try { _fileSystem.DeleteFile(image.Path); deleted = true; } catch (FileNotFoundException) { } } foreach (var image in deletedImages) { item.RemoveImage(image); } if (deleted) { item.ValidateImages(new DirectoryService(_logger, _fileSystem)); } }
/// <summary> /// Determines if an item already contains the given images /// </summary> /// <param name="item">The item.</param> /// <param name="images">The images.</param> /// <param name="savedOptions">The saved options.</param> /// <param name="backdropLimit">The backdrop limit.</param> /// <param name="screenshotLimit">The screenshot limit.</param> /// <returns><c>true</c> if the specified item contains images; otherwise, <c>false</c>.</returns> private bool ContainsImages(IHasImages item, List <ImageType> images, MetadataOptions savedOptions, int backdropLimit, int screenshotLimit) { if (_singularImages.Any(i => images.Contains(i) && !item.HasImage(i) && savedOptions.GetLimit(i) > 0)) { return(false); } if (images.Contains(ImageType.Backdrop) && item.GetImages(ImageType.Backdrop).Count() < backdropLimit) { return(false); } if (images.Contains(ImageType.Screenshot) && item.GetImages(ImageType.Screenshot).Count() < screenshotLimit) { return(false); } return(true); }
private void SaveImageStub(IHasImages item, ImageType imageType, string url) { var newIndex = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0; item.SetImage(new ItemImageInfo { Path = url, Type = imageType }, newIndex); }
private IEnumerable <string> GetStandardSavePaths(IHasImages item, ImageType type, int imageIndex, string extension) { string filename; switch (type) { case ImageType.Art: filename = "clearart"; break; case ImageType.BoxRear: filename = "back"; break; case ImageType.Disc: filename = item is MusicAlbum ? "cdart" : "disc"; break; case ImageType.Screenshot: filename = GetBackdropSaveFilename(item.GetImages(type), "screenshot", "screenshot", imageIndex); break; default: filename = type.ToString().ToLower(); break; } string path = null; if (item.IsInMixedFolder) { path = GetSavePathForItemInMixedFolder(item, type, filename, extension); } if (string.IsNullOrEmpty(path)) { path = Path.Combine(item.ContainingFolderPath, filename + extension); } if (string.IsNullOrEmpty(path)) { return(new string[] { }); } return(new[] { path }); }
private void ClearImages(IHasImages item, ImageType type) { var deleted = false; var deletedImages = new List <ItemImageInfo>(); foreach (var image in item.GetImages(type).ToList()) { if (!image.IsLocalFile) { deletedImages.Add(image); continue; } // Delete the source file var currentFile = _fileSystem.GetFileInfo(image.Path); // Deletion will fail if the file is hidden so remove the attribute first if (currentFile.Exists) { if (currentFile.IsHidden) { _fileSystem.SetHidden(currentFile.FullName, false); } _fileSystem.DeleteFile(currentFile.FullName); deleted = true; } } foreach (var image in deletedImages) { item.RemoveImage(image); } if (deleted) { item.ValidateImages(new DirectoryService(_logger, _fileSystem)); } }
/// <summary> /// Determines if an item already contains the given images /// </summary> /// <param name="item">The item.</param> /// <param name="images">The images.</param> /// <param name="savedOptions">The saved options.</param> /// <param name="backdropLimit">The backdrop limit.</param> /// <param name="screenshotLimit">The screenshot limit.</param> /// <returns><c>true</c> if the specified item contains images; otherwise, <c>false</c>.</returns> private bool ContainsImages(IHasImages item, List<ImageType> images, MetadataOptions savedOptions, int backdropLimit, int screenshotLimit) { if (_singularImages.Any(i => images.Contains(i) && !item.HasImage(i) && savedOptions.GetLimit(i) > 0)) { return false; } if (images.Contains(ImageType.Backdrop) && item.GetImages(ImageType.Backdrop).Count() < backdropLimit) { return false; } if (images.Contains(ImageType.Screenshot) && item.GetImages(ImageType.Screenshot).Count() < screenshotLimit) { return false; } return true; }
public async Task SaveImage(IHasImages item, Stream source, string mimeType, ImageType type, int?imageIndex, bool?saveLocallyWithMedia, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(mimeType)) { throw new ArgumentNullException("mimeType"); } var saveLocally = item.SupportsLocalMetadata && item.IsSaveLocalMetadataEnabled() && !item.IsOwnedItem && !(item is Audio); if (item is User) { saveLocally = true; } if (type != ImageType.Primary && item is Episode) { saveLocally = false; } var locationType = item.LocationType; if (locationType == LocationType.Remote || locationType == LocationType.Virtual) { saveLocally = false; var season = item as Season; // If season is virtual under a physical series, save locally if using compatible convention if (season != null && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Compatible) { var series = season.Series; if (series != null && series.SupportsLocalMetadata && series.IsSaveLocalMetadataEnabled()) { saveLocally = true; } } } if (saveLocallyWithMedia.HasValue && !saveLocallyWithMedia.Value) { saveLocally = saveLocallyWithMedia.Value; } if (!imageIndex.HasValue && item.AllowsMultipleImages(type)) { imageIndex = item.GetImages(type).Count(); } var index = imageIndex ?? 0; var paths = GetSavePaths(item, type, imageIndex, mimeType, saveLocally); var retryPaths = GetSavePaths(item, type, imageIndex, mimeType, false); // If there are more than one output paths, the stream will need to be seekable var memoryStream = _memoryStreamProvider.CreateNew(); using (source) { await source.CopyToAsync(memoryStream).ConfigureAwait(false); } source = memoryStream; var currentImage = GetCurrentImage(item, type, index); var currentImageIsLocalFile = currentImage != null && currentImage.IsLocalFile; var currentImagePath = currentImage == null ? null : currentImage.Path; var savedPaths = new List <string>(); using (source) { var currentPathIndex = 0; foreach (var path in paths) { source.Position = 0; string retryPath = null; if (paths.Length == retryPaths.Length) { retryPath = retryPaths[currentPathIndex]; } var savedPath = await SaveImageToLocation(source, path, retryPath, cancellationToken).ConfigureAwait(false); savedPaths.Add(savedPath); currentPathIndex++; } } // Set the path into the item SetImagePath(item, type, imageIndex, savedPaths[0]); // Delete the current path if (currentImageIsLocalFile && !savedPaths.Contains(currentImagePath, StringComparer.OrdinalIgnoreCase)) { var currentPath = currentImagePath; _logger.Debug("Deleting previous image {0}", currentPath); _libraryMonitor.ReportFileSystemChangeBeginning(currentPath); try { var currentFile = _fileSystem.GetFileInfo(currentPath); // This will fail if the file is hidden if (currentFile.Exists) { if (currentFile.IsHidden) { _fileSystem.SetHidden(currentFile.FullName, false); } _fileSystem.DeleteFile(currentFile.FullName); } } finally { _libraryMonitor.ReportFileSystemChangeComplete(currentPath, false); } } }
/// <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> /// <exception cref="System.ArgumentNullException">imageIndex</exception> private string[] GetCompatibleSavePaths(IHasImages item, ImageType type, int?imageIndex, string mimeType) { var season = item as Season; var extension = mimeType.Split('/').Last(); if (string.Equals(extension, "jpeg", StringComparison.OrdinalIgnoreCase)) { extension = "jpg"; } extension = "." + extension.ToLower(); // Backdrop paths if (type == ImageType.Backdrop) { if (!imageIndex.HasValue) { throw new ArgumentNullException("imageIndex"); } if (imageIndex.Value == 0) { if (item.IsInMixedFolder) { return(new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) }); } if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-fanart" + extension; return(new[] { Path.Combine(seriesFolder, imageFilename) }); } return(new[] { Path.Combine(item.ContainingFolderPath, "fanart" + extension) }); } var outputIndex = imageIndex.Value; if (item.IsInMixedFolder) { return(new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + outputIndex.ToString(UsCulture), extension) }); } var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", outputIndex); return(new[] { Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension), Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + outputIndex.ToString(UsCulture) + extension) }); } if (type == ImageType.Primary) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); 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) }); } if (item.IsInMixedFolder || item is MusicVideo) { return(new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) }); } if (item is MusicAlbum || item is MusicArtist) { return(new[] { Path.Combine(item.ContainingFolderPath, "folder" + extension) }); } return(new[] { Path.Combine(item.ContainingFolderPath, "poster" + extension) }); } if (type == ImageType.Banner) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-banner" + extension; return(new[] { Path.Combine(seriesFolder, imageFilename) }); } } if (type == ImageType.Thumb) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-landscape" + extension; return(new[] { Path.Combine(seriesFolder, imageFilename) }); } if (item.IsInMixedFolder) { return(new[] { GetSavePathForItemInMixedFolder(item, type, "landscape", extension) }); } return(new[] { Path.Combine(item.ContainingFolderPath, "landscape" + extension) }); } // All other paths are the same return(new[] { GetStandardSavePath(item, type, imageIndex, mimeType, true) }); }
public async Task SaveImage(IHasImages item, Stream source, string mimeType, ImageType type, int? imageIndex, string internalCacheKey, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(mimeType)) { throw new ArgumentNullException("mimeType"); } var saveLocally = item.SupportsLocalMetadata && item.IsSaveLocalMetadataEnabled() && !item.IsOwnedItem && !(item is Audio); if (item is User) { saveLocally = true; } if (type != ImageType.Primary && item is Episode) { saveLocally = false; } var locationType = item.LocationType; if (locationType == LocationType.Remote || locationType == LocationType.Virtual) { saveLocally = false; var season = item as Season; // If season is virtual under a physical series, save locally if using compatible convention if (season != null && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Compatible) { var series = season.Series; if (series != null && series.SupportsLocalMetadata && series.IsSaveLocalMetadataEnabled()) { saveLocally = true; } } } if (!string.IsNullOrEmpty(internalCacheKey)) { saveLocally = false; } if (!imageIndex.HasValue && item.AllowsMultipleImages(type)) { imageIndex = item.GetImages(type).Count(); } var index = imageIndex ?? 0; var paths = GetSavePaths(item, type, imageIndex, mimeType, saveLocally); var retryPaths = GetSavePaths(item, type, imageIndex, mimeType, false); // If there are more than one output paths, the stream will need to be seekable var memoryStream = new MemoryStream(); using (source) { await source.CopyToAsync(memoryStream).ConfigureAwait(false); } source = memoryStream; var currentImage = GetCurrentImage(item, type, index); var savedPaths = new List<string>(); using (source) { var currentPathIndex = 0; foreach (var path in paths) { source.Position = 0; string retryPath = null; if (paths.Length == retryPaths.Length) { retryPath = retryPaths[currentPathIndex]; } var savedPath = await SaveImageToLocation(source, path, retryPath, cancellationToken).ConfigureAwait(false); savedPaths.Add(savedPath); currentPathIndex++; } } // Set the path into the item SetImagePath(item, type, imageIndex, savedPaths[0]); // Delete the current path if (currentImage != null && currentImage.IsLocalFile && !savedPaths.Contains(currentImage.Path, StringComparer.OrdinalIgnoreCase)) { var currentPath = currentImage.Path; _libraryMonitor.ReportFileSystemChangeBeginning(currentPath); try { var currentFile = new FileInfo(currentPath); // This will fail if the file is hidden if (currentFile.Exists) { if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { currentFile.Attributes &= ~FileAttributes.Hidden; } _fileSystem.DeleteFile(currentFile.FullName); } } finally { _libraryMonitor.ReportFileSystemChangeComplete(currentPath, false); } } }
private void SaveImageStub(IHasImages item, ImageType imageType, string url) { var newIndex = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0; SaveImageStub(item, imageType, url, newIndex); }
private async Task DownloadBackdrops(IHasImages item, ImageType imageType, int limit, IRemoteImageProvider provider, RefreshResult result, IEnumerable<RemoteImageInfo> images, int minWidth, CancellationToken cancellationToken) { foreach (var image in images.Where(i => i.Type == imageType)) { if (item.GetImages(imageType).Count() >= limit) { break; } if (image.Width.HasValue && image.Width.Value < minWidth) { continue; } var url = image.Url; try { var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false); // If there's already an image of the same size, skip it if (response.ContentLength.HasValue) { try { if (item.GetImages(imageType).Any(i => new FileInfo(i.Path).Length == response.ContentLength.Value)) { response.Content.Dispose(); continue; } } catch (IOException ex) { _logger.ErrorException("Error examining images", ex); } } await _providerManager.SaveImage(item, response.Content, response.ContentType, imageType, null, cancellationToken).ConfigureAwait(false); result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate; } catch (HttpException ex) { // Sometimes providers send back bad url's. Just move onto the next image if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound) { continue; } break; } } }
private void SaveImageStub(IHasImages item, ImageType imageType, IEnumerable<string> urls) { var newIndex = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0; SaveImageStub(item, imageType, urls, newIndex); }
private void ClearImages(IHasImages item, ImageType type) { var deleted = false; var deletedImages = new List<ItemImageInfo>(); foreach (var image in item.GetImages(type).ToList()) { if (!image.IsLocalFile) { deletedImages.Add(image); continue; } // Delete the source file var currentFile = new FileInfo(image.Path); // Deletion will fail if the file is hidden so remove the attribute first if (currentFile.Exists) { if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { currentFile.Attributes &= ~FileAttributes.Hidden; } _fileSystem.DeleteFile(currentFile.FullName); deleted = true; } } foreach (var image in deletedImages) { item.RemoveImage(image); } if (deleted) { item.ValidateImages(new DirectoryService(_logger, _fileSystem)); } }
public IEnumerable <string> GetSavePaths(IHasImages item, ImageType type, ImageFormat format, int index) { var season = item as Season; if (!SupportsItem(item, type, season)) { return(new string[] { }); } var extension = "." + format.ToString().ToLower(); // Backdrop paths if (type == ImageType.Backdrop) { if (index == 0) { if (item.IsInMixedFolder) { return(new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) }); } if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", _usCulture); var imageFilename = "season" + seasonMarker + "-fanart" + extension; return(new[] { Path.Combine(seriesFolder, imageFilename) }); } return(new[] { Path.Combine(item.ContainingFolderPath, "fanart" + extension) }); } if (item.IsInMixedFolder) { return(new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + index.ToString(_usCulture), extension) }); } var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", index); return(new[] { Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension), Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + index.ToString(_usCulture) + extension) }); } if (type == ImageType.Primary) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", _usCulture); 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) }); } if (item.IsInMixedFolder || item is MusicVideo) { return(new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) }); } if (item is MusicAlbum || item is MusicArtist) { return(new[] { Path.Combine(item.ContainingFolderPath, "folder" + extension) }); } return(new[] { Path.Combine(item.ContainingFolderPath, "poster" + extension) }); } if (type == ImageType.Banner) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", _usCulture); var imageFilename = "season" + seasonMarker + "-banner" + extension; return(new[] { Path.Combine(seriesFolder, imageFilename) }); } } if (type == ImageType.Thumb) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", _usCulture); var imageFilename = "season" + seasonMarker + "-landscape" + extension; return(new[] { Path.Combine(seriesFolder, imageFilename) }); } if (item.IsInMixedFolder) { return(new[] { GetSavePathForItemInMixedFolder(item, type, "landscape", extension) }); } return(new[] { Path.Combine(item.ContainingFolderPath, "landscape" + extension) }); } return(GetStandardSavePaths(item, type, index, extension)); }
/// <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> /// <exception cref="System.ArgumentNullException"> /// imageIndex /// or /// imageIndex /// </exception> private string GetStandardSavePath(IHasImages item, ImageType type, int? imageIndex, string mimeType, bool saveLocally) { string filename; switch (type) { case ImageType.Art: filename = "clearart"; break; case ImageType.BoxRear: filename = "back"; break; case ImageType.Disc: filename = item is MusicAlbum ? "cdart" : "disc"; break; case ImageType.Primary: filename = item is Episode ? _fileSystem.GetFileNameWithoutExtension(item.Path) : "folder"; break; case ImageType.Backdrop: filename = GetBackdropSaveFilename(item.GetImages(type), "backdrop", "backdrop", imageIndex); break; case ImageType.Screenshot: filename = GetBackdropSaveFilename(item.GetImages(type), "screenshot", "screenshot", imageIndex); break; default: filename = type.ToString().ToLower(); break; } var extension = mimeType.Split('/').Last(); if (string.Equals(extension, "jpeg", StringComparison.OrdinalIgnoreCase)) { extension = "jpg"; } extension = "." + extension.ToLower(); string path = null; if (saveLocally) { if (item is Episode) { path = Path.Combine(Path.GetDirectoryName(item.Path), "metadata", filename + extension); } else if (item.IsInMixedFolder) { path = GetSavePathForItemInMixedFolder(item, type, filename, extension); } 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)) { if (string.IsNullOrEmpty(filename)) { filename = "folder"; } path = Path.Combine(item.GetInternalMetadataPath(), filename + extension); } return 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> /// <exception cref="System.ArgumentNullException"> /// imageIndex /// or /// imageIndex /// </exception> private string GetStandardSavePath(IHasImages item, ImageType type, int? imageIndex, string mimeType, bool saveLocally) { var season = item as Season; var extension = MimeTypes.ToExtension(mimeType); if (type == ImageType.Thumb && saveLocally) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-landscape" + extension; return Path.Combine(seriesFolder, imageFilename); } if (item.IsInMixedFolder) { return GetSavePathForItemInMixedFolder(item, type, "landscape", extension); } return Path.Combine(item.ContainingFolderPath, "landscape" + extension); } if (type == ImageType.Banner && saveLocally) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-banner" + extension; return Path.Combine(seriesFolder, imageFilename); } } string filename; var folderName = item is MusicAlbum || item is MusicArtist ? "folder" : "poster"; switch (type) { case ImageType.Art: filename = "clearart"; break; case ImageType.BoxRear: filename = "back"; break; case ImageType.Thumb: filename = "landscape"; break; case ImageType.Disc: filename = item is MusicAlbum ? "cdart" : "disc"; break; case ImageType.Primary: filename = item is Episode ? _fileSystem.GetFileNameWithoutExtension(item.Path) : folderName; break; case ImageType.Backdrop: filename = GetBackdropSaveFilename(item.GetImages(type), "backdrop", "backdrop", imageIndex); break; case ImageType.Screenshot: filename = GetBackdropSaveFilename(item.GetImages(type), "screenshot", "screenshot", imageIndex); break; default: filename = type.ToString().ToLower(); break; } if (string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase)) { extension = ".jpg"; } extension = extension.ToLower(); string path = null; if (saveLocally) { if (item is Episode) { path = Path.Combine(Path.GetDirectoryName(item.Path), "metadata", filename + extension); } else if (item.IsInMixedFolder) { path = GetSavePathForItemInMixedFolder(item, type, filename, extension); } 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)) { if (string.IsNullOrEmpty(filename)) { filename = folderName; } path = Path.Combine(item.GetInternalMetadataPath(), filename + extension); } return path; }
private void SaveImageStub(IHasImages item, ImageType imageType, IEnumerable <string> urls) { var newIndex = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0; SaveImageStub(item, imageType, urls, newIndex); }
private IEnumerable<string> GetStandardSavePaths(IHasImages item, ImageType type, int imageIndex, string extension) { string filename; switch (type) { case ImageType.Art: filename = "clearart"; break; case ImageType.BoxRear: filename = "back"; break; case ImageType.Disc: filename = item is MusicAlbum ? "cdart" : "disc"; break; case ImageType.Screenshot: filename = GetBackdropSaveFilename(item.GetImages(type), "screenshot", "screenshot", imageIndex); break; default: filename = type.ToString().ToLower(); break; } string path = null; if (item.IsInMixedFolder) { path = GetSavePathForItemInMixedFolder(item, type, filename, extension); } if (string.IsNullOrEmpty(path)) { path = Path.Combine(item.ContainingFolderPath, filename + extension); } if (string.IsNullOrEmpty(path)) { return new string[] { }; } return new[] { path }; }
public IEnumerable<string> GetSavePaths(IHasImages item, ImageType type, ImageFormat format, int index) { var season = item as Season; if (!SupportsItem(item, type, season)) { return new string[] { }; } var extension = "." + format.ToString().ToLower(); // Backdrop paths if (type == ImageType.Backdrop) { if (index == 0) { if (item.IsInMixedFolder) { return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) }; } if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", _usCulture); var imageFilename = "season" + seasonMarker + "-fanart" + extension; return new[] { Path.Combine(seriesFolder, imageFilename) }; } return new[] { Path.Combine(item.ContainingFolderPath, "fanart" + extension) }; } if (item.IsInMixedFolder) { return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + index.ToString(_usCulture), extension) }; } var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", index); return new[] { Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension), Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + index.ToString(_usCulture) + extension) }; } if (type == ImageType.Primary) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", _usCulture); 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) }; } if (item.IsInMixedFolder || item is MusicVideo) { return new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) }; } if (item is MusicAlbum || item is MusicArtist) { return new[] { Path.Combine(item.ContainingFolderPath, "folder" + extension) }; } return new[] { Path.Combine(item.ContainingFolderPath, "poster" + extension) }; } if (type == ImageType.Banner) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", _usCulture); var imageFilename = "season" + seasonMarker + "-banner" + extension; return new[] { Path.Combine(seriesFolder, imageFilename) }; } } if (type == ImageType.Thumb) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", _usCulture); var imageFilename = "season" + seasonMarker + "-landscape" + extension; return new[] { Path.Combine(seriesFolder, imageFilename) }; } if (item.IsInMixedFolder) { return new[] { GetSavePathForItemInMixedFolder(item, type, "landscape", extension) }; } return new[] { Path.Combine(item.ContainingFolderPath, "landscape" + extension) }; } return GetStandardSavePaths(item, type, index, extension); }
/// <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> /// <exception cref="System.ArgumentNullException">imageIndex</exception> private string[] GetCompatibleSavePaths(IHasImages item, ImageType type, int? imageIndex, string mimeType) { var season = item as Season; var extension = MimeTypes.ToExtension(mimeType); // Backdrop paths if (type == ImageType.Backdrop) { if (!imageIndex.HasValue) { throw new ArgumentNullException("imageIndex"); } if (imageIndex.Value == 0) { if (item.IsInMixedFolder) { return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) }; } if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-fanart" + extension; return new[] { Path.Combine(seriesFolder, imageFilename) }; } return new[] { Path.Combine(item.ContainingFolderPath, "fanart" + extension) }; } var outputIndex = imageIndex.Value; if (item.IsInMixedFolder) { return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + outputIndex.ToString(UsCulture), extension) }; } var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", outputIndex); var list = new List<string> { Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension) }; if (EnableExtraThumbsDuplication) { list.Add(Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + outputIndex.ToString(UsCulture) + extension)); } return list.ToArray(); } if (type == ImageType.Primary) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-poster" + extension; return new[] { Path.Combine(seriesFolder, imageFilename) }; } if (item is Episode) { var seasonFolder = Path.GetDirectoryName(item.Path); var imageFilename = _fileSystem.GetFileNameWithoutExtension(item.Path) + "-thumb" + extension; return new[] { Path.Combine(seasonFolder, imageFilename) }; } if (item.IsInMixedFolder || item is MusicVideo) { return new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) }; } 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 return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, true) }; }
/// <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> /// <exception cref="System.ArgumentNullException"> /// imageIndex /// or /// imageIndex /// </exception> private string GetStandardSavePath(IHasImages item, ImageType type, int?imageIndex, string mimeType, bool saveLocally) { var season = item as Season; var extension = MimeTypes.ToExtension(mimeType); if (string.IsNullOrWhiteSpace(extension)) { throw new ArgumentException(string.Format("Unable to determine image file extension from mime type {0}", mimeType)); } if (type == ImageType.Thumb && saveLocally) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-landscape" + extension; return(Path.Combine(seriesFolder, imageFilename)); } if (item.DetectIsInMixedFolder()) { return(GetSavePathForItemInMixedFolder(item, type, "landscape", extension)); } return(Path.Combine(item.ContainingFolderPath, "landscape" + extension)); } if (type == ImageType.Banner && saveLocally) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-banner" + extension; return(Path.Combine(seriesFolder, imageFilename)); } } string filename; var folderName = item is MusicAlbum || item is MusicArtist || item is PhotoAlbum || (saveLocally && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Legacy) ? "folder" : "poster"; switch (type) { case ImageType.Art: filename = "clearart"; break; case ImageType.BoxRear: filename = "back"; break; case ImageType.Thumb: filename = "landscape"; break; case ImageType.Disc: filename = item is MusicAlbum ? "cdart" : "disc"; break; case ImageType.Primary: filename = item is Episode?_fileSystem.GetFileNameWithoutExtension(item.Path) : folderName; break; case ImageType.Backdrop: filename = GetBackdropSaveFilename(item.GetImages(type), "backdrop", "backdrop", imageIndex); break; case ImageType.Screenshot: filename = GetBackdropSaveFilename(item.GetImages(type), "screenshot", "screenshot", imageIndex); break; default: filename = type.ToString().ToLower(); break; } if (string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase)) { extension = ".jpg"; } extension = extension.ToLower(); string path = null; if (saveLocally) { if (type == ImageType.Primary && item is Episode) { path = Path.Combine(Path.GetDirectoryName(item.Path), "metadata", filename + extension); } else if (item.DetectIsInMixedFolder()) { path = GetSavePathForItemInMixedFolder(item, type, filename, extension); } 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)) { if (string.IsNullOrEmpty(filename)) { filename = folderName; } path = Path.Combine(item.GetInternalMetadataPath(), filename + extension); } return(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> /// <exception cref="System.ArgumentNullException"> /// imageIndex /// or /// imageIndex /// </exception> private string GetStandardSavePath(IHasImages item, ImageType type, int?imageIndex, string mimeType, bool saveLocally) { string filename; switch (type) { case ImageType.Art: filename = "clearart"; break; case ImageType.BoxRear: filename = "back"; break; case ImageType.Disc: filename = item is MusicAlbum ? "cdart" : "disc"; break; case ImageType.Primary: filename = item is Episode?Path.GetFileNameWithoutExtension(item.Path) : "folder"; break; case ImageType.Backdrop: filename = GetBackdropSaveFilename(item.GetImages(type), "backdrop", "backdrop", imageIndex); break; case ImageType.Screenshot: filename = GetBackdropSaveFilename(item.GetImages(type), "screenshot", "screenshot", imageIndex); break; default: filename = type.ToString().ToLower(); break; } var extension = mimeType.Split('/').Last(); if (string.Equals(extension, "jpeg", StringComparison.OrdinalIgnoreCase)) { extension = "jpg"; } extension = "." + extension.ToLower(); string path = null; if (saveLocally) { if (item is Episode) { path = Path.Combine(Path.GetDirectoryName(item.Path), "metadata", filename + extension); } else if (item.IsInMixedFolder) { path = GetSavePathForItemInMixedFolder(item, type, filename, extension); } 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)) { if (string.IsNullOrEmpty(filename)) { filename = "folder"; } path = Path.Combine(_config.ApplicationPaths.GetInternalMetadataPath(item.Id), filename + extension); } return(path); }
/// <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> /// <exception cref="System.ArgumentNullException">imageIndex</exception> private string[] GetCompatibleSavePaths(IHasImages item, ImageType type, int?imageIndex, string mimeType) { var season = item as Season; var extension = MimeTypes.ToExtension(mimeType); // Backdrop paths if (type == ImageType.Backdrop) { if (!imageIndex.HasValue) { throw new ArgumentNullException("imageIndex"); } if (imageIndex.Value == 0) { if (item.DetectIsInMixedFolder()) { return(new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) }); } if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-fanart" + extension; return(new[] { Path.Combine(seriesFolder, imageFilename) }); } return(new[] { Path.Combine(item.ContainingFolderPath, "fanart" + extension) }); } var outputIndex = imageIndex.Value; if (item.DetectIsInMixedFolder()) { return(new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + outputIndex.ToString(UsCulture), extension) }); } var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", outputIndex); var list = new List <string> { Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension) }; if (EnableExtraThumbsDuplication) { list.Add(Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + outputIndex.ToString(UsCulture) + extension)); } return(list.ToArray()); } if (type == ImageType.Primary) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-poster" + extension; return(new[] { Path.Combine(seriesFolder, imageFilename) }); } if (item is Episode) { var seasonFolder = Path.GetDirectoryName(item.Path); var imageFilename = _fileSystem.GetFileNameWithoutExtension(item.Path) + "-thumb" + extension; return(new[] { Path.Combine(seasonFolder, imageFilename) }); } if (item.DetectIsInMixedFolder() || item is MusicVideo) { return(new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) }); } 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 return(new[] { GetStandardSavePath(item, type, imageIndex, mimeType, true) }); }
/// <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> /// <exception cref="System.ArgumentNullException">mimeType</exception> public async Task SaveImage(IHasImages item, Stream source, string mimeType, ImageType type, int?imageIndex, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(mimeType)) { throw new ArgumentNullException("mimeType"); } var saveLocally = item.SupportsLocalMetadata && item.IsSaveLocalMetadataEnabled() && !item.IsOwnedItem && !(item is Audio); if (item is IItemByName || item is User) { saveLocally = true; } if (type != ImageType.Primary && item is Episode) { saveLocally = false; } var locationType = item.LocationType; if (locationType == LocationType.Remote || locationType == LocationType.Virtual) { saveLocally = false; var season = item as Season; // If season is virtual under a physical series, save locally if using compatible convention if (season != null && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Compatible) { var series = season.Series; if (series != null && series.SupportsLocalMetadata && series.IsSaveLocalMetadataEnabled()) { saveLocally = true; } } } if (!imageIndex.HasValue && item.AllowsMultipleImages(type)) { imageIndex = item.GetImages(type).Count(); } var index = imageIndex ?? 0; var paths = GetSavePaths(item, type, imageIndex, mimeType, saveLocally); // If there are more than one output paths, the stream will need to be seekable if (paths.Length > 1 && !source.CanSeek) { var memoryStream = new MemoryStream(); using (source) { await source.CopyToAsync(memoryStream).ConfigureAwait(false); } memoryStream.Position = 0; source = memoryStream; } var currentPath = GetCurrentImagePath(item, type, index); using (source) { var isFirst = true; foreach (var path in paths) { // Seek back to the beginning if (!isFirst) { source.Position = 0; } await SaveImageToLocation(source, path, cancellationToken).ConfigureAwait(false); isFirst = false; } } // Set the path into the item SetImagePath(item, type, imageIndex, paths[0]); // Delete the current path if (!string.IsNullOrEmpty(currentPath) && !paths.Contains(currentPath, StringComparer.OrdinalIgnoreCase)) { _libraryMonitor.ReportFileSystemChangeBeginning(currentPath); try { var currentFile = new FileInfo(currentPath); // This will fail if the file is hidden if (currentFile.Exists) { if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { currentFile.Attributes &= ~FileAttributes.Hidden; } currentFile.Delete(); } } finally { _libraryMonitor.ReportFileSystemChangeComplete(currentPath, false); } } }
/// <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> /// <exception cref="System.ArgumentNullException">imageIndex</exception> private string[] GetCompatibleSavePaths(IHasImages item, ImageType type, int? imageIndex, string mimeType) { var season = item as Season; var extension = mimeType.Split('/').Last(); if (string.Equals(extension, "jpeg", StringComparison.OrdinalIgnoreCase)) { extension = "jpg"; } extension = "." + extension.ToLower(); // Backdrop paths if (type == ImageType.Backdrop) { if (!imageIndex.HasValue) { throw new ArgumentNullException("imageIndex"); } if (imageIndex.Value == 0) { if (item.IsInMixedFolder) { return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) }; } if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-fanart" + extension; return new[] { Path.Combine(seriesFolder, imageFilename) }; } return new[] { Path.Combine(item.ContainingFolderPath, "fanart" + extension) }; } var outputIndex = imageIndex.Value; if (item.IsInMixedFolder) { return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + outputIndex.ToString(UsCulture), extension) }; } var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", outputIndex); return new[] { Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension), Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + outputIndex.ToString(UsCulture) + extension) }; } if (type == ImageType.Primary) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); 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) }; } if (item.IsInMixedFolder || item is MusicVideo) { return new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) }; } if (item is MusicAlbum || item is MusicArtist) { return new[] { Path.Combine(item.ContainingFolderPath, "folder" + extension) }; } return new[] { Path.Combine(item.ContainingFolderPath, "poster" + extension) }; } if (type == ImageType.Banner) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-banner" + extension; return new[] { Path.Combine(seriesFolder, imageFilename) }; } } if (type == ImageType.Thumb) { if (season != null && season.IndexNumber.HasValue) { var seriesFolder = season.SeriesPath; var seasonMarker = season.IndexNumber.Value == 0 ? "-specials" : season.IndexNumber.Value.ToString("00", UsCulture); var imageFilename = "season" + seasonMarker + "-landscape" + extension; return new[] { Path.Combine(seriesFolder, imageFilename) }; } if (item.IsInMixedFolder) { return new[] { GetSavePathForItemInMixedFolder(item, type, "landscape", extension) }; } return new[] { Path.Combine(item.ContainingFolderPath, "landscape" + extension) }; } // All other paths are the same return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, true) }; }