2013-11-26 14:36:11 -07:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2013-09-26 08:48:14 -07:00
|
|
|
|
using MediaBrowser.Model.LiveTv;
|
2013-11-25 13:39:23 -07:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
2013-09-26 08:48:14 -07:00
|
|
|
|
using ServiceStack.ServiceHost;
|
2013-11-25 13:39:23 -07:00
|
|
|
|
using System;
|
2013-09-26 08:48:14 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.LiveTv
|
|
|
|
|
{
|
|
|
|
|
[Route("/LiveTv/Services", "GET")]
|
|
|
|
|
[Api(Description = "Gets available live tv services.")]
|
|
|
|
|
public class GetServices : IReturn<List<LiveTvServiceInfo>>
|
|
|
|
|
{
|
2013-11-11 12:36:48 -07:00
|
|
|
|
[ApiMember(Name = "ServiceName", Description = "Optional filter by service.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string ServiceName { get; set; }
|
2013-09-26 08:48:14 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/LiveTv/Channels", "GET")]
|
|
|
|
|
[Api(Description = "Gets available live tv channels.")]
|
2013-11-25 13:39:23 -07:00
|
|
|
|
public class GetChannels : IReturn<QueryResult<ChannelInfoDto>>
|
2013-09-26 08:48:14 -07:00
|
|
|
|
{
|
2013-11-11 12:36:48 -07:00
|
|
|
|
[ApiMember(Name = "ServiceName", Description = "Optional filter by service.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string ServiceName { get; set; }
|
2013-11-24 13:51:45 -07:00
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "Type", Description = "Optional filter by channel type.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public ChannelType? Type { get; set; }
|
|
|
|
|
|
2013-11-25 19:53:48 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
2013-11-24 13:51:45 -07:00
|
|
|
|
public string UserId { get; set; }
|
2013-09-26 08:48:14 -07:00
|
|
|
|
}
|
2013-10-31 13:45:58 -07:00
|
|
|
|
|
2013-11-24 14:30:38 -07:00
|
|
|
|
[Route("/LiveTv/Channels/{Id}", "GET")]
|
|
|
|
|
[Api(Description = "Gets a live tv channel")]
|
|
|
|
|
public class GetChannel : IReturn<ChannelInfoDto>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
[ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Id { get; set; }
|
2013-11-25 19:53:48 -07:00
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "UserId", Description = "Optional user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string UserId { get; set; }
|
2013-11-24 14:30:38 -07:00
|
|
|
|
}
|
2013-11-25 09:15:31 -07:00
|
|
|
|
|
2013-11-25 19:53:48 -07:00
|
|
|
|
[Route("/LiveTv/Recordings", "GET")]
|
|
|
|
|
[Api(Description = "Gets live tv recordings")]
|
|
|
|
|
public class GetRecordings : IReturn<QueryResult<RecordingInfoDto>>
|
|
|
|
|
{
|
2013-11-26 14:36:11 -07:00
|
|
|
|
[ApiMember(Name = "ServiceName", Description = "Optional filter by service.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string ServiceName { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "ChannelId", Description = "Optional filter by channel id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string ChannelId { get; set; }
|
2013-11-25 19:53:48 -07:00
|
|
|
|
}
|
2013-11-26 14:36:11 -07:00
|
|
|
|
|
2013-11-25 09:15:31 -07:00
|
|
|
|
[Route("/LiveTv/Programs", "GET")]
|
2013-11-02 14:38:21 -07:00
|
|
|
|
[Api(Description = "Gets available live tv epgs..")]
|
2013-11-25 13:39:23 -07:00
|
|
|
|
public class GetPrograms : IReturn<QueryResult<ProgramInfoDto>>
|
2013-11-02 14:38:21 -07:00
|
|
|
|
{
|
2013-11-25 13:39:23 -07:00
|
|
|
|
[ApiMember(Name = "ServiceName", Description = "Live tv service name", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
2013-11-11 12:36:48 -07:00
|
|
|
|
public string ServiceName { get; set; }
|
|
|
|
|
|
2013-11-25 13:39:23 -07:00
|
|
|
|
[ApiMember(Name = "ChannelIds", Description = "The channels to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
2013-11-15 14:31:44 -07:00
|
|
|
|
public string ChannelIds { get; set; }
|
2013-11-25 19:53:48 -07:00
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string UserId { get; set; }
|
2013-11-02 14:38:21 -07:00
|
|
|
|
}
|
2013-11-15 14:31:44 -07:00
|
|
|
|
|
2013-09-26 08:48:14 -07:00
|
|
|
|
public class LiveTvService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
private readonly ILiveTvManager _liveTvManager;
|
|
|
|
|
|
|
|
|
|
public LiveTvService(ILiveTvManager liveTvManager)
|
|
|
|
|
{
|
|
|
|
|
_liveTvManager = liveTvManager;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 12:36:48 -07:00
|
|
|
|
private IEnumerable<ILiveTvService> GetServices(string serviceName)
|
2013-09-26 08:48:14 -07:00
|
|
|
|
{
|
2013-11-11 12:36:48 -07:00
|
|
|
|
IEnumerable<ILiveTvService> services = _liveTvManager.Services;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(serviceName))
|
|
|
|
|
{
|
2013-11-26 14:36:11 -07:00
|
|
|
|
services = services.Where(i => string.Equals(i.Name, serviceName, StringComparison.OrdinalIgnoreCase));
|
2013-11-11 12:36:48 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
2013-09-26 08:48:14 -07:00
|
|
|
|
|
2013-11-11 12:36:48 -07:00
|
|
|
|
public object Get(GetServices request)
|
|
|
|
|
{
|
|
|
|
|
var services = GetServices(request.ServiceName)
|
|
|
|
|
.Select(GetServiceInfo)
|
2013-09-26 08:48:14 -07:00
|
|
|
|
.ToList();
|
|
|
|
|
|
2013-11-11 12:36:48 -07:00
|
|
|
|
return ToOptimizedResult(services);
|
2013-09-26 08:48:14 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 13:45:58 -07:00
|
|
|
|
private LiveTvServiceInfo GetServiceInfo(ILiveTvService service)
|
|
|
|
|
{
|
|
|
|
|
return new LiveTvServiceInfo
|
|
|
|
|
{
|
|
|
|
|
Name = service.Name
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-26 08:48:14 -07:00
|
|
|
|
public object Get(GetChannels request)
|
|
|
|
|
{
|
2013-11-24 13:51:45 -07:00
|
|
|
|
var result = _liveTvManager.GetChannels(new ChannelQuery
|
|
|
|
|
{
|
|
|
|
|
ChannelType = request.Type,
|
|
|
|
|
ServiceName = request.ServiceName,
|
|
|
|
|
UserId = request.UserId
|
2013-09-26 08:48:14 -07:00
|
|
|
|
|
2013-11-25 13:39:23 -07:00
|
|
|
|
});
|
2013-09-26 08:48:14 -07:00
|
|
|
|
|
2013-11-25 13:39:23 -07:00
|
|
|
|
return ToOptimizedResult(result);
|
2013-09-26 08:48:14 -07:00
|
|
|
|
}
|
2013-10-31 13:45:58 -07:00
|
|
|
|
|
2013-11-24 14:30:38 -07:00
|
|
|
|
public object Get(GetChannel request)
|
|
|
|
|
{
|
2013-11-25 19:53:48 -07:00
|
|
|
|
var result = _liveTvManager.GetChannelInfoDto(request.Id, request.UserId);
|
2013-11-24 14:30:38 -07:00
|
|
|
|
|
2013-11-25 19:53:48 -07:00
|
|
|
|
return ToOptimizedResult(result);
|
2013-11-24 14:30:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 09:15:31 -07:00
|
|
|
|
public object Get(GetPrograms request)
|
2013-11-02 14:38:21 -07:00
|
|
|
|
{
|
2013-11-25 09:15:31 -07:00
|
|
|
|
var result = _liveTvManager.GetPrograms(new ProgramQuery
|
|
|
|
|
{
|
|
|
|
|
ServiceName = request.ServiceName,
|
2013-11-25 19:53:48 -07:00
|
|
|
|
ChannelIdList = (request.ChannelIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray(),
|
|
|
|
|
UserId = request.UserId
|
2013-11-26 14:36:11 -07:00
|
|
|
|
|
|
|
|
|
}, CancellationToken.None).Result;
|
2013-11-02 14:38:21 -07:00
|
|
|
|
|
2013-11-25 13:39:23 -07:00
|
|
|
|
return ToOptimizedResult(result);
|
2013-11-02 14:38:21 -07:00
|
|
|
|
}
|
2013-11-25 19:53:48 -07:00
|
|
|
|
|
|
|
|
|
public object Get(GetRecordings request)
|
|
|
|
|
{
|
2013-11-26 14:36:11 -07:00
|
|
|
|
var result = _liveTvManager.GetRecordings(new RecordingQuery
|
|
|
|
|
{
|
|
|
|
|
ChannelId = request.ChannelId,
|
|
|
|
|
ServiceName = request.ServiceName
|
|
|
|
|
|
|
|
|
|
}, CancellationToken.None).Result;
|
2013-11-25 19:53:48 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
2013-09-26 08:48:14 -07:00
|
|
|
|
}
|
2013-11-02 14:38:21 -07:00
|
|
|
|
}
|