#551 - Add manual image selection for movies

This commit is contained in:
Luke Pulverenti 2013-10-31 17:03:24 -04:00
parent 882d0681e6
commit 9adcdd007a
10 changed files with 128 additions and 40 deletions

View File

@ -5,10 +5,8 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Querying;
using ServiceStack.ServiceHost;
using System;
@ -34,21 +32,6 @@ namespace MediaBrowser.Api
public string Id { get; set; }
}
[Route("/Items/{Id}/RemoteImages/{Type}", "GET")]
[Api(Description = "Gets available remote images for an item")]
public class GetRemoteImages : IReturn<List<RemoteImageInfo>>
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
[ApiMember(Name = "Type", Description = "The image type", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public ImageType Type { get; set; }
}
/// <summary>
/// Class GetCriticReviews
/// </summary>
@ -225,7 +208,6 @@ namespace MediaBrowser.Api
private readonly ILibraryManager _libraryManager;
private readonly IUserManager _userManager;
private readonly IUserDataManager _userDataManager;
private readonly IProviderManager _providerManager;
private readonly IDtoService _dtoService;
@ -233,14 +215,13 @@ namespace MediaBrowser.Api
/// Initializes a new instance of the <see cref="LibraryService" /> class.
/// </summary>
public LibraryService(IItemRepository itemRepo, ILibraryManager libraryManager, IUserManager userManager,
IDtoService dtoService, IUserDataManager userDataManager, IProviderManager providerManager)
IDtoService dtoService, IUserDataManager userDataManager)
{
_itemRepo = itemRepo;
_libraryManager = libraryManager;
_userManager = userManager;
_dtoService = dtoService;
_userDataManager = userDataManager;
_providerManager = providerManager;
}
public object Get(GetFile request)
@ -259,15 +240,6 @@ namespace MediaBrowser.Api
return ToStaticFileResult(item.Path);
}
public object Get(GetRemoteImages request)
{
var item = _dtoService.GetItemByDtoId(request.Id);
var result = _providerManager.GetAvailableRemoteImages(item, request.Type, CancellationToken.None).Result;
return ToOptimizedResult(result);
}
/// <summary>
/// Gets the specified request.
/// </summary>

View File

@ -100,6 +100,7 @@
<Compile Include="Playback\StreamState.cs" />
<Compile Include="Playback\Progressive\VideoService.cs" />
<Compile Include="PluginService.cs" />
<Compile Include="RemoteImageService.cs" />
<Compile Include="ScheduledTasks\ScheduledTaskService.cs" />
<Compile Include="ScheduledTasks\ScheduledTasksWebSocketListener.cs" />
<Compile Include="ApiEntryPoint.cs" />

View File

@ -0,0 +1,82 @@
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using ServiceStack.ServiceHost;
using System.Linq;
using System.Threading;
namespace MediaBrowser.Api
{
[Route("/Items/{Id}/RemoteImages/{Type}", "GET")]
[Api(Description = "Gets available remote images for an item")]
public class GetRemoteImages : IReturn<RemoteImageResult>
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
[ApiMember(Name = "Type", Description = "The image type", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public ImageType Type { get; set; }
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get; set; }
}
public class RemoteImageService : BaseApiService
{
private readonly IProviderManager _providerManager;
private readonly IDtoService _dtoService;
public RemoteImageService(IProviderManager providerManager, IDtoService dtoService)
{
_providerManager = providerManager;
_dtoService = dtoService;
}
public object Get(GetRemoteImages request)
{
var item = _dtoService.GetItemByDtoId(request.Id);
var images = _providerManager.GetAvailableRemoteImages(item, request.Type, CancellationToken.None).Result;
var imagesList = images.ToList();
var result = new RemoteImageResult
{
TotalRecordCount = imagesList.Count
};
if (request.StartIndex.HasValue)
{
imagesList = imagesList.Skip(request.StartIndex.Value)
.ToList();
}
if (request.Limit.HasValue)
{
imagesList = imagesList.Take(request.Limit.Value)
.ToList();
}
result.Images = imagesList;
return ToOptimizedResult(result);
}
}
}

View File

@ -290,6 +290,9 @@
<Compile Include="..\MediaBrowser.Model\Providers\RemoteImageInfo.cs">
<Link>Providers\RemoteImageInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Providers\RemoteImageResult.cs">
<Link>Providers\RemoteImageResult.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Querying\ArtistsQuery.cs">
<Link>Querying\ArtistsQuery.cs</Link>
</Compile>

View File

@ -277,6 +277,9 @@
<Compile Include="..\MediaBrowser.Model\Providers\RemoteImageInfo.cs">
<Link>Providers\RemoteImageInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Providers\RemoteImageResult.cs">
<Link>Providers\RemoteImageResult.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Querying\ArtistsQuery.cs">
<Link>Querying\ArtistsQuery.cs</Link>
</Compile>

View File

@ -82,6 +82,7 @@
<Compile Include="Notifications\NotificationQuery.cs" />
<Compile Include="Notifications\NotificationResult.cs" />
<Compile Include="Notifications\NotificationsSummary.cs" />
<Compile Include="Providers\RemoteImageResult.cs" />
<Compile Include="Querying\ArtistsQuery.cs" />
<Compile Include="Querying\ItemCountsQuery.cs" />
<Compile Include="Querying\ItemReviewsResult.cs" />

View File

@ -0,0 +1,22 @@
using System.Collections.Generic;
namespace MediaBrowser.Model.Providers
{
/// <summary>
/// Class RemoteImageResult.
/// </summary>
public class RemoteImageResult
{
/// <summary>
/// Gets or sets the images.
/// </summary>
/// <value>The images.</value>
public List<RemoteImageInfo> Images { get; set; }
/// <summary>
/// Gets or sets the total record count.
/// </summary>
/// <value>The total record count.</value>
public int TotalRecordCount { get; set; }
}
}

View File

@ -69,11 +69,11 @@ namespace MediaBrowser.Server.Implementations.Providers
throw new ArgumentNullException("mimeType");
}
var saveLocally = _config.Configuration.SaveLocalMeta || item is IItemByName || item is User;
var saveLocally = _config.Configuration.SaveLocalMeta && item.Parent != null && !(item is Audio);
if (item is Audio || item.Parent == null)
if (item is IItemByName || item is User)
{
saveLocally = false;
saveLocally = true;
}
if (type != ImageType.Primary && item is Episode)

View File

@ -306,16 +306,20 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
});
};
self.getAvailableRemoteImages = function (itemId, imageType) {
self.getAvailableRemoteImages = function (options) {
if (!itemId) {
throw new Error("null itemId");
}
if (!imageType) {
throw new Error("null imageType");
if (!options) {
throw new Error("null options");
}
var url = self.getUrl("Items/" + itemId + "/RemoteImages/" + imageType);
var urlPrefix = "Items/" + options.itemId;
var imageType = options.imageType;
delete options.itemId;
delete options.imageType;
var url = self.getUrl(urlPrefix + "/RemoteImages/" + imageType, options);
return self.ajax({
type: "GET",

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.183" targetFramework="net45" />
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.184" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.62" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" />
</packages>