fixes #709 - Add option to show all languages in image interface

This commit is contained in:
Luke Pulverenti 2014-02-11 22:33:59 -05:00
parent 03d17dea70
commit 5a41d7e0fd
6 changed files with 14 additions and 52 deletions

View File

@ -40,9 +40,6 @@ namespace MediaBrowser.Api.Images
[ApiMember(Name = "ProviderName", Description = "Optional. The image provider to use", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ProviderName { get; set; }
[ApiMember(Name = "IncludeAllLanguages", Description = "Optional.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool IncludeAllLanguages { get; set; }
}
[Route("/Items/{Id}/RemoteImages", "GET")]
@ -220,14 +217,7 @@ namespace MediaBrowser.Api.Images
private RemoteImageResult GetRemoteImageResult(BaseItem item, BaseRemoteImageRequest request)
{
var images = _providerManager.GetAvailableRemoteImages(item, new RemoteImageQuery
{
ProviderName = request.ProviderName,
IncludeAllLanguages = request.IncludeAllLanguages,
IncludeDisabledProviders = true,
ImageType = request.Type
}, CancellationToken.None).Result;
var images = _providerManager.GetAvailableRemoteImages(item, CancellationToken.None, request.ProviderName, request.Type).Result;
var imagesList = images.ToList();

View File

@ -190,8 +190,6 @@ namespace MediaBrowser.Controller.LiveTv
public override Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
{
DateLastSaved = DateTime.UtcNow;
// Avoid library manager and keep out of in-memory cache
// Not great that this class has to know about that, but we'll improve that later.
return ItemRepository.SaveItem(this, cancellationToken);

View File

@ -62,10 +62,11 @@ namespace MediaBrowser.Controller.Providers
/// Gets the available remote images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="query">The query.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="providerName">Name of the provider.</param>
/// <param name="type">The type.</param>
/// <returns>Task{IEnumerable{RemoteImageInfo}}.</returns>
Task<IEnumerable<RemoteImageInfo>> GetAvailableRemoteImages(IHasImages item, RemoteImageQuery query, CancellationToken cancellationToken);
Task<IEnumerable<RemoteImageInfo>> GetAvailableRemoteImages(IHasImages item, CancellationToken cancellationToken, string providerName = null, ImageType? type = null);
/// <summary>
/// Gets the image providers.

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.Providers
{
@ -26,15 +25,4 @@ namespace MediaBrowser.Model.Providers
/// <value>The providers.</value>
public List<string> Providers { get; set; }
}
public class RemoteImageQuery
{
public string ProviderName { get; set; }
public ImageType? ImageType { get; set; }
public bool IncludeDisabledProviders { get; set; }
public bool IncludeAllLanguages { get; set; }
}
}

View File

@ -213,14 +213,7 @@ namespace MediaBrowser.Providers.Manager
_logger.Debug("Running {0} for {1}", provider.GetType().Name, item.Path ?? item.Name);
var images = await _providerManager.GetAvailableRemoteImages(item, new RemoteImageQuery
{
ProviderName = provider.Name,
IncludeAllLanguages = false,
IncludeDisabledProviders = false,
}, cancellationToken).ConfigureAwait(false);
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, provider.Name).ConfigureAwait(false);
var list = images.ToList();
int minWidth;

View File

@ -205,31 +205,26 @@ namespace MediaBrowser.Providers.Manager
/// Gets the available remote images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="query">The query.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="providerName">Name of the provider.</param>
/// <param name="type">The type.</param>
/// <returns>Task{IEnumerable{RemoteImageInfo}}.</returns>
public async Task<IEnumerable<RemoteImageInfo>> GetAvailableRemoteImages(IHasImages item, RemoteImageQuery query, CancellationToken cancellationToken)
public async Task<IEnumerable<RemoteImageInfo>> GetAvailableRemoteImages(IHasImages item, CancellationToken cancellationToken, string providerName = null, ImageType? type = null)
{
var providers = GetRemoteImageProviders(item, query.IncludeDisabledProviders);
var providers = GetRemoteImageProviders(item, true);
if (!string.IsNullOrEmpty(query.ProviderName))
if (!string.IsNullOrEmpty(providerName))
{
var providerName = query.ProviderName;
providers = providers.Where(i => string.Equals(i.Name, providerName, StringComparison.OrdinalIgnoreCase));
}
var preferredLanguage = item.GetPreferredMetadataLanguage();
var language = query.IncludeAllLanguages ? null : preferredLanguage;
var tasks = providers.Select(i => GetImages(item, cancellationToken, i, language, query.ImageType));
var tasks = providers.Select(i => GetImages(item, cancellationToken, i, preferredLanguage, type));
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
var images = results.SelectMany(i => i);
return images;
return results.SelectMany(i => i);
}
/// <summary>
@ -249,15 +244,12 @@ namespace MediaBrowser.Providers.Manager
{
var result = await i.GetImages(item, type.Value, cancellationToken).ConfigureAwait(false);
return string.IsNullOrEmpty(preferredLanguage) ? result :
FilterImages(result, preferredLanguage);
return FilterImages(result, preferredLanguage);
}
else
{
var result = await i.GetAllImages(item, cancellationToken).ConfigureAwait(false);
return string.IsNullOrEmpty(preferredLanguage) ? result :
FilterImages(result, preferredLanguage);
return FilterImages(result, preferredLanguage);
}
}
catch (Exception ex)