Merge pull request #6531 from GodTamIt/img-lang

Fix images "not loading" after manual identification
pull/6551/head
Bond-009 3 years ago committed by GitHub
commit d7109d4d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,6 +18,12 @@ namespace MediaBrowser.Model.Extensions
/// <returns>The ordered remote image infos.</returns> /// <returns>The ordered remote image infos.</returns>
public static IEnumerable<RemoteImageInfo> OrderByLanguageDescending(this IEnumerable<RemoteImageInfo> remoteImageInfos, string requestedLanguage) public static IEnumerable<RemoteImageInfo> OrderByLanguageDescending(this IEnumerable<RemoteImageInfo> 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); var isRequestedLanguageEn = string.Equals(requestedLanguage, "en", StringComparison.OrdinalIgnoreCase);
return remoteImageInfos.OrderByDescending(i => return remoteImageInfos.OrderByDescending(i =>
@ -27,14 +33,16 @@ namespace MediaBrowser.Model.Extensions
return 3; return 3;
} }
if (!isRequestedLanguageEn && string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase)) if (string.IsNullOrEmpty(i.Language))
{ {
return 2; // Assume empty image language is likely to be English.
return isRequestedLanguageEn ? 3 : 2;
} }
if (string.IsNullOrEmpty(i.Language)) if (!isRequestedLanguageEn && string.Equals(i.Language, "en", StringComparison.OrdinalIgnoreCase))
{ {
return isRequestedLanguageEn ? 3 : 2; // Prioritize English over non-requested languages.
return 2;
} }
return 0; return 0;

@ -275,7 +275,7 @@ namespace MediaBrowser.Providers.Manager
item, item,
new RemoteImageQuery(provider.Name) new RemoteImageQuery(provider.Name)
{ {
IncludeAllLanguages = false, IncludeAllLanguages = true,
IncludeDisabledProviders = false, IncludeDisabledProviders = false,
}, },
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
@ -469,7 +469,7 @@ namespace MediaBrowser.Providers.Manager
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var eligibleImages = images var eligibleImages = images
.Where(i => i.Type == type && !(i.Width.HasValue && i.Width.Value < minWidth)) .Where(i => i.Type == type && i.Width >= minWidth)
.ToList(); .ToList();
if (EnableImageStub(item) && eligibleImages.Count > 0) if (EnableImageStub(item) && eligibleImages.Count > 0)

@ -24,6 +24,7 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Subtitles; using MediaBrowser.Controller.Subtitles;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers; using MediaBrowser.Model.Providers;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -235,14 +236,7 @@ namespace MediaBrowser.Providers.Manager
var preferredLanguage = item.GetPreferredMetadataLanguage(); var preferredLanguage = item.GetPreferredMetadataLanguage();
var languages = new List<string>(); var tasks = providers.Select(i => GetImages(item, i, preferredLanguage, query.IncludeAllLanguages, cancellationToken, query.ImageType));
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 results = await Task.WhenAll(tasks).ConfigureAwait(false); var results = await Task.WhenAll(tasks).ConfigureAwait(false);
@ -254,17 +248,21 @@ namespace MediaBrowser.Providers.Manager
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="provider">The provider.</param> /// <param name="provider">The provider.</param>
/// <param name="preferredLanguages">The preferred languages.</param> /// <param name="preferredLanguage">The preferred language.</param>
/// <param name="includeAllLanguages">Whether to include all languages in results.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <param name="type">The type.</param> /// <param name="type">The type.</param>
/// <returns>Task{IEnumerable{RemoteImageInfo}}.</returns> /// <returns>Task{IEnumerable{RemoteImageInfo}}.</returns>
private async Task<IEnumerable<RemoteImageInfo>> GetImages( private async Task<IEnumerable<RemoteImageInfo>> GetImages(
BaseItem item, BaseItem item,
IRemoteImageProvider provider, IRemoteImageProvider provider,
IReadOnlyCollection<string> preferredLanguages, string preferredLanguage,
bool includeAllLanguages,
CancellationToken cancellationToken, CancellationToken cancellationToken,
ImageType? type = null) ImageType? type = null)
{ {
bool hasPreferredLanguage = !string.IsNullOrWhiteSpace(preferredLanguage);
try try
{ {
var result = await provider.GetImages(item, cancellationToken).ConfigureAwait(false); 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); result = result.Where(i => i.Type == type.Value);
} }
if (preferredLanguages.Count > 0) if (!includeAllLanguages && hasPreferredLanguage)
{ {
result = result.Where(i => string.IsNullOrEmpty(i.Language) || // Filter out languages that do not match the preferred languages.
preferredLanguages.Contains(i.Language, StringComparer.OrdinalIgnoreCase) || //
// 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)); string.Equals(i.Language, "en", StringComparison.OrdinalIgnoreCase));
} }
return result; return result.OrderByLanguageDescending(preferredLanguage);
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {

@ -101,7 +101,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
}); });
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages;
} }
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)

@ -13,7 +13,6 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Providers; using MediaBrowser.Model.Providers;
using TMDbLib.Objects.Find; using TMDbLib.Objects.Find;
@ -118,7 +117,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
}); });
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages;
} }
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)

@ -10,7 +10,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Providers; using MediaBrowser.Model.Providers;
namespace MediaBrowser.Providers.Plugins.Tmdb.People namespace MediaBrowser.Providers.Plugins.Tmdb.People
@ -77,7 +76,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
}; };
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages;
} }
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)

@ -12,7 +12,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Providers; using MediaBrowser.Model.Providers;
namespace MediaBrowser.Providers.Plugins.Tmdb.TV namespace MediaBrowser.Providers.Plugins.Tmdb.TV
@ -92,7 +91,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
}; };
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages;
} }
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)

@ -81,7 +81,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
}; };
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages;
} }
public IEnumerable<ImageType> GetSupportedImages(BaseItem item) public IEnumerable<ImageType> GetSupportedImages(BaseItem item)

@ -13,7 +13,6 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Providers; using MediaBrowser.Model.Providers;
namespace MediaBrowser.Providers.Plugins.Tmdb.TV namespace MediaBrowser.Providers.Plugins.Tmdb.TV
@ -107,7 +106,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
}; };
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages;
} }
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)

Loading…
Cancel
Save