From 123016f62f4ac5a386c91d45619a133b14686671 Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Wed, 9 Oct 2024 05:46:50 +0200 Subject: [PATCH] fix: properly implement the respect preferred image _option_ - Hook up the code to actually use the option to respect the preferred image, instead of just always doing it. --- Shokofin/Providers/ImageProvider.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Shokofin/Providers/ImageProvider.cs b/Shokofin/Providers/ImageProvider.cs index 862ec2a8..f96cb954 100644 --- a/Shokofin/Providers/ImageProvider.cs +++ b/Shokofin/Providers/ImageProvider.cs @@ -46,6 +46,7 @@ public async Task> GetImages(BaseItem item, Cancell var list = new List(); var metadataLanguage = item.GetPreferredMetadataLanguage(); var baseKind = item.GetBaseItemKind(); + var sortPreferred = Plugin.Instance.Configuration.RespectPreferredImage; var trackerId = Plugin.Instance.Tracker.Add($"Providing images for {baseKind} \"{item.Name}\". (Path=\"{item.Path}\")"); try { switch (item) { @@ -53,14 +54,13 @@ public async Task> GetImages(BaseItem item, Cancell if (Lookup.TryGetEpisodeIdFor(episode, out var episodeId)) { var episodeImages = await ApiClient.GetEpisodeImages(episodeId); if (episodeImages is not null) - AddImagesForEpisode(ref list, episodeImages, metadataLanguage); + AddImagesForEpisode(ref list, episodeImages, metadataLanguage, sortPreferred); Logger.LogInformation("Getting {Count} images for episode {EpisodeName} (Episode={EpisodeId},Language={MetadataLanguage})", list.Count, episode.Name, episodeId, metadataLanguage); } break; } case Series series: { if (Lookup.TryGetSeriesIdFor(series, out var seriesId)) { var seriesImages = await ApiClient.GetSeriesImages(seriesId); - var sortPreferred = true; if (seriesImages is not null) { AddImagesForSeries(ref list, seriesImages, metadataLanguage, sortPreferred); sortPreferred = false; @@ -96,7 +96,6 @@ public async Task> GetImages(BaseItem item, Cancell if (Lookup.TryGetSeriesIdFor(season, out var seriesId)) { var seasonInfo = await ApiManager.GetSeasonInfoForSeries(seriesId); var seriesImages = await ApiClient.GetSeriesImages(seriesId); - var sortPreferred = true; if (seriesImages is not null) { AddImagesForSeries(ref list, seriesImages, metadataLanguage, sortPreferred); sortPreferred = false; @@ -121,7 +120,7 @@ public async Task> GetImages(BaseItem item, Cancell if (Lookup.TryGetEpisodeIdFor(movie, out var episodeId)) { var episodeImages = await ApiClient.GetEpisodeImages(episodeId); if (episodeImages is not null) - AddImagesForSeries(ref list, episodeImages, metadataLanguage); + AddImagesForSeries(ref list, episodeImages, metadataLanguage, sortPreferred); Logger.LogInformation("Getting {Count} images for movie {MovieName} (Episode={EpisodeId},Language={MetadataLanguage})", list.Count, movie.Name, episodeId, metadataLanguage); } break; @@ -134,7 +133,7 @@ public async Task> GetImages(BaseItem item, Cancell if (!string.IsNullOrEmpty(seriesId)) { var seriesImages = await ApiClient.GetSeriesImages(seriesId); if (seriesImages is not null) - AddImagesForSeries(ref list, seriesImages, metadataLanguage); + AddImagesForSeries(ref list, seriesImages, metadataLanguage, sortPreferred); Logger.LogInformation("Getting {Count} images for collection {CollectionName} (Group={GroupId},Series={SeriesId},Language={MetadataLanguage})", list.Count, collection.Name, groupId, groupId == null ? seriesId : null, metadataLanguage); } break; @@ -151,13 +150,16 @@ public async Task> GetImages(BaseItem item, Cancell } } - public static void AddImagesForEpisode(ref List list, API.Models.EpisodeImages images, string metadataLanguage) + public static void AddImagesForEpisode(ref List list, API.Models.EpisodeImages images, string metadataLanguage, bool sortList) { - foreach (var image in images.Thumbnails.OrderByDescending(image => image.IsPreferred)) + IEnumerable imagesList = sortList + ? images.Thumbnails.OrderByDescending(image => image.IsPreferred) + : images.Thumbnails; + foreach (var image in imagesList) AddImage(ref list, ImageType.Primary, image, metadataLanguage); } - private static void AddImagesForSeries(ref List list, API.Models.Images images, string metadataLanguage, bool sortList = true) + private static void AddImagesForSeries(ref List list, API.Models.Images images, string metadataLanguage, bool sortList) { IEnumerable imagesList = sortList ? images.Posters.OrderByDescending(image => image.IsPreferred)