2013-09-26 08:48:14 -07:00
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
|
|
|
|
using MediaBrowser.Model.LiveTv;
|
|
|
|
|
using ServiceStack.ServiceHost;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.LiveTv
|
|
|
|
|
{
|
|
|
|
|
[Route("/LiveTv/Services", "GET")]
|
|
|
|
|
[Api(Description = "Gets available live tv services.")]
|
|
|
|
|
public class GetServices : IReturn<List<LiveTvServiceInfo>>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/LiveTv/Channels", "GET")]
|
|
|
|
|
[Api(Description = "Gets available live tv channels.")]
|
|
|
|
|
public class GetChannels : IReturn<List<ChannelInfoDto>>
|
|
|
|
|
{
|
|
|
|
|
// Add filter by service if needed, and/or other filters
|
|
|
|
|
}
|
2013-10-31 13:45:58 -07:00
|
|
|
|
|
|
|
|
|
[Route("/LiveTv/Recordings", "GET")]
|
|
|
|
|
[Api(Description = "Gets available live tv recordings.")]
|
|
|
|
|
public class GetRecordings : IReturn<List<RecordingInfo>>
|
|
|
|
|
{
|
|
|
|
|
// Add filter by service if needed, and/or other filters
|
|
|
|
|
}
|
2013-11-02 14:38:21 -07:00
|
|
|
|
|
|
|
|
|
[Route("/LiveTv/EPG", "GET")]
|
|
|
|
|
[Api(Description = "Gets available live tv epgs..")]
|
|
|
|
|
public class GetEpg : IReturn<List<EpgFullInfo>>
|
|
|
|
|
{
|
|
|
|
|
// Add filter by service if needed, and/or other filters
|
|
|
|
|
}
|
2013-09-26 08:48:14 -07:00
|
|
|
|
|
|
|
|
|
public class LiveTvService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
private readonly ILiveTvManager _liveTvManager;
|
|
|
|
|
|
|
|
|
|
public LiveTvService(ILiveTvManager liveTvManager)
|
|
|
|
|
{
|
|
|
|
|
_liveTvManager = liveTvManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Get(GetServices request)
|
|
|
|
|
{
|
|
|
|
|
var services = _liveTvManager.Services;
|
|
|
|
|
|
|
|
|
|
var result = services.Select(GetServiceInfo)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
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-09-26 09:17:36 -07:00
|
|
|
|
var result = GetChannelsAsync(request).Result;
|
2013-09-26 08:48:14 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 13:45:58 -07:00
|
|
|
|
private async Task<IEnumerable<ChannelInfoDto>> GetChannelsAsync(GetChannels request)
|
2013-09-26 08:48:14 -07:00
|
|
|
|
{
|
|
|
|
|
var services = _liveTvManager.Services;
|
|
|
|
|
|
2013-10-31 13:45:58 -07:00
|
|
|
|
var tasks = services.Select(i => i.GetChannelsAsync(CancellationToken.None));
|
2013-09-26 08:48:14 -07:00
|
|
|
|
|
2013-10-31 13:45:58 -07:00
|
|
|
|
var channelLists = await Task.WhenAll(tasks).ConfigureAwait(false);
|
2013-09-26 08:48:14 -07:00
|
|
|
|
|
|
|
|
|
// Aggregate all channels from all services
|
|
|
|
|
return channelLists.SelectMany(i => i)
|
|
|
|
|
.Select(_liveTvManager.GetChannelInfoDto);
|
|
|
|
|
}
|
2013-10-31 13:45:58 -07:00
|
|
|
|
|
|
|
|
|
public object Get(GetRecordings request)
|
2013-09-26 08:48:14 -07:00
|
|
|
|
{
|
2013-10-31 13:45:58 -07:00
|
|
|
|
var result = GetRecordingsAsync(request).Result;
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<IEnumerable<RecordingInfo>> GetRecordingsAsync(GetRecordings request)
|
|
|
|
|
{
|
|
|
|
|
var services = _liveTvManager.Services;
|
|
|
|
|
|
|
|
|
|
var tasks = services.Select(i => i.GetRecordingsAsync(CancellationToken.None));
|
|
|
|
|
|
|
|
|
|
var recordings = await Task.WhenAll(tasks).ConfigureAwait(false);
|
|
|
|
|
|
2013-11-10 14:47:26 -07:00
|
|
|
|
return recordings.SelectMany(i => i).Select(_liveTvManager.GetRecordingInfo);
|
2013-09-26 08:48:14 -07:00
|
|
|
|
}
|
2013-11-02 14:38:21 -07:00
|
|
|
|
|
|
|
|
|
public object Get(GetEpg request)
|
|
|
|
|
{
|
|
|
|
|
var result = GetEpgAsync(request).Result;
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<IEnumerable<EpgFullInfo>> GetEpgAsync(GetEpg request)
|
|
|
|
|
{
|
|
|
|
|
var services = _liveTvManager.Services;
|
|
|
|
|
|
|
|
|
|
var tasks = services.Select(i => i.GetEpgAsync(CancellationToken.None));
|
|
|
|
|
|
|
|
|
|
var epg = await Task.WhenAll(tasks).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return epg.SelectMany(i => i);
|
|
|
|
|
}
|
2013-09-26 08:48:14 -07:00
|
|
|
|
}
|
2013-11-02 14:38:21 -07:00
|
|
|
|
}
|