Merge pull request #6531 from GodTamIt/img-lang

Fix images "not loading" after manual identification
This commit is contained in:
Bond-009 2021-09-10 13:35:03 +02:00 committed by GitHub
commit d7109d4d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 31 deletions

View File

@ -18,6 +18,12 @@ namespace MediaBrowser.Model.Extensions
/// <returns>The ordered remote image infos.</returns>
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);
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)

View File

@ -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)

View File

@ -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<string>();
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
/// </summary>
/// <param name="item">The item.</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="type">The type.</param>
/// <returns>Task{IEnumerable{RemoteImageInfo}}.</returns>
private async Task<IEnumerable<RemoteImageInfo>> GetImages(
BaseItem item,
IRemoteImageProvider provider,
IReadOnlyCollection<string> 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)
{

View File

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

View File

@ -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<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)

View File

@ -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<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)

View File

@ -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<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)

View File

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

View File

@ -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<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)