2015-03-07 22:43:53 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-11-19 02:45:12 +00:00
|
|
|
|
using MediaBrowser.Controller.Net;
|
2015-03-16 16:47:14 +00:00
|
|
|
|
using MediaBrowser.Model.Dlna;
|
|
|
|
|
using MediaBrowser.Model.Dto;
|
2014-11-19 02:45:12 +00:00
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
|
|
|
|
using ServiceStack;
|
2015-03-16 16:47:14 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-11-19 02:45:12 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Playback
|
|
|
|
|
{
|
2015-03-15 19:22:04 +00:00
|
|
|
|
[Route("/Items/{Id}/MediaInfo", "GET", Summary = "Gets live playback media info for an item")]
|
2014-11-19 02:45:12 +00:00
|
|
|
|
public class GetLiveMediaInfo : IReturn<LiveMediaInfoResult>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string UserId { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-07 22:43:53 +00:00
|
|
|
|
[Route("/Items/{Id}/PlaybackInfo", "GET", Summary = "Gets live playback media info for an item")]
|
|
|
|
|
public class GetPlaybackInfo : IReturn<LiveMediaInfoResult>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string UserId { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-19 02:45:12 +00:00
|
|
|
|
[Authenticated]
|
|
|
|
|
public class MediaInfoService : BaseApiService
|
|
|
|
|
{
|
2015-03-07 22:43:53 +00:00
|
|
|
|
private readonly IMediaSourceManager _mediaSourceManager;
|
2014-11-19 02:45:12 +00:00
|
|
|
|
|
2015-03-07 22:43:53 +00:00
|
|
|
|
public MediaInfoService(IMediaSourceManager mediaSourceManager)
|
2014-11-19 02:45:12 +00:00
|
|
|
|
{
|
2015-03-07 22:43:53 +00:00
|
|
|
|
_mediaSourceManager = mediaSourceManager;
|
2014-11-19 02:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 16:47:14 +00:00
|
|
|
|
public Task<object> Get(GetPlaybackInfo request)
|
2014-11-19 02:45:12 +00:00
|
|
|
|
{
|
2015-03-16 16:47:14 +00:00
|
|
|
|
return GetPlaybackInfo(request.Id, request.UserId);
|
|
|
|
|
}
|
2014-11-19 02:45:12 +00:00
|
|
|
|
|
2015-03-16 16:47:14 +00:00
|
|
|
|
public Task<object> Get(GetLiveMediaInfo request)
|
|
|
|
|
{
|
|
|
|
|
return GetPlaybackInfo(request.Id, request.UserId);
|
2015-03-07 22:43:53 +00:00
|
|
|
|
}
|
2014-11-26 04:12:29 +00:00
|
|
|
|
|
2015-03-16 16:47:14 +00:00
|
|
|
|
private async Task<object> GetPlaybackInfo(string id, string userId)
|
2015-03-07 22:43:53 +00:00
|
|
|
|
{
|
2015-03-16 16:47:14 +00:00
|
|
|
|
IEnumerable<MediaSourceInfo> mediaSources;
|
|
|
|
|
var result = new LiveMediaInfoResult();
|
2014-11-19 02:45:12 +00:00
|
|
|
|
|
2015-03-16 16:47:14 +00:00
|
|
|
|
try
|
2014-11-19 02:45:12 +00:00
|
|
|
|
{
|
2015-03-16 16:47:14 +00:00
|
|
|
|
mediaSources = await _mediaSourceManager.GetPlayackMediaSources(id, userId, true, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (PlaybackException ex)
|
|
|
|
|
{
|
|
|
|
|
mediaSources = new List<MediaSourceInfo>();
|
|
|
|
|
result.ErrorCode = ex.ErrorCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.MediaSources = mediaSources.ToList();
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
2014-11-19 02:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|