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