2015-04-12 20:58:21 +02:00
using MediaBrowser.Controller.Dto ;
using MediaBrowser.Controller.Library ;
2013-12-15 02:17:57 +01:00
using MediaBrowser.Controller.LiveTv ;
2014-07-02 20:34:08 +02:00
using MediaBrowser.Controller.Net ;
2014-06-07 21:46:24 +02:00
using MediaBrowser.Model.Dto ;
2014-01-12 00:07:56 +01:00
using MediaBrowser.Model.Entities ;
2013-09-26 17:48:14 +02:00
using MediaBrowser.Model.LiveTv ;
2013-11-25 21:39:23 +01:00
using MediaBrowser.Model.Querying ;
2013-12-07 16:52:38 +01:00
using ServiceStack ;
2013-11-25 21:39:23 +01:00
using System ;
2014-01-10 14:52:01 +01:00
using System.Globalization ;
2013-09-26 17:48:14 +02:00
using System.Linq ;
2013-12-04 05:18:50 +01:00
using System.Threading ;
using System.Threading.Tasks ;
2013-09-26 17:48:14 +02:00
namespace MediaBrowser.Api.LiveTv
{
2014-10-16 05:26:39 +02:00
/// <summary>
/// This is insecure right now to avoid windows phone refactoring
/// </summary>
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Info", "GET", Summary = "Gets available live tv services.")]
2014-11-15 03:31:03 +01:00
[Authenticated]
2014-01-14 21:03:35 +01:00
public class GetLiveTvInfo : IReturn < LiveTvInfo >
2013-09-26 17:48:14 +02:00
{
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Channels", "GET", Summary = "Gets available live tv channels.")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-11-25 21:39:23 +01:00
public class GetChannels : IReturn < QueryResult < ChannelInfoDto > >
2013-09-26 17:48:14 +02:00
{
2013-11-24 21:51:45 +01:00
[ApiMember(Name = "Type", Description = "Optional filter by channel type.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
2014-06-01 06:11:04 +02:00
public ChannelType ? Type { get ; set ; }
2013-11-24 21:51:45 +01:00
2013-12-15 02:17:57 +01:00
[ApiMember(Name = "UserId", Description = "Optional filter by user and attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
2013-11-24 21:51:45 +01:00
public string UserId { get ; set ; }
2014-01-10 14:52:01 +01:00
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get ; set ; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get ; set ; }
2014-03-29 03:28:02 +01:00
[ApiMember(Name = "IsFavorite", Description = "Filter by channels that are favorites, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsFavorite { get ; set ; }
2014-05-24 01:58:28 +02:00
[ApiMember(Name = "IsLiked", Description = "Filter by channels that are liked, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsLiked { get ; set ; }
[ApiMember(Name = "IsDisliked", Description = "Filter by channels that are disliked, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsDisliked { get ; set ; }
2014-09-26 05:47:46 +02:00
[ApiMember(Name = "EnableFavoriteSorting", Description = "Incorporate favorite and like status into channel sorting.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool EnableFavoriteSorting { get ; set ; }
2013-09-26 17:48:14 +02:00
}
2013-10-31 21:45:58 +01:00
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Channels/{Id}", "GET", Summary = "Gets a live tv channel")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-11-24 22:30:38 +01:00
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-26 03:53:48 +01:00
2013-12-15 02:17:57 +01:00
[ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
2013-11-26 03:53:48 +01:00
public string UserId { get ; set ; }
2013-11-24 22:30:38 +01:00
}
2013-11-25 17:15:31 +01:00
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Recordings", "GET", Summary = "Gets live tv recordings")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-11-26 03:53:48 +01:00
public class GetRecordings : IReturn < QueryResult < RecordingInfoDto > >
{
2013-11-26 22:36:11 +01:00
[ApiMember(Name = "ChannelId", Description = "Optional filter by channel id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ChannelId { get ; set ; }
2013-12-15 02:17:57 +01:00
[ApiMember(Name = "UserId", Description = "Optional filter by user and attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get ; set ; }
2013-12-28 22:37:01 +01:00
[ApiMember(Name = "GroupId", Description = "Optional filter by recording group.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string GroupId { get ; set ; }
2013-12-29 00:09:24 +01:00
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get ; set ; }
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get ; set ; }
2014-01-01 19:26:31 +01:00
2014-01-15 16:18:31 +01:00
[ApiMember(Name = "Status", Description = "Optional filter by recording status.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public RecordingStatus ? Status { get ; set ; }
2014-01-08 06:25:21 +01:00
2014-01-15 16:18:31 +01:00
[ApiMember(Name = "Status", Description = "Optional filter by recordings that are in progress, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsInProgress { get ; set ; }
2014-01-16 18:23:30 +01:00
2014-01-08 06:25:21 +01:00
[ApiMember(Name = "SeriesTimerId", Description = "Optional filter by recordings belonging to a series timer", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string SeriesTimerId { get ; set ; }
2013-12-28 22:37:01 +01:00
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Recordings/Groups", "GET", Summary = "Gets live tv recording groups")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2014-01-02 04:53:27 +01:00
public class GetRecordingGroups : IReturn < QueryResult < RecordingGroupDto > >
2013-12-28 22:37:01 +01:00
{
[ApiMember(Name = "UserId", Description = "Optional filter by user and attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get ; set ; }
2013-11-26 03:53:48 +01:00
}
2013-11-26 22:36:11 +01:00
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Recordings/{Id}", "GET", Summary = "Gets a live tv recording")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-04 05:18:50 +01:00
public class GetRecording : IReturn < RecordingInfoDto >
{
[ApiMember(Name = "Id", Description = "Recording Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
2013-12-15 02:17:57 +01:00
[ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get ; set ; }
2013-12-04 05:18:50 +01:00
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Tuners/{Id}/Reset", "POST", Summary = "Resets a tv tuner")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2014-01-23 23:15:15 +01:00
public class ResetTuner : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Tuner Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Timers/{Id}", "GET", Summary = "Gets a live tv timer")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-04 05:18:50 +01:00
public class GetTimer : IReturn < TimerInfoDto >
{
[ApiMember(Name = "Id", Description = "Timer Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Timers/Defaults", "GET", Summary = "Gets default values for a new timer")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-18 06:44:46 +01:00
public class GetDefaultTimer : IReturn < SeriesTimerInfoDto >
2013-12-17 21:02:12 +01:00
{
2013-12-18 06:44:46 +01:00
[ApiMember(Name = "ProgramId", Description = "Optional, to attach default values based on a program.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ProgramId { get ; set ; }
2013-12-17 21:02:12 +01:00
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Timers", "GET", Summary = "Gets live tv timers")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-11-27 20:04:19 +01:00
public class GetTimers : IReturn < QueryResult < TimerInfoDto > >
{
[ApiMember(Name = "ChannelId", Description = "Optional filter by channel id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ChannelId { get ; set ; }
2014-01-08 06:25:21 +01:00
[ApiMember(Name = "SeriesTimerId", Description = "Optional filter by timers belonging to a series timer", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string SeriesTimerId { get ; set ; }
2013-11-27 20:04:19 +01:00
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Programs", "GET,POST", Summary = "Gets available live tv epgs..")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-11-25 21:39:23 +01:00
public class GetPrograms : IReturn < QueryResult < ProgramInfoDto > >
2013-11-02 22:38:21 +01:00
{
2014-01-10 14:52:01 +01:00
[ApiMember(Name = "ChannelIds", Description = "The channels to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
2013-11-15 22:31:44 +01:00
public string ChannelIds { get ; set ; }
2013-11-26 03:53:48 +01:00
2014-01-10 14:52:01 +01:00
[ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
2013-11-26 03:53:48 +01:00
public string UserId { get ; set ; }
2014-01-06 02:59:21 +01:00
2014-01-10 14:52:01 +01:00
[ApiMember(Name = "MinStartDate", Description = "Optional. The minimum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
2014-01-06 02:59:21 +01:00
public string MinStartDate { get ; set ; }
2015-03-07 04:53:31 +01:00
[ApiMember(Name = "HasAired", Description = "Optional. Filter by programs that have completed airing, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? HasAired { get ; set ; }
2014-01-10 14:52:01 +01:00
[ApiMember(Name = "MaxStartDate", Description = "Optional. The maximum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
2014-01-06 02:59:21 +01:00
public string MaxStartDate { get ; set ; }
2014-01-10 14:52:01 +01:00
[ApiMember(Name = "MinEndDate", Description = "Optional. The minimum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
2014-01-06 02:59:21 +01:00
public string MinEndDate { get ; set ; }
2014-01-10 14:52:01 +01:00
[ApiMember(Name = "MaxEndDate", Description = "Optional. The maximum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
2014-01-06 02:59:21 +01:00
public string MaxEndDate { get ; set ; }
2015-03-14 21:00:32 +01:00
[ApiMember(Name = "IsMovie", Description = "Optional filter for movies.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
public bool? IsMovie { get ; set ; }
2015-04-03 18:31:56 +02:00
[ApiMember(Name = "IsSports", Description = "Optional filter for sports.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
public bool? IsSports { get ; set ; }
2015-03-14 21:00:32 +01:00
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get ; set ; }
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get ; set ; }
[ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Name, StartDate", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string SortBy { get ; set ; }
[ApiMember(Name = "SortOrder", Description = "Sort Order - Ascending,Descending", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public SortOrder ? SortOrder { get ; set ; }
[ApiMember(Name = "Genres", Description = "The genres to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
public string Genres { get ; set ; }
2013-11-02 22:38:21 +01:00
}
2013-11-15 22:31:44 +01:00
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Programs/Recommended", "GET", Summary = "Gets available live tv epgs..")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2014-01-12 16:58:47 +01:00
public class GetRecommendedPrograms : IReturn < QueryResult < ProgramInfoDto > >
{
[ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
public string UserId { get ; set ; }
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get ; set ; }
[ApiMember(Name = "IsAiring", Description = "Optional. Filter by programs that are currently airing, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsAiring { get ; set ; }
[ApiMember(Name = "HasAired", Description = "Optional. Filter by programs that have completed airing, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? HasAired { get ; set ; }
2015-03-14 21:00:32 +01:00
2015-04-03 18:31:56 +02:00
[ApiMember(Name = "IsSports", Description = "Optional filter for sports.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
public bool? IsSports { get ; set ; }
2015-03-14 21:00:32 +01:00
[ApiMember(Name = "IsMovie", Description = "Optional filter for movies.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsMovie { get ; set ; }
2014-01-12 16:58:47 +01:00
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Programs/{Id}", "GET", Summary = "Gets a live tv program")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-17 21:02:12 +01:00
public class GetProgram : IReturn < ProgramInfoDto >
{
[ApiMember(Name = "Id", Description = "Program Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
[ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get ; set ; }
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Recordings/{Id}", "DELETE", Summary = "Deletes a live tv recording")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-11-29 17:58:24 +01:00
public class DeleteRecording : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Recording Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Timers/{Id}", "DELETE", Summary = "Cancels a live tv timer")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-11-29 17:58:24 +01:00
public class CancelTimer : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Timer Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
}
2013-12-15 02:17:57 +01:00
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Timers/{Id}", "POST", Summary = "Updates a live tv timer")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-15 02:17:57 +01:00
public class UpdateTimer : TimerInfoDto , IReturnVoid
{
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Timers", "POST", Summary = "Creates a live tv timer")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-17 21:02:12 +01:00
public class CreateTimer : TimerInfoDto , IReturnVoid
{
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/SeriesTimers/{Id}", "GET", Summary = "Gets a live tv series timer")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-15 02:17:57 +01:00
public class GetSeriesTimer : IReturn < TimerInfoDto >
{
[ApiMember(Name = "Id", Description = "Timer Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/SeriesTimers", "GET", Summary = "Gets live tv series timers")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-15 02:17:57 +01:00
public class GetSeriesTimers : IReturn < QueryResult < SeriesTimerInfoDto > >
{
2014-01-12 00:07:56 +01:00
[ApiMember(Name = "SortBy", Description = "Optional. Sort by SortName or Priority", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
public string SortBy { get ; set ; }
[ApiMember(Name = "SortOrder", Description = "Optional. Sort in Ascending or Descending order", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
public SortOrder SortOrder { get ; set ; }
2013-12-15 02:17:57 +01:00
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/SeriesTimers/{Id}", "DELETE", Summary = "Cancels a live tv series timer")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-15 15:19:24 +01:00
public class CancelSeriesTimer : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Timer Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/SeriesTimers/{Id}", "POST", Summary = "Updates a live tv series timer")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-15 15:19:24 +01:00
public class UpdateSeriesTimer : SeriesTimerInfoDto , IReturnVoid
{
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/SeriesTimers", "POST", Summary = "Creates a live tv series timer")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2013-12-17 21:02:12 +01:00
public class CreateSeriesTimer : SeriesTimerInfoDto , IReturnVoid
{
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/Recordings/Groups/{Id}", "GET", Summary = "Gets a recording group")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2014-01-02 04:53:27 +01:00
public class GetRecordingGroup : IReturn < RecordingGroupDto >
{
[ApiMember(Name = "Id", Description = "Recording group Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get ; set ; }
}
2014-03-26 17:10:46 +01:00
[Route("/LiveTv/GuideInfo", "GET", Summary = "Gets guide info")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2014-01-07 19:39:35 +01:00
public class GetGuideInfo : IReturn < GuideInfo >
{
}
2014-06-07 21:46:24 +02:00
[Route("/LiveTv/Folder", "GET", Summary = "Gets the users live tv folder, along with configured images")]
2014-10-15 14:46:24 +02:00
[Authenticated]
2014-06-07 21:46:24 +02:00
public class GetLiveTvFolder : IReturn < BaseItemDto >
{
[ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get ; set ; }
}
2013-09-26 17:48:14 +02:00
public class LiveTvService : BaseApiService
{
private readonly ILiveTvManager _liveTvManager ;
2013-12-15 02:17:57 +01:00
private readonly IUserManager _userManager ;
2013-09-26 17:48:14 +02:00
2013-12-15 02:17:57 +01:00
public LiveTvService ( ILiveTvManager liveTvManager , IUserManager userManager )
2013-09-26 17:48:14 +02:00
{
_liveTvManager = liveTvManager ;
2013-12-15 02:17:57 +01:00
_userManager = userManager ;
2013-09-26 17:48:14 +02:00
}
2014-01-13 21:31:09 +01:00
private void AssertUserCanManageLiveTv ( )
{
2015-03-09 20:40:03 +01:00
var user = SessionContext . GetUser ( Request ) . Result ;
2014-01-13 21:31:09 +01:00
if ( user = = null )
{
throw new UnauthorizedAccessException ( "Anonymous live tv management is not allowed." ) ;
}
2014-12-20 07:06:27 +01:00
if ( ! user . Policy . EnableLiveTvManagement )
2014-01-13 21:31:09 +01:00
{
throw new UnauthorizedAccessException ( "The current user does not have permission to manage live tv." ) ;
}
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetLiveTvInfo request )
2013-11-11 20:36:48 +01:00
{
2014-08-17 07:38:13 +02:00
var info = await _liveTvManager . GetLiveTvInfo ( CancellationToken . None ) . ConfigureAwait ( false ) ;
2014-01-23 22:09:00 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( info ) ;
2013-09-26 17:48:14 +02:00
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetChannels request )
2013-09-26 17:48:14 +02:00
{
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetChannels ( new LiveTvChannelQuery
2013-11-24 21:51:45 +01:00
{
ChannelType = request . Type ,
2014-01-10 14:52:01 +01:00
UserId = request . UserId ,
StartIndex = request . StartIndex ,
2014-03-29 03:28:02 +01:00
Limit = request . Limit ,
2014-05-24 01:58:28 +02:00
IsFavorite = request . IsFavorite ,
IsLiked = request . IsLiked ,
2014-09-26 05:47:46 +02:00
IsDisliked = request . IsDisliked ,
EnableFavoriteSorting = request . EnableFavoriteSorting
2013-09-26 17:48:14 +02:00
2014-08-17 07:38:13 +02:00
} , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-09-26 17:48:14 +02:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-09-26 17:48:14 +02:00
}
2013-10-31 21:45:58 +01:00
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetChannel request )
2013-11-24 22:30:38 +01:00
{
2014-09-14 17:10:51 +02:00
var user = string . IsNullOrEmpty ( request . UserId ) ? null : _userManager . GetUserById ( request . UserId ) ;
2013-12-15 02:17:57 +01:00
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetChannel ( request . Id , CancellationToken . None , user ) . ConfigureAwait ( false ) ;
2013-11-24 22:30:38 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-11-24 22:30:38 +01:00
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetLiveTvFolder request )
2014-06-07 21:46:24 +02:00
{
2014-08-17 07:38:13 +02:00
return ToOptimizedResult ( await _liveTvManager . GetLiveTvFolder ( request . UserId , CancellationToken . None ) . ConfigureAwait ( false ) ) ;
2014-06-07 21:46:24 +02:00
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetPrograms request )
2013-11-02 22:38:21 +01:00
{
2014-01-06 02:59:21 +01:00
var query = new ProgramQuery
2013-11-25 17:15:31 +01:00
{
2015-03-14 21:00:32 +01:00
ChannelIds = ( request . ChannelIds ? ? string . Empty ) . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) . ToArray ( ) ,
2015-03-07 04:53:31 +01:00
UserId = request . UserId ,
HasAired = request . HasAired
2014-01-06 02:59:21 +01:00
} ;
2013-11-26 22:36:11 +01:00
2014-01-06 02:59:21 +01:00
if ( ! string . IsNullOrEmpty ( request . MinStartDate ) )
{
2014-01-07 19:39:35 +01:00
query . MinStartDate = DateTime . Parse ( request . MinStartDate , null , DateTimeStyles . RoundtripKind ) . ToUniversalTime ( ) ;
2014-01-06 02:59:21 +01:00
}
if ( ! string . IsNullOrEmpty ( request . MinEndDate ) )
{
2014-01-07 19:39:35 +01:00
query . MinEndDate = DateTime . Parse ( request . MinEndDate , null , DateTimeStyles . RoundtripKind ) . ToUniversalTime ( ) ;
2014-01-06 02:59:21 +01:00
}
if ( ! string . IsNullOrEmpty ( request . MaxStartDate ) )
{
2014-01-07 19:39:35 +01:00
query . MaxStartDate = DateTime . Parse ( request . MaxStartDate , null , DateTimeStyles . RoundtripKind ) . ToUniversalTime ( ) ;
2014-01-06 02:59:21 +01:00
}
if ( ! string . IsNullOrEmpty ( request . MaxEndDate ) )
{
2014-01-07 19:39:35 +01:00
query . MaxEndDate = DateTime . Parse ( request . MaxEndDate , null , DateTimeStyles . RoundtripKind ) . ToUniversalTime ( ) ;
2014-01-06 02:59:21 +01:00
}
2015-03-14 21:00:32 +01:00
query . StartIndex = request . StartIndex ;
query . Limit = request . Limit ;
query . SortBy = ( request . SortBy ? ? String . Empty ) . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) ;
query . SortOrder = request . SortOrder ;
query . IsMovie = request . IsMovie ;
2015-04-03 18:31:56 +02:00
query . IsSports = request . IsSports ;
2015-03-14 21:00:32 +01:00
query . Genres = ( request . Genres ? ? String . Empty ) . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) ;
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetPrograms ( query , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-11-02 22:38:21 +01:00
2015-04-09 07:20:23 +02:00
return ToOptimizedResult ( result ) ;
2014-01-12 16:58:47 +01:00
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetRecommendedPrograms request )
2014-01-12 16:58:47 +01:00
{
var query = new RecommendedProgramQuery
{
UserId = request . UserId ,
IsAiring = request . IsAiring ,
Limit = request . Limit ,
2015-03-14 21:00:32 +01:00
HasAired = request . HasAired ,
2015-04-03 18:31:56 +02:00
IsMovie = request . IsMovie ,
IsSports = request . IsSports
2014-01-12 16:58:47 +01:00
} ;
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetRecommendedPrograms ( query , CancellationToken . None ) . ConfigureAwait ( false ) ;
2014-01-12 16:58:47 +01:00
2015-04-09 07:20:23 +02:00
return ToOptimizedResult ( result ) ;
2013-11-02 22:38:21 +01:00
}
2013-11-26 03:53:48 +01:00
2014-01-10 14:52:01 +01:00
public object Post ( GetPrograms request )
{
return Get ( request ) ;
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetRecordings request )
2013-11-26 03:53:48 +01:00
{
2015-04-12 20:58:21 +02:00
var options = new DtoOptions ( ) ;
options . DeviceId = AuthorizationContext . GetAuthorizationInfo ( Request ) . DeviceId ;
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetRecordings ( new RecordingQuery
2013-11-26 22:36:11 +01:00
{
2013-12-15 02:17:57 +01:00
ChannelId = request . ChannelId ,
2013-12-28 22:37:01 +01:00
UserId = request . UserId ,
2013-12-29 00:09:24 +01:00
GroupId = request . GroupId ,
StartIndex = request . StartIndex ,
2014-01-01 19:26:31 +01:00
Limit = request . Limit ,
2014-01-15 16:18:31 +01:00
Status = request . Status ,
SeriesTimerId = request . SeriesTimerId ,
IsInProgress = request . IsInProgress
2013-11-26 22:36:11 +01:00
2015-04-12 20:58:21 +02:00
} , options , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-11-26 03:53:48 +01:00
2015-04-09 07:20:23 +02:00
return ToOptimizedResult ( result ) ;
2013-11-26 03:53:48 +01:00
}
2013-11-27 20:04:19 +01:00
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetRecording request )
2013-12-04 05:18:50 +01:00
{
2014-09-14 17:10:51 +02:00
var user = string . IsNullOrEmpty ( request . UserId ) ? null : _userManager . GetUserById ( request . UserId ) ;
2013-12-15 02:17:57 +01:00
2015-04-12 20:58:21 +02:00
var options = new DtoOptions ( ) ;
options . DeviceId = AuthorizationContext . GetAuthorizationInfo ( Request ) . DeviceId ;
var result = await _liveTvManager . GetRecording ( request . Id , options , CancellationToken . None , user ) . ConfigureAwait ( false ) ;
2013-12-04 05:18:50 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-12-04 05:18:50 +01:00
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetTimer request )
2013-12-04 05:18:50 +01:00
{
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetTimer ( request . Id , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-12-04 05:18:50 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-12-04 05:18:50 +01:00
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetTimers request )
2013-11-27 20:04:19 +01:00
{
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetTimers ( new TimerQuery
2013-11-27 20:04:19 +01:00
{
2014-01-08 06:25:21 +01:00
ChannelId = request . ChannelId ,
SeriesTimerId = request . SeriesTimerId
2013-11-27 20:04:19 +01:00
2014-08-17 07:38:13 +02:00
} , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-11-27 20:04:19 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-11-27 20:04:19 +01:00
}
2013-11-29 17:58:24 +01:00
public void Delete ( DeleteRecording request )
{
2014-01-13 21:31:09 +01:00
AssertUserCanManageLiveTv ( ) ;
2013-11-29 17:58:24 +01:00
var task = _liveTvManager . DeleteRecording ( request . Id ) ;
Task . WaitAll ( task ) ;
}
public void Delete ( CancelTimer request )
{
2014-01-13 21:31:09 +01:00
AssertUserCanManageLiveTv ( ) ;
2013-11-29 17:58:24 +01:00
var task = _liveTvManager . CancelTimer ( request . Id ) ;
Task . WaitAll ( task ) ;
}
2013-12-15 02:17:57 +01:00
public void Post ( UpdateTimer request )
{
2014-01-13 21:31:09 +01:00
AssertUserCanManageLiveTv ( ) ;
2013-12-15 02:17:57 +01:00
var task = _liveTvManager . UpdateTimer ( request , CancellationToken . None ) ;
Task . WaitAll ( task ) ;
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetSeriesTimers request )
2013-12-15 02:17:57 +01:00
{
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetSeriesTimers ( new SeriesTimerQuery
2013-12-17 21:02:12 +01:00
{
2014-01-12 00:07:56 +01:00
SortOrder = request . SortOrder ,
SortBy = request . SortBy
2013-12-15 02:17:57 +01:00
2014-08-17 07:38:13 +02:00
} , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-12-15 02:17:57 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-12-15 02:17:57 +01:00
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetSeriesTimer request )
2013-12-15 02:17:57 +01:00
{
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetSeriesTimer ( request . Id , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-12-15 02:17:57 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-12-15 02:17:57 +01:00
}
2013-12-15 15:19:24 +01:00
public void Delete ( CancelSeriesTimer request )
{
2014-01-13 21:31:09 +01:00
AssertUserCanManageLiveTv ( ) ;
2013-12-15 15:19:24 +01:00
var task = _liveTvManager . CancelSeriesTimer ( request . Id ) ;
Task . WaitAll ( task ) ;
}
public void Post ( UpdateSeriesTimer request )
{
2014-01-13 21:31:09 +01:00
AssertUserCanManageLiveTv ( ) ;
2013-12-15 15:19:24 +01:00
var task = _liveTvManager . UpdateSeriesTimer ( request , CancellationToken . None ) ;
Task . WaitAll ( task ) ;
}
2013-12-17 21:02:12 +01:00
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetDefaultTimer request )
2013-12-17 21:02:12 +01:00
{
2013-12-18 06:44:46 +01:00
if ( string . IsNullOrEmpty ( request . ProgramId ) )
{
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetNewTimerDefaults ( CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-12-17 21:02:12 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-12-18 06:44:46 +01:00
}
else
{
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetNewTimerDefaults ( request . ProgramId , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-12-18 06:44:46 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-12-18 06:44:46 +01:00
}
2013-12-17 21:02:12 +01:00
}
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetProgram request )
2013-12-17 21:02:12 +01:00
{
2014-09-14 17:10:51 +02:00
var user = string . IsNullOrEmpty ( request . UserId ) ? null : _userManager . GetUserById ( request . UserId ) ;
2013-12-17 21:02:12 +01:00
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetProgram ( request . Id , CancellationToken . None , user ) . ConfigureAwait ( false ) ;
2013-12-17 21:02:12 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-12-17 21:02:12 +01:00
}
public void Post ( CreateSeriesTimer request )
{
2014-01-13 21:31:09 +01:00
AssertUserCanManageLiveTv ( ) ;
2013-12-17 21:02:12 +01:00
var task = _liveTvManager . CreateSeriesTimer ( request , CancellationToken . None ) ;
Task . WaitAll ( task ) ;
}
public void Post ( CreateTimer request )
{
2014-01-13 21:31:09 +01:00
AssertUserCanManageLiveTv ( ) ;
2013-12-17 21:02:12 +01:00
var task = _liveTvManager . CreateTimer ( request , CancellationToken . None ) ;
Task . WaitAll ( task ) ;
}
2013-12-22 19:58:51 +01:00
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetRecordingGroups request )
2013-12-28 22:37:01 +01:00
{
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetRecordingGroups ( new RecordingGroupQuery
2013-12-28 22:37:01 +01:00
{
UserId = request . UserId
2014-08-17 07:38:13 +02:00
} , CancellationToken . None ) . ConfigureAwait ( false ) ;
2013-12-28 22:37:01 +01:00
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( result ) ;
2013-12-28 22:37:01 +01:00
}
2014-01-02 04:53:27 +01:00
2014-08-17 07:38:13 +02:00
public async Task < object > Get ( GetRecordingGroup request )
2014-01-02 04:53:27 +01:00
{
2014-08-17 07:38:13 +02:00
var result = await _liveTvManager . GetRecordingGroups ( new RecordingGroupQuery
2014-01-02 04:53:27 +01:00
{
2014-08-17 07:38:13 +02:00
} , CancellationToken . None ) . ConfigureAwait ( false ) ;
2014-01-02 04:53:27 +01:00
var group = result . Items . FirstOrDefault ( i = > string . Equals ( i . Id , request . Id , StringComparison . OrdinalIgnoreCase ) ) ;
2014-02-04 05:04:19 +01:00
return ToOptimizedSerializedResultUsingCache ( group ) ;
2014-01-02 04:53:27 +01:00
}
2014-01-07 19:39:35 +01:00
public object Get ( GetGuideInfo request )
{
return ToOptimizedResult ( _liveTvManager . GetGuideInfo ( ) ) ;
}
2014-01-23 23:15:15 +01:00
public void Post ( ResetTuner request )
{
AssertUserCanManageLiveTv ( ) ;
var task = _liveTvManager . ResetTuner ( request . Id , CancellationToken . None ) ;
Task . WaitAll ( task ) ;
}
2013-09-26 17:48:14 +02:00
}
2013-11-02 22:38:21 +01:00
}