From 1ff62edd845e0ff2da2150307b4addb13794bd16 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 11 Feb 2014 22:46:27 -0500 Subject: [PATCH] fixes #709 - show all languages --- MediaBrowser.Api/Images/RemoteImageService.cs | 12 +++++++- .../LiveTv/LiveTvProgram.cs | 2 ++ .../Providers/IProviderManager.cs | 5 ++-- .../Providers/RemoteImageResult.cs | 12 ++++++++ .../Manager/ItemImageProvider.cs | 9 +++++- .../Manager/ProviderManager.cs | 30 ++++++++++++------- .../MediaBrowser.ServerApplication.csproj | 2 +- 7 files changed, 55 insertions(+), 17 deletions(-) diff --git a/MediaBrowser.Api/Images/RemoteImageService.cs b/MediaBrowser.Api/Images/RemoteImageService.cs index 960de017d..36b509c74 100644 --- a/MediaBrowser.Api/Images/RemoteImageService.cs +++ b/MediaBrowser.Api/Images/RemoteImageService.cs @@ -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(); diff --git a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs index 48041da11..e7a501479 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs @@ -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); diff --git a/MediaBrowser.Controller/Providers/IProviderManager.cs b/MediaBrowser.Controller/Providers/IProviderManager.cs index a4800955d..691a5add6 100644 --- a/MediaBrowser.Controller/Providers/IProviderManager.cs +++ b/MediaBrowser.Controller/Providers/IProviderManager.cs @@ -62,11 +62,10 @@ namespace MediaBrowser.Controller.Providers /// Gets the available remote images. /// /// The item. + /// The query. /// The cancellation token. - /// Name of the provider. - /// The type. /// Task{IEnumerable{RemoteImageInfo}}. - Task> GetAvailableRemoteImages(IHasImages item, CancellationToken cancellationToken, string providerName = null, ImageType? type = null); + Task> GetAvailableRemoteImages(IHasImages item, RemoteImageQuery query, CancellationToken cancellationToken); /// /// Gets the image providers. diff --git a/MediaBrowser.Model/Providers/RemoteImageResult.cs b/MediaBrowser.Model/Providers/RemoteImageResult.cs index 1c60db6ae..ed2788c0b 100644 --- a/MediaBrowser.Model/Providers/RemoteImageResult.cs +++ b/MediaBrowser.Model/Providers/RemoteImageResult.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using MediaBrowser.Model.Entities; namespace MediaBrowser.Model.Providers { @@ -25,4 +26,15 @@ namespace MediaBrowser.Model.Providers /// The providers. public List 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; } + } } diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs index c4cce9310..773ad354c 100644 --- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs +++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs @@ -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; diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index db0a25ec6..f49bbb6ae 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -205,26 +205,31 @@ namespace MediaBrowser.Providers.Manager /// Gets the available remote images. /// /// The item. + /// The query. /// The cancellation token. - /// Name of the provider. - /// The type. /// Task{IEnumerable{RemoteImageInfo}}. - public async Task> GetAvailableRemoteImages(IHasImages item, CancellationToken cancellationToken, string providerName = null, ImageType? type = null) + public async Task> 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; } /// @@ -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 } } } -} +} \ No newline at end of file diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 874a89a3e..bfee13bf8 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {68468A75-9778-4F9B-98EE-17B223B0314B} + {156EA256-AD2D-4D2F-B116-2ED4B9EFD869} WinExe Properties MediaBrowser.ServerApplication