From b0cd1f5e39a74c99e2c8ce015cc5d52b65dd4161 Mon Sep 17 00:00:00 2001 From: Chris Tam Date: Wed, 8 Sep 2021 17:20:11 -0400 Subject: [PATCH] Fix images "not loading" after manual identification --- .../Extensions/EnumerableExtensions.cs | 18 ++++++++---- .../Manager/ItemImageProvider.cs | 4 +-- .../Manager/ProviderManager.cs | 29 ++++++++++--------- .../Tmdb/BoxSets/TmdbBoxSetImageProvider.cs | 2 +- .../Tmdb/Movies/TmdbMovieImageProvider.cs | 3 +- .../Tmdb/People/TmdbPersonImageProvider.cs | 3 +- .../Tmdb/TV/TmdbEpisodeImageProvider.cs | 3 +- .../Tmdb/TV/TmdbSeasonImageProvider.cs | 2 +- .../Tmdb/TV/TmdbSeriesImageProvider.cs | 3 +- 9 files changed, 36 insertions(+), 31 deletions(-) diff --git a/MediaBrowser.Model/Extensions/EnumerableExtensions.cs b/MediaBrowser.Model/Extensions/EnumerableExtensions.cs index 712fa381e..a5a6b18aa 100644 --- a/MediaBrowser.Model/Extensions/EnumerableExtensions.cs +++ b/MediaBrowser.Model/Extensions/EnumerableExtensions.cs @@ -18,6 +18,12 @@ namespace MediaBrowser.Model.Extensions /// The ordered remote image infos. public static IEnumerable OrderByLanguageDescending(this IEnumerable remoteImageInfos, string requestedLanguage) { + if (string.IsNullOrWhiteSpace(requestedLanguage)) + { + // Default to English if no requested language is specified. + requestedLanguage = "en"; + } + var isRequestedLanguageEn = string.Equals(requestedLanguage, "en", StringComparison.OrdinalIgnoreCase); return remoteImageInfos.OrderByDescending(i => @@ -27,16 +33,18 @@ namespace MediaBrowser.Model.Extensions return 3; } - if (!isRequestedLanguageEn && string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase)) - { - return 2; - } - if (string.IsNullOrEmpty(i.Language)) { + // Assume empty image language is likely to be English. return isRequestedLanguageEn ? 3 : 2; } + if (!isRequestedLanguageEn && string.Equals(i.Language, "en", StringComparison.OrdinalIgnoreCase)) + { + // Prioritize English over non-requested languages. + return 2; + } + return 0; }) .ThenByDescending(i => i.CommunityRating ?? 0) diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs index 4b325f2cf..7fdef6b44 100644 --- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs +++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs @@ -275,7 +275,7 @@ namespace MediaBrowser.Providers.Manager item, new RemoteImageQuery(provider.Name) { - IncludeAllLanguages = false, + IncludeAllLanguages = true, IncludeDisabledProviders = false, }, cancellationToken).ConfigureAwait(false); @@ -469,7 +469,7 @@ namespace MediaBrowser.Providers.Manager CancellationToken cancellationToken) { var eligibleImages = images - .Where(i => i.Type == type && !(i.Width.HasValue && i.Width.Value < minWidth)) + .Where(i => i.Type == type && i.Width >= minWidth) .ToList(); if (EnableImageStub(item) && eligibleImages.Count > 0) diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index 812f5cf06..b51a25417 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -24,6 +24,7 @@ using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Subtitles; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Extensions; using MediaBrowser.Model.IO; using MediaBrowser.Model.Providers; using Microsoft.Extensions.Logging; @@ -235,14 +236,7 @@ namespace MediaBrowser.Providers.Manager var preferredLanguage = item.GetPreferredMetadataLanguage(); - var languages = new List(); - if (!query.IncludeAllLanguages && !string.IsNullOrWhiteSpace(preferredLanguage)) - { - languages.Add(preferredLanguage); - } - - // TODO include [query.IncludeAllLanguages] as an argument to the providers - var tasks = providers.Select(i => GetImages(item, i, languages, cancellationToken, query.ImageType)); + var tasks = providers.Select(i => GetImages(item, i, preferredLanguage, query.IncludeAllLanguages, cancellationToken, query.ImageType)); var results = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -254,17 +248,21 @@ namespace MediaBrowser.Providers.Manager /// /// The item. /// The provider. - /// The preferred languages. + /// The preferred language. + /// Whether to include all languages in results. /// The cancellation token. /// The type. /// Task{IEnumerable{RemoteImageInfo}}. private async Task> GetImages( BaseItem item, IRemoteImageProvider provider, - IReadOnlyCollection preferredLanguages, + string preferredLanguage, + bool includeAllLanguages, CancellationToken cancellationToken, ImageType? type = null) { + bool hasPreferredLanguage = !string.IsNullOrWhiteSpace(preferredLanguage); + try { var result = await provider.GetImages(item, cancellationToken).ConfigureAwait(false); @@ -274,14 +272,17 @@ namespace MediaBrowser.Providers.Manager result = result.Where(i => i.Type == type.Value); } - if (preferredLanguages.Count > 0) + if (!includeAllLanguages && hasPreferredLanguage) { - result = result.Where(i => string.IsNullOrEmpty(i.Language) || - preferredLanguages.Contains(i.Language, StringComparer.OrdinalIgnoreCase) || + // Filter out languages that do not match the preferred languages. + // + // TODO: should exception case of "en" (English) eventually be removed? + result = result.Where(i => string.IsNullOrWhiteSpace(i.Language) || + string.Equals(preferredLanguage, i.Language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Language, "en", StringComparison.OrdinalIgnoreCase)); } - return result; + return result.OrderByLanguageDescending(preferredLanguage); } catch (OperationCanceledException) { diff --git a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs index 5ad61c567..a5287e749 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs @@ -101,7 +101,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets }); } - return remoteImages.OrderByLanguageDescending(language); + return remoteImages; } public Task GetImageResponse(string url, CancellationToken cancellationToken) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs index f34d689c1..d3cef49d8 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieImageProvider.cs @@ -13,7 +13,6 @@ using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Providers; using TMDbLib.Objects.Find; @@ -118,7 +117,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies }); } - return remoteImages.OrderByLanguageDescending(language); + return remoteImages; } public Task GetImageResponse(string url, CancellationToken cancellationToken) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs index e4c908a62..1fc5ccba5 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonImageProvider.cs @@ -10,7 +10,6 @@ using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Providers; namespace MediaBrowser.Providers.Plugins.Tmdb.People @@ -77,7 +76,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People }; } - return remoteImages.OrderByLanguageDescending(language); + return remoteImages; } public Task GetImageResponse(string url, CancellationToken cancellationToken) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs index ba18c542f..45e18c0ac 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs @@ -12,7 +12,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Providers; namespace MediaBrowser.Providers.Plugins.Tmdb.TV @@ -92,7 +91,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV }; } - return remoteImages.OrderByLanguageDescending(language); + return remoteImages; } public Task GetImageResponse(string url, CancellationToken cancellationToken) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs index 0d23c7872..1bda1a09b 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs @@ -81,7 +81,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV }; } - return remoteImages.OrderByLanguageDescending(language); + return remoteImages; } public IEnumerable GetSupportedImages(BaseItem item) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs index 326c116b3..f3f340378 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs @@ -13,7 +13,6 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Providers; namespace MediaBrowser.Providers.Plugins.Tmdb.TV @@ -107,7 +106,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV }; } - return remoteImages.OrderByLanguageDescending(language); + return remoteImages; } public Task GetImageResponse(string url, CancellationToken cancellationToken)