fixes #709 - show all languages

This commit is contained in:
Luke Pulverenti 2014-02-11 22:46:27 -05:00
parent e57259b302
commit 1ff62edd84
7 changed files with 55 additions and 17 deletions

View File

@ -40,6 +40,9 @@ 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")]
@ -217,7 +220,14 @@ namespace MediaBrowser.Api.Images
private RemoteImageResult GetRemoteImageResult(BaseItem item, BaseRemoteImageRequest request)
{
var images = _providerManager.GetAvailableRemoteImages(item, CancellationToken.None, request.ProviderName, request.Type).Result;
var images = _providerManager.GetAvailableRemoteImages(item, new RemoteImageQuery
{
ProviderName = request.ProviderName,
IncludeAllLanguages = request.IncludeAllLanguages,
IncludeDisabledProviders = true,
ImageType = request.Type
}, CancellationToken.None).Result;
var imagesList = images.ToList();

View File

@ -190,6 +190,8 @@ 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,11 +62,10 @@ 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, CancellationToken cancellationToken, string providerName = null, ImageType? type = null);
Task<IEnumerable<RemoteImageInfo>> GetAvailableRemoteImages(IHasImages item, RemoteImageQuery query, CancellationToken cancellationToken);
/// <summary>
/// Gets the image providers.

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.Providers
{
@ -25,4 +26,15 @@ 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,7 +213,14 @@ namespace MediaBrowser.Providers.Manager
_logger.Debug("Running {0} for {1}", provider.GetType().Name, item.Path ?? item.Name);
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, provider.Name).ConfigureAwait(false);
var images = await _providerManager.GetAvailableRemoteImages(item, new RemoteImageQuery
{
ProviderName = provider.Name,
IncludeAllLanguages = false,
IncludeDisabledProviders = false,
}, cancellationToken).ConfigureAwait(false);
var list = images.ToList();
int minWidth;

View File

@ -205,26 +205,31 @@ 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, CancellationToken cancellationToken, string providerName = null, ImageType? type = null)
public async Task<IEnumerable<RemoteImageInfo>> GetAvailableRemoteImages(IHasImages item, RemoteImageQuery query, CancellationToken cancellationToken)
{
var providers = GetRemoteImageProviders(item, true);
var providers = GetRemoteImageProviders(item, query.IncludeDisabledProviders);
if (!string.IsNullOrEmpty(providerName))
if (!string.IsNullOrEmpty(query.ProviderName))
{
var providerName = query.ProviderName;
providers = providers.Where(i => string.Equals(i.Name, providerName, StringComparison.OrdinalIgnoreCase));
}
var preferredLanguage = item.GetPreferredMetadataLanguage();
var tasks = providers.Select(i => GetImages(item, cancellationToken, i, preferredLanguage, type));
var language = query.IncludeAllLanguages ? null : preferredLanguage;
var tasks = providers.Select(i => GetImages(item, cancellationToken, i, language, query.ImageType));
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
return results.SelectMany(i => i);
var images = results.SelectMany(i => i);
return images;
}
/// <summary>
@ -244,12 +249,15 @@ namespace MediaBrowser.Providers.Manager
{
var result = await i.GetImages(item, type.Value, cancellationToken).ConfigureAwait(false);
return FilterImages(result, preferredLanguage);
return string.IsNullOrEmpty(preferredLanguage) ? result :
FilterImages(result, preferredLanguage);
}
else
{
var result = await i.GetAllImages(item, cancellationToken).ConfigureAwait(false);
return FilterImages(result, preferredLanguage);
return string.IsNullOrEmpty(preferredLanguage) ? result :
FilterImages(result, preferredLanguage);
}
}
catch (Exception ex)
@ -347,7 +355,7 @@ namespace MediaBrowser.Providers.Manager
return index;
}
}
// Not configured. Just return some high number to put it at the end.
return 100;
})
@ -671,4 +679,4 @@ namespace MediaBrowser.Providers.Manager
}
}
}
}
}

View File

@ -4,7 +4,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{68468A75-9778-4F9B-98EE-17B223B0314B}</ProjectGuid>
<ProjectGuid>{156EA256-AD2D-4D2F-B116-2ED4B9EFD869}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MediaBrowser.ServerApplication</RootNamespace>