pull/13748/merge
THOMAS B 3 weeks ago committed by GitHub
commit 8cbc543b67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -335,11 +335,7 @@ namespace MediaBrowser.Providers.Manager
if (!includeAllLanguages && hasPreferredLanguage)
{
// 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));
result = result.Where(i => IsValidImage(i, preferredLanguage));
}
return result.OrderByLanguageDescending(preferredLanguage);
@ -355,6 +351,50 @@ namespace MediaBrowser.Providers.Manager
}
}
/// <summary>
/// Check if image type requires language specification.
/// </summary>
/// <param name="type">The image type.</param>
/// <returns>True if image requires language specification, otherwise False.</returns>
private bool RequiresLanguage(ImageType type)
{
return type is ImageType.Primary or ImageType.Logo or ImageType.Thumb;
}
/// <summary>
/// Check if image is valid based on language requirements.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="preferredLanguage">The preferred language.</param>
/// <param name="fallbackLanguage">The fallback language (default is English => "en").</param>
/// <returns>True if image meets language requirements, otherwise False.</returns>
private bool IsValidImage(RemoteImageInfo image, string preferredLanguage, string fallbackLanguage = "en")
{
// TODO: should exception case of "en" (English) eventually be removed?
bool matchesLanguage = MatchesLanguage(image.Language, preferredLanguage) || MatchesLanguage(image.Language, fallbackLanguage);
if (RequiresLanguage(image.Type))
{
return image.Language is not null && matchesLanguage;
}
return string.IsNullOrEmpty(image.Language) || matchesLanguage;
}
/// <summary>
/// Compares two language strings in a case-insensitive manner.
/// </summary>
/// <param name="imageLanguage">The language code of the image.</param>
/// <param name="targetLanguage">The language code to compare against.</param>
/// <returns>
/// True if the language codes match (case-insensitive), otherwise False.
/// Returns False if either parameter is null.
/// </returns>
private bool MatchesLanguage(string imageLanguage, string targetLanguage)
{
return string.Equals(imageLanguage, targetLanguage, StringComparison.OrdinalIgnoreCase);
}
/// <inheritdoc/>
public IEnumerable<ImageProviderInfo> GetRemoteImageProviderInfo(BaseItem item)
{

Loading…
Cancel
Save