From 1fe1908aeea9b1273c63edb19f187cef1f688d7a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 21 Jan 2016 21:59:07 -0500 Subject: [PATCH] sync image file names --- .../Images/LocalImageProvider.cs | 40 +++++--- MediaBrowser.Providers/Manager/ImageSaver.cs | 91 ++++++++++--------- 2 files changed, 73 insertions(+), 58 deletions(-) diff --git a/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs b/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs index afbc2640d..c6f81d874 100644 --- a/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs +++ b/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs @@ -122,6 +122,16 @@ namespace MediaBrowser.LocalMetadata.Images private void PopulateImages(IHasImages item, List images, List files, bool supportParentSeriesFiles, IDirectoryService directoryService) { + if (supportParentSeriesFiles) + { + var season = item as Season; + + if (season != null) + { + PopulateSeasonImagesFromSeriesFolder(season, images, directoryService); + } + } + var imagePrefix = item.FileNameWithoutExtension + "-"; var isInMixedFolder = item.IsInMixedFolder; @@ -151,33 +161,33 @@ namespace MediaBrowser.LocalMetadata.Images AddImage(files, images, "banner", imagePrefix, isInMixedFolder, ImageType.Banner); // Thumb - AddImage(files, images, "thumb", imagePrefix, isInMixedFolder, ImageType.Thumb); AddImage(files, images, "landscape", imagePrefix, isInMixedFolder, ImageType.Thumb); + AddImage(files, images, "thumb", imagePrefix, isInMixedFolder, ImageType.Thumb); PopulateBackdrops(item, images, files, imagePrefix, isInMixedFolder, directoryService); PopulateScreenshots(images, files, imagePrefix, isInMixedFolder); - - if (supportParentSeriesFiles) - { - var season = item as Season; - - if (season != null) - { - PopulateSeasonImagesFromSeriesFolder(season, images, directoryService); - } - } } private void PopulatePrimaryImages(IHasImages item, List images, List files, string imagePrefix, bool isInMixedFolder) { var names = new List { - "folder", - "poster", "cover", "default" }; + if (item is MusicAlbum || item is MusicArtist) + { + // these prefer folder + names.Insert(0, "poster"); + names.Insert(0, "folder"); + } + else + { + names.Insert(0, "folder"); + names.Insert(0, "poster"); + } + // Support plex/kodi convention if (item is Series) { @@ -212,8 +222,6 @@ namespace MediaBrowser.LocalMetadata.Images private void PopulateBackdrops(IHasImages item, List images, List files, string imagePrefix, bool isInMixedFolder, IDirectoryService directoryService) { - PopulateBackdrops(images, files, imagePrefix, "backdrop", "backdrop", isInMixedFolder, ImageType.Backdrop); - if (!string.IsNullOrEmpty(item.Path)) { var name = item.FileNameWithoutExtension; @@ -241,6 +249,8 @@ namespace MediaBrowser.LocalMetadata.Images { PopulateBackdropsFromExtraFanart(extraFanartFolder.FullName, images, directoryService); } + + PopulateBackdrops(images, files, imagePrefix, "backdrop", "backdrop", isInMixedFolder, ImageType.Backdrop); } private void PopulateBackdropsFromExtraFanart(string path, List images, IDirectoryService directoryService) diff --git a/MediaBrowser.Providers/Manager/ImageSaver.cs b/MediaBrowser.Providers/Manager/ImageSaver.cs index 4542c9c42..4bec352f6 100644 --- a/MediaBrowser.Providers/Manager/ImageSaver.cs +++ b/MediaBrowser.Providers/Manager/ImageSaver.cs @@ -332,7 +332,50 @@ namespace MediaBrowser.Providers.Manager /// 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) { @@ -342,11 +385,14 @@ namespace MediaBrowser.Providers.Manager 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) : "folder"; + filename = item is Episode ? _fileSystem.GetFileNameWithoutExtension(item.Path) : folderName; break; case ImageType.Backdrop: filename = GetBackdropSaveFilename(item.GetImages(type), "backdrop", "backdrop", imageIndex); @@ -359,8 +405,6 @@ namespace MediaBrowser.Providers.Manager break; } - var extension = mimeType.Split('/').Last(); - if (string.Equals(extension, "jpeg", StringComparison.OrdinalIgnoreCase)) { extension = "jpg"; @@ -393,7 +437,7 @@ namespace MediaBrowser.Providers.Manager { if (string.IsNullOrEmpty(filename)) { - filename = "folder"; + filename = folderName; } path = Path.Combine(item.GetInternalMetadataPath(), filename + extension); } @@ -526,45 +570,6 @@ namespace MediaBrowser.Providers.Manager 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) }; }