jellyfin/MediaBrowser.Api/VideosService.cs

76 lines
2.8 KiB
C#
Raw Normal View History

using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Querying;
using ServiceStack.ServiceHost;
using System;
using System.Linq;
namespace MediaBrowser.Api
{
[Route("/Videos/{Id}/AdditionalParts", "GET")]
[Api(Description = "Gets additional parts for a video.")]
public class GetAdditionalParts : IReturn<ItemsResult>
{
[ApiMember(Name = "UserId", Description = "Optional. Filter by user id, and attach user data", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid? UserId { get; set; }
/// <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; }
}
public class VideosService : BaseApiService
{
private readonly ILibraryManager _libraryManager;
private readonly IUserManager _userManager;
2013-09-04 17:02:19 +00:00
private readonly IDtoService _dtoService;
2013-09-25 22:35:23 +00:00
public VideosService( ILibraryManager libraryManager, IUserManager userManager, IDtoService dtoService)
{
_libraryManager = libraryManager;
_userManager = userManager;
2013-09-04 17:02:19 +00:00
_dtoService = dtoService;
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetAdditionalParts request)
{
var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;
var item = string.IsNullOrEmpty(request.Id)
? (request.UserId.HasValue
? user.RootFolder
: (Folder)_libraryManager.RootFolder)
2013-09-04 17:02:19 +00:00
: _dtoService.GetItemByDtoId(request.Id, request.UserId);
// Get everything
var fields = Enum.GetNames(typeof(ItemFields))
.Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
.ToList();
var video = (Video)item;
2013-09-25 22:35:23 +00:00
var items = video.AdditionalPartIds.Select(_libraryManager.GetItemById)
.OrderBy(i => i.SortName)
2013-09-04 17:02:19 +00:00
.Select(i => _dtoService.GetBaseItemDto(i, fields, user, video))
.ToArray();
var result = new ItemsResult
{
Items = items,
TotalRecordCount = items.Length
};
return ToOptimizedResult(result);
}
}
}