diff --git a/MediaBrowser.Api/Images/RemoteImageService.cs b/MediaBrowser.Api/Images/RemoteImageService.cs index 617cf0ca14..0cf51abac8 100644 --- a/MediaBrowser.Api/Images/RemoteImageService.cs +++ b/MediaBrowser.Api/Images/RemoteImageService.cs @@ -11,6 +11,7 @@ using MediaBrowser.Model.Providers; using ServiceStack.ServiceHost; using ServiceStack.Text.Controller; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; @@ -70,6 +71,35 @@ namespace MediaBrowser.Api.Images public string Name { get; set; } } + [Route("/Items/{Id}/RemoteImages/Providers", "GET")] + [Api(Description = "Gets available remote image providers for an item")] + public class GetRemoteImageProviders : IReturn> + { + /// + /// Gets or sets the id. + /// + /// The id. + [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Id { get; set; } + } + + [Route("/Artists/{Name}/RemoteImages/Providers", "GET")] + [Route("/Genres/{Name}/RemoteImages/Providers", "GET")] + [Route("/GameGenres/{Name}/RemoteImages/Providers", "GET")] + [Route("/MusicGenres/{Name}/RemoteImages/Providers", "GET")] + [Route("/Persons/{Name}/RemoteImages/Providers", "GET")] + [Route("/Studios/{Name}/RemoteImages/Providers", "GET")] + [Api(Description = "Gets available remote image providers for an item")] + public class GetItemByNameRemoteImageProviders : IReturn> + { + /// + /// Gets or sets the id. + /// + /// The id. + [ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Name { get; set; } + } + public class BaseDownloadRemoteImage : IReturnVoid { [ApiMember(Name = "Type", Description = "The image type", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] @@ -81,7 +111,7 @@ namespace MediaBrowser.Api.Images [ApiMember(Name = "ImageUrl", Description = "The image url", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string ImageUrl { get; set; } } - + [Route("/Items/{Id}/RemoteImages/Download", "POST")] [Api(Description = "Downloads a remote image for an item")] public class DownloadRemoteImage : BaseDownloadRemoteImage @@ -110,7 +140,7 @@ namespace MediaBrowser.Api.Images [ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] public string Name { get; set; } } - + [Route("/Images/Remote", "GET")] [Api(Description = "Gets a remote image")] public class GetRemoteImage @@ -140,6 +170,37 @@ namespace MediaBrowser.Api.Images _libraryManager = libraryManager; } + public object Get(GetRemoteImageProviders request) + { + var item = _dtoService.GetItemByDtoId(request.Id); + + var result = GetImageProviders(item); + + return ToOptimizedResult(result); + } + + public object Get(GetItemByNameRemoteImageProviders request) + { + var pathInfo = PathInfo.Parse(RequestContext.PathInfo); + var type = pathInfo.GetArgumentValue(0); + + var item = GetItemByName(request.Name, type, _libraryManager); + + var result = GetImageProviders(item); + + return ToOptimizedResult(result); + } + + private List GetImageProviders(BaseItem item) + { + return _providerManager.GetImageProviders(item).Select(i => new ImageProviderInfo + { + Name = i.Name, + Priority = i.Priority + + }).ToList(); + } + public object Get(GetRemoteImages request) { var item = _dtoService.GetItemByDtoId(request.Id); @@ -158,7 +219,7 @@ namespace MediaBrowser.Api.Images return GetRemoteImageResult(item, request); } - + private RemoteImageResult GetRemoteImageResult(BaseItem item, BaseRemoteImageRequest request) { var images = _providerManager.GetAvailableRemoteImages(item, CancellationToken.None, request.ProviderName, request.Type).Result; @@ -212,7 +273,7 @@ namespace MediaBrowser.Api.Images Task.WaitAll(task); } - + /// /// Downloads the remote image. /// diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index 542620d47d..a5bff2b40b 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -296,6 +296,9 @@ Plugins\PluginInfo.cs + + Providers\ImageProviderInfo.cs + Providers\RemoteImageInfo.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 31f781faef..60deab47d3 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -283,6 +283,9 @@ Plugins\PluginInfo.cs + + Providers\ImageProviderInfo.cs + Providers\RemoteImageInfo.cs diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 3ca4ff571e..d641b27052 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -61,6 +61,7 @@ + diff --git a/MediaBrowser.Model/Providers/ImageProviderInfo.cs b/MediaBrowser.Model/Providers/ImageProviderInfo.cs new file mode 100644 index 0000000000..325aa90cb7 --- /dev/null +++ b/MediaBrowser.Model/Providers/ImageProviderInfo.cs @@ -0,0 +1,20 @@ +namespace MediaBrowser.Model.Providers +{ + /// + /// Class ImageProviderInfo. + /// + public class ImageProviderInfo + { + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the priority. + /// + /// The priority. + public int Priority { get; set; } + } +} diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index a55879d2da..3254b84f36 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -342,6 +342,23 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi return urlPrefix; } + self.getRemoteImageProviders = function (options) { + + if (!options) { + throw new Error("null options"); + } + + var urlPrefix = getRemoteImagePrefix(options); + + var url = self.getUrl(urlPrefix + "/RemoteImages/Providers", options); + + return self.ajax({ + type: "GET", + url: url, + dataType: "json" + }); + }; + self.getAvailableRemoteImages = function (options) { if (!options) { diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.config index 62726239a1..ad8173057b 100644 --- a/MediaBrowser.WebDashboard/packages.config +++ b/MediaBrowser.WebDashboard/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file