updated live tv api
This commit is contained in:
parent
a347475b7b
commit
78e6304ac0
|
@ -12,27 +12,35 @@ namespace MediaBrowser.Api.LiveTv
|
||||||
[Api(Description = "Gets available live tv services.")]
|
[Api(Description = "Gets available live tv services.")]
|
||||||
public class GetServices : IReturn<List<LiveTvServiceInfo>>
|
public class GetServices : IReturn<List<LiveTvServiceInfo>>
|
||||||
{
|
{
|
||||||
|
[ApiMember(Name = "ServiceName", Description = "Optional filter by service.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||||
|
public string ServiceName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("/LiveTv/Channels", "GET")]
|
[Route("/LiveTv/Channels", "GET")]
|
||||||
[Api(Description = "Gets available live tv channels.")]
|
[Api(Description = "Gets available live tv channels.")]
|
||||||
public class GetChannels : IReturn<List<ChannelInfoDto>>
|
public class GetChannels : IReturn<List<ChannelInfoDto>>
|
||||||
{
|
{
|
||||||
// Add filter by service if needed, and/or other filters
|
[ApiMember(Name = "ServiceName", Description = "Optional filter by service.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||||
|
public string ServiceName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("/LiveTv/Recordings", "GET")]
|
[Route("/LiveTv/Recordings", "GET")]
|
||||||
[Api(Description = "Gets available live tv recordings.")]
|
[Api(Description = "Gets available live tv recordings.")]
|
||||||
public class GetRecordings : IReturn<List<RecordingInfo>>
|
public class GetRecordings : IReturn<List<RecordingInfo>>
|
||||||
{
|
{
|
||||||
// Add filter by service if needed, and/or other filters
|
[ApiMember(Name = "ServiceName", Description = "Optional filter by service.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||||
|
public string ServiceName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("/LiveTv/EPG", "GET")]
|
[Route("/LiveTv/EPG", "GET")]
|
||||||
[Api(Description = "Gets available live tv epgs..")]
|
[Api(Description = "Gets available live tv epgs..")]
|
||||||
public class GetEpg : IReturn<List<EpgFullInfo>>
|
public class GetEpg : IReturn<EpgFullInfo>
|
||||||
{
|
{
|
||||||
// Add filter by service if needed, and/or other filters
|
[ApiMember(Name = "ServiceName", Description = "The live tv service name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||||
|
public string ServiceName { get; set; }
|
||||||
|
|
||||||
|
[ApiMember(Name = "ChannelId", Description = "The channel id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||||
|
public string ChannelId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LiveTvService : BaseApiService
|
public class LiveTvService : BaseApiService
|
||||||
|
@ -44,14 +52,25 @@ namespace MediaBrowser.Api.LiveTv
|
||||||
_liveTvManager = liveTvManager;
|
_liveTvManager = liveTvManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<ILiveTvService> GetServices(string serviceName)
|
||||||
|
{
|
||||||
|
IEnumerable<ILiveTvService> services = _liveTvManager.Services;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(serviceName))
|
||||||
|
{
|
||||||
|
services = services.Where(i => string.Equals(i.Name, serviceName, System.StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
public object Get(GetServices request)
|
public object Get(GetServices request)
|
||||||
{
|
{
|
||||||
var services = _liveTvManager.Services;
|
var services = GetServices(request.ServiceName)
|
||||||
|
.Select(GetServiceInfo)
|
||||||
var result = services.Select(GetServiceInfo)
|
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
return ToOptimizedResult(services);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LiveTvServiceInfo GetServiceInfo(ILiveTvService service)
|
private LiveTvServiceInfo GetServiceInfo(ILiveTvService service)
|
||||||
|
@ -71,7 +90,7 @@ namespace MediaBrowser.Api.LiveTv
|
||||||
|
|
||||||
private async Task<IEnumerable<ChannelInfoDto>> GetChannelsAsync(GetChannels request)
|
private async Task<IEnumerable<ChannelInfoDto>> GetChannelsAsync(GetChannels request)
|
||||||
{
|
{
|
||||||
var services = _liveTvManager.Services;
|
var services = GetServices(request.ServiceName);
|
||||||
|
|
||||||
var tasks = services.Select(i => i.GetChannelsAsync(CancellationToken.None));
|
var tasks = services.Select(i => i.GetChannelsAsync(CancellationToken.None));
|
||||||
|
|
||||||
|
@ -91,7 +110,7 @@ namespace MediaBrowser.Api.LiveTv
|
||||||
|
|
||||||
private async Task<IEnumerable<RecordingInfo>> GetRecordingsAsync(GetRecordings request)
|
private async Task<IEnumerable<RecordingInfo>> GetRecordingsAsync(GetRecordings request)
|
||||||
{
|
{
|
||||||
var services = _liveTvManager.Services;
|
var services = GetServices(request.ServiceName);
|
||||||
|
|
||||||
var tasks = services.Select(i => i.GetRecordingsAsync(CancellationToken.None));
|
var tasks = services.Select(i => i.GetRecordingsAsync(CancellationToken.None));
|
||||||
|
|
||||||
|
@ -109,13 +128,12 @@ namespace MediaBrowser.Api.LiveTv
|
||||||
|
|
||||||
private async Task<IEnumerable<EpgFullInfo>> GetEpgAsync(GetEpg request)
|
private async Task<IEnumerable<EpgFullInfo>> GetEpgAsync(GetEpg request)
|
||||||
{
|
{
|
||||||
var services = _liveTvManager.Services;
|
var service = GetServices(request.ServiceName)
|
||||||
|
.First();
|
||||||
|
|
||||||
var tasks = services.Select(i => i.GetEpgAsync(CancellationToken.None));
|
var epg = await service.GetEpgAsync(request.ChannelId, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|
||||||
var epg = await Task.WhenAll(tasks).ConfigureAwait(false);
|
return epg;
|
||||||
|
|
||||||
return epg.SelectMany(i => i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using MediaBrowser.Model.LiveTv;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Model.LiveTv;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.LiveTv
|
namespace MediaBrowser.Controller.LiveTv
|
||||||
{
|
{
|
||||||
|
@ -23,8 +23,19 @@ namespace MediaBrowser.Controller.LiveTv
|
||||||
/// <returns>Task{IEnumerable{ChannelInfo}}.</returns>
|
/// <returns>Task{IEnumerable{ChannelInfo}}.</returns>
|
||||||
Task<IEnumerable<ChannelInfo>> GetChannelsAsync(CancellationToken cancellationToken);
|
Task<IEnumerable<ChannelInfo>> GetChannelsAsync(CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the recordings asynchronous.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns>Task{IEnumerable{RecordingInfo}}.</returns>
|
||||||
Task<IEnumerable<RecordingInfo>> GetRecordingsAsync(CancellationToken cancellationToken);
|
Task<IEnumerable<RecordingInfo>> GetRecordingsAsync(CancellationToken cancellationToken);
|
||||||
|
|
||||||
Task<IEnumerable<EpgFullInfo>> GetEpgAsync(CancellationToken cancellationToken);
|
/// <summary>
|
||||||
|
/// Gets the epg asynchronous.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="channelId">The channel identifier.</param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns>Task{IEnumerable{EpgFullInfo}}.</returns>
|
||||||
|
Task<IEnumerable<EpgFullInfo>> GetEpgAsync(string channelId, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user