LiveTvService.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Common.Net;
  3. using MediaBrowser.Controller.Dto;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Controller.LiveTv;
  6. using MediaBrowser.Controller.Net;
  7. using MediaBrowser.Model.Dto;
  8. using MediaBrowser.Model.Entities;
  9. using MediaBrowser.Model.LiveTv;
  10. using MediaBrowser.Model.Querying;
  11. using ServiceStack;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Globalization;
  15. using System.Linq;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. namespace MediaBrowser.Api.LiveTv
  19. {
  20. /// <summary>
  21. /// This is insecure right now to avoid windows phone refactoring
  22. /// </summary>
  23. [Route("/LiveTv/Info", "GET", Summary = "Gets available live tv services.")]
  24. [Authenticated]
  25. public class GetLiveTvInfo : IReturn<LiveTvInfo>
  26. {
  27. }
  28. [Route("/LiveTv/Channels", "GET", Summary = "Gets available live tv channels.")]
  29. [Authenticated]
  30. public class GetChannels : IReturn<QueryResult<ChannelInfoDto>>, IHasDtoOptions
  31. {
  32. [ApiMember(Name = "Type", Description = "Optional filter by channel type.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  33. public ChannelType? Type { get; set; }
  34. [ApiMember(Name = "UserId", Description = "Optional filter by user and attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  35. public string UserId { get; set; }
  36. /// <summary>
  37. /// Skips over a given number of items within the results. Use for paging.
  38. /// </summary>
  39. /// <value>The start index.</value>
  40. [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")]
  41. public int? StartIndex { get; set; }
  42. /// <summary>
  43. /// The maximum number of items to return
  44. /// </summary>
  45. /// <value>The limit.</value>
  46. [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  47. public int? Limit { get; set; }
  48. [ApiMember(Name = "IsFavorite", Description = "Filter by channels that are favorites, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  49. public bool? IsFavorite { get; set; }
  50. [ApiMember(Name = "IsLiked", Description = "Filter by channels that are liked, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  51. public bool? IsLiked { get; set; }
  52. [ApiMember(Name = "IsDisliked", Description = "Filter by channels that are disliked, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  53. public bool? IsDisliked { get; set; }
  54. [ApiMember(Name = "EnableFavoriteSorting", Description = "Incorporate favorite and like status into channel sorting.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  55. public bool EnableFavoriteSorting { get; set; }
  56. [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
  57. public bool? EnableImages { get; set; }
  58. [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  59. public int? ImageTypeLimit { get; set; }
  60. [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  61. public string EnableImageTypes { get; set; }
  62. /// <summary>
  63. /// Fields to return within the items, in addition to basic information
  64. /// </summary>
  65. /// <value>The fields.</value>
  66. [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  67. public string Fields { get; set; }
  68. [ApiMember(Name = "AddCurrentProgram", Description = "Optional. Adds current program info to each channel", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  69. public bool AddCurrentProgram { get; set; }
  70. public GetChannels()
  71. {
  72. AddCurrentProgram = true;
  73. }
  74. }
  75. [Route("/LiveTv/Channels/{Id}", "GET", Summary = "Gets a live tv channel")]
  76. [Authenticated]
  77. public class GetChannel : IReturn<ChannelInfoDto>
  78. {
  79. /// <summary>
  80. /// Gets or sets the id.
  81. /// </summary>
  82. /// <value>The id.</value>
  83. [ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  84. public string Id { get; set; }
  85. [ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  86. public string UserId { get; set; }
  87. }
  88. [Route("/LiveTv/Recordings", "GET", Summary = "Gets live tv recordings")]
  89. [Authenticated]
  90. public class GetRecordings : IReturn<QueryResult<BaseItemDto>>, IHasDtoOptions
  91. {
  92. [ApiMember(Name = "ChannelId", Description = "Optional filter by channel id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  93. public string ChannelId { get; set; }
  94. [ApiMember(Name = "UserId", Description = "Optional filter by user and attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  95. public string UserId { get; set; }
  96. [ApiMember(Name = "GroupId", Description = "Optional filter by recording group.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  97. public string GroupId { get; set; }
  98. [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")]
  99. public int? StartIndex { get; set; }
  100. [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  101. public int? Limit { get; set; }
  102. [ApiMember(Name = "Status", Description = "Optional filter by recording status.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  103. public RecordingStatus? Status { get; set; }
  104. [ApiMember(Name = "Status", Description = "Optional filter by recordings that are in progress, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  105. public bool? IsInProgress { get; set; }
  106. [ApiMember(Name = "SeriesTimerId", Description = "Optional filter by recordings belonging to a series timer", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  107. public string SeriesTimerId { get; set; }
  108. [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
  109. public bool? EnableImages { get; set; }
  110. [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  111. public int? ImageTypeLimit { get; set; }
  112. [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  113. public string EnableImageTypes { get; set; }
  114. /// <summary>
  115. /// Fields to return within the items, in addition to basic information
  116. /// </summary>
  117. /// <value>The fields.</value>
  118. [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  119. public string Fields { get; set; }
  120. }
  121. [Route("/LiveTv/Recordings/Groups", "GET", Summary = "Gets live tv recording groups")]
  122. [Authenticated]
  123. public class GetRecordingGroups : IReturn<QueryResult<BaseItemDto>>
  124. {
  125. [ApiMember(Name = "UserId", Description = "Optional filter by user and attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  126. public string UserId { get; set; }
  127. }
  128. [Route("/LiveTv/Recordings/{Id}", "GET", Summary = "Gets a live tv recording")]
  129. [Authenticated]
  130. public class GetRecording : IReturn<BaseItemDto>
  131. {
  132. [ApiMember(Name = "Id", Description = "Recording Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  133. public string Id { get; set; }
  134. [ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  135. public string UserId { get; set; }
  136. }
  137. [Route("/LiveTv/Tuners/{Id}/Reset", "POST", Summary = "Resets a tv tuner")]
  138. [Authenticated]
  139. public class ResetTuner : IReturnVoid
  140. {
  141. [ApiMember(Name = "Id", Description = "Tuner Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  142. public string Id { get; set; }
  143. }
  144. [Route("/LiveTv/Timers/{Id}", "GET", Summary = "Gets a live tv timer")]
  145. [Authenticated]
  146. public class GetTimer : IReturn<TimerInfoDto>
  147. {
  148. [ApiMember(Name = "Id", Description = "Timer Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  149. public string Id { get; set; }
  150. }
  151. [Route("/LiveTv/Timers/Defaults", "GET", Summary = "Gets default values for a new timer")]
  152. [Authenticated]
  153. public class GetDefaultTimer : IReturn<SeriesTimerInfoDto>
  154. {
  155. [ApiMember(Name = "ProgramId", Description = "Optional, to attach default values based on a program.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  156. public string ProgramId { get; set; }
  157. }
  158. [Route("/LiveTv/Timers", "GET", Summary = "Gets live tv timers")]
  159. [Authenticated]
  160. public class GetTimers : IReturn<QueryResult<TimerInfoDto>>
  161. {
  162. [ApiMember(Name = "ChannelId", Description = "Optional filter by channel id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  163. public string ChannelId { get; set; }
  164. [ApiMember(Name = "SeriesTimerId", Description = "Optional filter by timers belonging to a series timer", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  165. public string SeriesTimerId { get; set; }
  166. public bool? IsActive { get; set; }
  167. }
  168. [Route("/LiveTv/Programs", "GET,POST", Summary = "Gets available live tv epgs..")]
  169. [Authenticated]
  170. public class GetPrograms : IReturn<QueryResult<BaseItemDto>>, IHasDtoOptions
  171. {
  172. [ApiMember(Name = "ChannelIds", Description = "The channels to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  173. public string ChannelIds { get; set; }
  174. [ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  175. public string UserId { get; set; }
  176. [ApiMember(Name = "MinStartDate", Description = "Optional. The minimum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  177. public string MinStartDate { get; set; }
  178. [ApiMember(Name = "HasAired", Description = "Optional. Filter by programs that have completed airing, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  179. public bool? HasAired { get; set; }
  180. [ApiMember(Name = "MaxStartDate", Description = "Optional. The maximum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  181. public string MaxStartDate { get; set; }
  182. [ApiMember(Name = "MinEndDate", Description = "Optional. The minimum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  183. public string MinEndDate { get; set; }
  184. [ApiMember(Name = "MaxEndDate", Description = "Optional. The maximum premiere date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  185. public string MaxEndDate { get; set; }
  186. [ApiMember(Name = "IsMovie", Description = "Optional filter for movies.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
  187. public bool? IsMovie { get; set; }
  188. [ApiMember(Name = "IsKids", Description = "Optional filter for kids.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
  189. public bool? IsKids { get; set; }
  190. [ApiMember(Name = "IsSports", Description = "Optional filter for sports.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
  191. public bool? IsSports { get; set; }
  192. [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")]
  193. public int? StartIndex { get; set; }
  194. [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  195. public int? Limit { get; set; }
  196. [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)]
  197. public string SortBy { get; set; }
  198. [ApiMember(Name = "SortOrder", Description = "Sort Order - Ascending,Descending", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  199. public SortOrder? SortOrder { get; set; }
  200. [ApiMember(Name = "Genres", Description = "The genres to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  201. public string Genres { get; set; }
  202. [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
  203. public bool? EnableImages { get; set; }
  204. public bool EnableTotalRecordCount { get; set; }
  205. [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  206. public int? ImageTypeLimit { get; set; }
  207. [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  208. public string EnableImageTypes { get; set; }
  209. /// <summary>
  210. /// Fields to return within the items, in addition to basic information
  211. /// </summary>
  212. /// <value>The fields.</value>
  213. [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  214. public string Fields { get; set; }
  215. public GetPrograms()
  216. {
  217. EnableTotalRecordCount = true;
  218. }
  219. }
  220. [Route("/LiveTv/Programs/Recommended", "GET", Summary = "Gets available live tv epgs..")]
  221. [Authenticated]
  222. public class GetRecommendedPrograms : IReturn<QueryResult<BaseItemDto>>, IHasDtoOptions
  223. {
  224. public bool EnableTotalRecordCount { get; set; }
  225. public GetRecommendedPrograms()
  226. {
  227. EnableTotalRecordCount = true;
  228. }
  229. [ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  230. public string UserId { get; set; }
  231. [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  232. public int? Limit { get; set; }
  233. [ApiMember(Name = "IsAiring", Description = "Optional. Filter by programs that are currently airing, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  234. public bool? IsAiring { get; set; }
  235. [ApiMember(Name = "HasAired", Description = "Optional. Filter by programs that have completed airing, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  236. public bool? HasAired { get; set; }
  237. [ApiMember(Name = "IsSports", Description = "Optional filter for sports.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
  238. public bool? IsSports { get; set; }
  239. [ApiMember(Name = "IsMovie", Description = "Optional filter for movies.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  240. public bool? IsMovie { get; set; }
  241. [ApiMember(Name = "IsKids", Description = "Optional filter for kids.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  242. public bool? IsKids { get; set; }
  243. [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
  244. public bool? EnableImages { get; set; }
  245. [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  246. public int? ImageTypeLimit { get; set; }
  247. [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  248. public string EnableImageTypes { get; set; }
  249. /// <summary>
  250. /// Fields to return within the items, in addition to basic information
  251. /// </summary>
  252. /// <value>The fields.</value>
  253. [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  254. public string Fields { get; set; }
  255. }
  256. [Route("/LiveTv/Programs/{Id}", "GET", Summary = "Gets a live tv program")]
  257. [Authenticated]
  258. public class GetProgram : IReturn<BaseItemDto>
  259. {
  260. [ApiMember(Name = "Id", Description = "Program Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  261. public string Id { get; set; }
  262. [ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  263. public string UserId { get; set; }
  264. }
  265. [Route("/LiveTv/Recordings/{Id}", "DELETE", Summary = "Deletes a live tv recording")]
  266. [Authenticated]
  267. public class DeleteRecording : IReturnVoid
  268. {
  269. [ApiMember(Name = "Id", Description = "Recording Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  270. public string Id { get; set; }
  271. }
  272. [Route("/LiveTv/Timers/{Id}", "DELETE", Summary = "Cancels a live tv timer")]
  273. [Authenticated]
  274. public class CancelTimer : IReturnVoid
  275. {
  276. [ApiMember(Name = "Id", Description = "Timer Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  277. public string Id { get; set; }
  278. }
  279. [Route("/LiveTv/Timers/{Id}", "POST", Summary = "Updates a live tv timer")]
  280. [Authenticated]
  281. public class UpdateTimer : TimerInfoDto, IReturnVoid
  282. {
  283. }
  284. [Route("/LiveTv/Timers", "POST", Summary = "Creates a live tv timer")]
  285. [Authenticated]
  286. public class CreateTimer : TimerInfoDto, IReturnVoid
  287. {
  288. }
  289. [Route("/LiveTv/SeriesTimers/{Id}", "GET", Summary = "Gets a live tv series timer")]
  290. [Authenticated]
  291. public class GetSeriesTimer : IReturn<TimerInfoDto>
  292. {
  293. [ApiMember(Name = "Id", Description = "Timer Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  294. public string Id { get; set; }
  295. }
  296. [Route("/LiveTv/SeriesTimers", "GET", Summary = "Gets live tv series timers")]
  297. [Authenticated]
  298. public class GetSeriesTimers : IReturn<QueryResult<SeriesTimerInfoDto>>
  299. {
  300. [ApiMember(Name = "SortBy", Description = "Optional. Sort by SortName or Priority", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  301. public string SortBy { get; set; }
  302. [ApiMember(Name = "SortOrder", Description = "Optional. Sort in Ascending or Descending order", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
  303. public SortOrder SortOrder { get; set; }
  304. }
  305. [Route("/LiveTv/SeriesTimers/{Id}", "DELETE", Summary = "Cancels a live tv series timer")]
  306. [Authenticated]
  307. public class CancelSeriesTimer : IReturnVoid
  308. {
  309. [ApiMember(Name = "Id", Description = "Timer Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  310. public string Id { get; set; }
  311. }
  312. [Route("/LiveTv/SeriesTimers/{Id}", "POST", Summary = "Updates a live tv series timer")]
  313. [Authenticated]
  314. public class UpdateSeriesTimer : SeriesTimerInfoDto, IReturnVoid
  315. {
  316. }
  317. [Route("/LiveTv/SeriesTimers", "POST", Summary = "Creates a live tv series timer")]
  318. [Authenticated]
  319. public class CreateSeriesTimer : SeriesTimerInfoDto, IReturnVoid
  320. {
  321. }
  322. [Route("/LiveTv/Recordings/Groups/{Id}", "GET", Summary = "Gets a recording group")]
  323. [Authenticated]
  324. public class GetRecordingGroup : IReturn<BaseItemDto>
  325. {
  326. [ApiMember(Name = "Id", Description = "Recording group Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  327. public string Id { get; set; }
  328. }
  329. [Route("/LiveTv/GuideInfo", "GET", Summary = "Gets guide info")]
  330. [Authenticated]
  331. public class GetGuideInfo : IReturn<GuideInfo>
  332. {
  333. }
  334. [Route("/LiveTv/Folder", "GET", Summary = "Gets the users live tv folder, along with configured images")]
  335. [Authenticated]
  336. public class GetLiveTvFolder : IReturn<BaseItemDto>
  337. {
  338. [ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  339. public string UserId { get; set; }
  340. }
  341. [Route("/LiveTv/TunerHosts", "POST", Summary = "Adds a tuner host")]
  342. [Authenticated]
  343. public class AddTunerHost : TunerHostInfo, IReturn<TunerHostInfo>
  344. {
  345. }
  346. [Route("/LiveTv/TunerHosts", "DELETE", Summary = "Deletes a tuner host")]
  347. [Authenticated]
  348. public class DeleteTunerHost : IReturnVoid
  349. {
  350. [ApiMember(Name = "Id", Description = "Tuner host id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "DELETE")]
  351. public string Id { get; set; }
  352. }
  353. [Route("/LiveTv/ListingProviders/Default", "GET")]
  354. [Authenticated(AllowBeforeStartupWizard = true)]
  355. public class GetDefaultListingProvider : ListingsProviderInfo, IReturn<ListingsProviderInfo>
  356. {
  357. }
  358. [Route("/LiveTv/ListingProviders", "POST", Summary = "Adds a listing provider")]
  359. [Authenticated(AllowBeforeStartupWizard = true)]
  360. public class AddListingProvider : ListingsProviderInfo, IReturn<ListingsProviderInfo>
  361. {
  362. public bool ValidateLogin { get; set; }
  363. public bool ValidateListings { get; set; }
  364. }
  365. [Route("/LiveTv/ListingProviders", "DELETE", Summary = "Deletes a listing provider")]
  366. [Authenticated(AllowBeforeStartupWizard = true)]
  367. public class DeleteListingProvider : IReturnVoid
  368. {
  369. [ApiMember(Name = "Id", Description = "Provider id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "DELETE")]
  370. public string Id { get; set; }
  371. }
  372. [Route("/LiveTv/ListingProviders/Lineups", "GET", Summary = "Gets available lineups")]
  373. [Authenticated(AllowBeforeStartupWizard = true)]
  374. public class GetLineups : IReturn<List<NameIdPair>>
  375. {
  376. [ApiMember(Name = "Id", Description = "Provider id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  377. public string Id { get; set; }
  378. [ApiMember(Name = "Type", Description = "Provider Type", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  379. public string Type { get; set; }
  380. [ApiMember(Name = "Location", Description = "Location", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  381. public string Location { get; set; }
  382. [ApiMember(Name = "Country", Description = "Country", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  383. public string Country { get; set; }
  384. }
  385. [Route("/LiveTv/ListingProviders/SchedulesDirect/Countries", "GET", Summary = "Gets available lineups")]
  386. [Authenticated(AllowBeforeStartupWizard = true)]
  387. public class GetSchedulesDirectCountries
  388. {
  389. }
  390. [Route("/LiveTv/ChannelMappingOptions")]
  391. [Authenticated(AllowBeforeStartupWizard = true)]
  392. public class GetChannelMappingOptions
  393. {
  394. [ApiMember(Name = "Id", Description = "Provider id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
  395. public string ProviderId { get; set; }
  396. }
  397. [Route("/LiveTv/ChannelMappings")]
  398. [Authenticated(AllowBeforeStartupWizard = true)]
  399. public class SetChannelMapping
  400. {
  401. [ApiMember(Name = "Id", Description = "Provider id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
  402. public string ProviderId { get; set; }
  403. public string TunerChannelNumber { get; set; }
  404. public string ProviderChannelNumber { get; set; }
  405. }
  406. public class ChannelMappingOptions
  407. {
  408. public List<TunerChannelMapping> TunerChannels { get; set; }
  409. public List<NameIdPair> ProviderChannels { get; set; }
  410. public List<NameValuePair> Mappings { get; set; }
  411. public string ProviderName { get; set; }
  412. }
  413. public class TunerChannelMapping
  414. {
  415. public string Name { get; set; }
  416. public string Number { get; set; }
  417. public string ProviderChannelNumber { get; set; }
  418. public string ProviderChannelName { get; set; }
  419. }
  420. [Route("/LiveTv/Registration", "GET")]
  421. [Authenticated]
  422. public class GetLiveTvRegistrationInfo : IReturn<MBRegistrationRecord>
  423. {
  424. [ApiMember(Name = "ChannelId", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  425. public string ChannelId { get; set; }
  426. [ApiMember(Name = "ProgramId", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  427. public string ProgramId { get; set; }
  428. [ApiMember(Name = "Feature", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  429. public string Feature { get; set; }
  430. }
  431. [Route("/LiveTv/TunerHosts/Satip/IniMappings", "GET", Summary = "Gets available mappings")]
  432. [Authenticated(AllowBeforeStartupWizard = true)]
  433. public class GetSatIniMappings : IReturn<List<NameValuePair>>
  434. {
  435. }
  436. [Route("/LiveTv/TunerHosts/Satip/ChannelScan", "GET", Summary = "Scans for available channels")]
  437. [Authenticated(AllowBeforeStartupWizard = true)]
  438. public class GetSatChannnelScanResult : TunerHostInfo
  439. {
  440. }
  441. public class LiveTvService : BaseApiService
  442. {
  443. private readonly ILiveTvManager _liveTvManager;
  444. private readonly IUserManager _userManager;
  445. private readonly IConfigurationManager _config;
  446. private readonly IHttpClient _httpClient;
  447. private readonly ILibraryManager _libraryManager;
  448. private readonly IDtoService _dtoService;
  449. public LiveTvService(ILiveTvManager liveTvManager, IUserManager userManager, IConfigurationManager config, IHttpClient httpClient, ILibraryManager libraryManager, IDtoService dtoService)
  450. {
  451. _liveTvManager = liveTvManager;
  452. _userManager = userManager;
  453. _config = config;
  454. _httpClient = httpClient;
  455. _libraryManager = libraryManager;
  456. _dtoService = dtoService;
  457. }
  458. public object Get(GetDefaultListingProvider request)
  459. {
  460. return ToOptimizedResult(new ListingsProviderInfo());
  461. }
  462. public async Task<object> Get(GetSatChannnelScanResult request)
  463. {
  464. var result = await _liveTvManager.GetSatChannelScanResult(request, CancellationToken.None).ConfigureAwait(false);
  465. return ToOptimizedResult(result);
  466. }
  467. public async Task<object> Get(GetLiveTvRegistrationInfo request)
  468. {
  469. var result = await _liveTvManager.GetRegistrationInfo(request.ChannelId, request.ProgramId, request.Feature).ConfigureAwait(false);
  470. return ToOptimizedResult(result);
  471. }
  472. public async Task<object> Post(SetChannelMapping request)
  473. {
  474. var config = GetConfiguration();
  475. var listingsProviderInfo = config.ListingProviders.First(i => string.Equals(request.ProviderId, i.Id, StringComparison.OrdinalIgnoreCase));
  476. listingsProviderInfo.ChannelMappings = listingsProviderInfo.ChannelMappings.Where(i => !string.Equals(i.Name, request.TunerChannelNumber, StringComparison.OrdinalIgnoreCase)).ToArray();
  477. if (!string.Equals(request.TunerChannelNumber, request.ProviderChannelNumber, StringComparison.OrdinalIgnoreCase))
  478. {
  479. var list = listingsProviderInfo.ChannelMappings.ToList();
  480. list.Add(new NameValuePair
  481. {
  482. Name = request.TunerChannelNumber,
  483. Value = request.ProviderChannelNumber
  484. });
  485. listingsProviderInfo.ChannelMappings = list.ToArray();
  486. }
  487. UpdateConfiguration(config);
  488. var tunerChannels = await _liveTvManager.GetChannelsForListingsProvider(request.ProviderId, CancellationToken.None)
  489. .ConfigureAwait(false);
  490. var providerChannels = await _liveTvManager.GetChannelsFromListingsProviderData(request.ProviderId, CancellationToken.None)
  491. .ConfigureAwait(false);
  492. var mappings = listingsProviderInfo.ChannelMappings.ToList();
  493. var tunerChannelMappings =
  494. tunerChannels.Select(i => GetTunerChannelMapping(i, mappings, providerChannels)).ToList();
  495. return tunerChannelMappings.First(i => string.Equals(i.Number, request.TunerChannelNumber, StringComparison.OrdinalIgnoreCase));
  496. }
  497. public async Task<object> Get(GetChannelMappingOptions request)
  498. {
  499. var config = GetConfiguration();
  500. var listingsProviderInfo = config.ListingProviders.First(i => string.Equals(request.ProviderId, i.Id, StringComparison.OrdinalIgnoreCase));
  501. var listingsProviderName = _liveTvManager.ListingProviders.First(i => string.Equals(i.Type, listingsProviderInfo.Type, StringComparison.OrdinalIgnoreCase)).Name;
  502. var tunerChannels = await _liveTvManager.GetChannelsForListingsProvider(request.ProviderId, CancellationToken.None)
  503. .ConfigureAwait(false);
  504. var providerChannels = await _liveTvManager.GetChannelsFromListingsProviderData(request.ProviderId, CancellationToken.None)
  505. .ConfigureAwait(false);
  506. var mappings = listingsProviderInfo.ChannelMappings.ToList();
  507. var result = new ChannelMappingOptions
  508. {
  509. TunerChannels = tunerChannels.Select(i => GetTunerChannelMapping(i, mappings, providerChannels)).ToList(),
  510. ProviderChannels = providerChannels.Select(i => new NameIdPair
  511. {
  512. Name = i.Name,
  513. Id = i.Number
  514. }).ToList(),
  515. Mappings = mappings,
  516. ProviderName = listingsProviderName
  517. };
  518. return ToOptimizedResult(result);
  519. }
  520. private TunerChannelMapping GetTunerChannelMapping(ChannelInfo channel, List<NameValuePair> mappings, List<ChannelInfo> providerChannels)
  521. {
  522. var result = new TunerChannelMapping
  523. {
  524. Name = channel.Number + " " + channel.Name,
  525. Number = channel.Number
  526. };
  527. var mapping = mappings.FirstOrDefault(i => string.Equals(i.Name, channel.Number, StringComparison.OrdinalIgnoreCase));
  528. var providerChannelNumber = channel.Number;
  529. if (mapping != null)
  530. {
  531. providerChannelNumber = mapping.Value;
  532. }
  533. var providerChannel = providerChannels.FirstOrDefault(i => string.Equals(i.Number, providerChannelNumber, StringComparison.OrdinalIgnoreCase));
  534. if (providerChannel != null)
  535. {
  536. result.ProviderChannelNumber = providerChannel.Number;
  537. result.ProviderChannelName = providerChannel.Name;
  538. }
  539. return result;
  540. }
  541. public object Get(GetSatIniMappings request)
  542. {
  543. return ToOptimizedResult(_liveTvManager.GetSatIniMappings());
  544. }
  545. public async Task<object> Get(GetSchedulesDirectCountries request)
  546. {
  547. // https://json.schedulesdirect.org/20141201/available/countries
  548. var response = await _httpClient.Get(new HttpRequestOptions
  549. {
  550. Url = "https://json.schedulesdirect.org/20141201/available/countries"
  551. }).ConfigureAwait(false);
  552. return ResultFactory.GetResult(response, "application/json");
  553. }
  554. private void AssertUserCanManageLiveTv()
  555. {
  556. var user = SessionContext.GetUser(Request).Result;
  557. if (user == null)
  558. {
  559. throw new SecurityException("Anonymous live tv management is not allowed.");
  560. }
  561. if (!user.Policy.EnableLiveTvManagement)
  562. {
  563. throw new SecurityException("The current user does not have permission to manage live tv.");
  564. }
  565. }
  566. public async Task<object> Post(AddListingProvider request)
  567. {
  568. var result = await _liveTvManager.SaveListingProvider(request, request.ValidateLogin, request.ValidateListings).ConfigureAwait(false);
  569. return ToOptimizedResult(result);
  570. }
  571. public void Delete(DeleteListingProvider request)
  572. {
  573. var config = GetConfiguration();
  574. config.ListingProviders = config.ListingProviders.Where(i => !string.Equals(request.Id, i.Id, StringComparison.OrdinalIgnoreCase)).ToList();
  575. _config.SaveConfiguration("livetv", config);
  576. }
  577. public async Task<object> Post(AddTunerHost request)
  578. {
  579. var result = await _liveTvManager.SaveTunerHost(request).ConfigureAwait(false);
  580. return ToOptimizedResult(result);
  581. }
  582. public void Delete(DeleteTunerHost request)
  583. {
  584. var config = GetConfiguration();
  585. config.TunerHosts = config.TunerHosts.Where(i => !string.Equals(request.Id, i.Id, StringComparison.OrdinalIgnoreCase)).ToList();
  586. _config.SaveConfiguration("livetv", config);
  587. }
  588. private LiveTvOptions GetConfiguration()
  589. {
  590. return _config.GetConfiguration<LiveTvOptions>("livetv");
  591. }
  592. private void UpdateConfiguration(LiveTvOptions options)
  593. {
  594. _config.SaveConfiguration("livetv", options);
  595. }
  596. public async Task<object> Get(GetLineups request)
  597. {
  598. var info = await _liveTvManager.GetLineups(request.Type, request.Id, request.Country, request.Location).ConfigureAwait(false);
  599. return ToOptimizedSerializedResultUsingCache(info);
  600. }
  601. public async Task<object> Get(GetLiveTvInfo request)
  602. {
  603. var info = await _liveTvManager.GetLiveTvInfo(CancellationToken.None).ConfigureAwait(false);
  604. return ToOptimizedSerializedResultUsingCache(info);
  605. }
  606. public async Task<object> Get(GetChannels request)
  607. {
  608. var channelResult = await _liveTvManager.GetInternalChannels(new LiveTvChannelQuery
  609. {
  610. ChannelType = request.Type,
  611. UserId = request.UserId,
  612. StartIndex = request.StartIndex,
  613. Limit = request.Limit,
  614. IsFavorite = request.IsFavorite,
  615. IsLiked = request.IsLiked,
  616. IsDisliked = request.IsDisliked,
  617. EnableFavoriteSorting = request.EnableFavoriteSorting,
  618. AddCurrentProgram = request.AddCurrentProgram
  619. }, CancellationToken.None).ConfigureAwait(false);
  620. var user = string.IsNullOrEmpty(request.UserId) ? null : _userManager.GetUserById(request.UserId);
  621. var returnArray = (await _dtoService.GetBaseItemDtos(channelResult.Items, GetDtoOptions(Request), user).ConfigureAwait(false)).ToArray();
  622. var result = new QueryResult<BaseItemDto>
  623. {
  624. Items = returnArray,
  625. TotalRecordCount = channelResult.TotalRecordCount
  626. };
  627. return ToOptimizedSerializedResultUsingCache(result);
  628. }
  629. public object Get(GetChannel request)
  630. {
  631. var user = string.IsNullOrWhiteSpace(request.UserId) ? null : _userManager.GetUserById(request.UserId);
  632. var item = _libraryManager.GetItemById(request.Id);
  633. var dtoOptions = GetDtoOptions(request);
  634. var result = _dtoService.GetBaseItemDto(item, dtoOptions, user);
  635. return ToOptimizedSerializedResultUsingCache(result);
  636. }
  637. public async Task<object> Get(GetLiveTvFolder request)
  638. {
  639. return ToOptimizedResult(await _liveTvManager.GetLiveTvFolder(request.UserId, CancellationToken.None).ConfigureAwait(false));
  640. }
  641. public async Task<object> Get(GetPrograms request)
  642. {
  643. var query = new ProgramQuery
  644. {
  645. ChannelIds = (request.ChannelIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray(),
  646. UserId = request.UserId,
  647. HasAired = request.HasAired,
  648. EnableTotalRecordCount = request.EnableTotalRecordCount
  649. };
  650. if (!string.IsNullOrEmpty(request.MinStartDate))
  651. {
  652. query.MinStartDate = DateTime.Parse(request.MinStartDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
  653. }
  654. if (!string.IsNullOrEmpty(request.MinEndDate))
  655. {
  656. query.MinEndDate = DateTime.Parse(request.MinEndDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
  657. }
  658. if (!string.IsNullOrEmpty(request.MaxStartDate))
  659. {
  660. query.MaxStartDate = DateTime.Parse(request.MaxStartDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
  661. }
  662. if (!string.IsNullOrEmpty(request.MaxEndDate))
  663. {
  664. query.MaxEndDate = DateTime.Parse(request.MaxEndDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
  665. }
  666. query.StartIndex = request.StartIndex;
  667. query.Limit = request.Limit;
  668. query.SortBy = (request.SortBy ?? String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  669. query.SortOrder = request.SortOrder;
  670. query.IsMovie = request.IsMovie;
  671. query.IsKids = request.IsKids;
  672. query.IsSports = request.IsSports;
  673. query.Genres = (request.Genres ?? String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  674. var result = await _liveTvManager.GetPrograms(query, GetDtoOptions(request), CancellationToken.None).ConfigureAwait(false);
  675. return ToOptimizedResult(result);
  676. }
  677. public async Task<object> Get(GetRecommendedPrograms request)
  678. {
  679. var query = new RecommendedProgramQuery
  680. {
  681. UserId = request.UserId,
  682. IsAiring = request.IsAiring,
  683. Limit = request.Limit,
  684. HasAired = request.HasAired,
  685. IsMovie = request.IsMovie,
  686. IsKids = request.IsKids,
  687. IsSports = request.IsSports,
  688. EnableTotalRecordCount = request.EnableTotalRecordCount
  689. };
  690. var result = await _liveTvManager.GetRecommendedPrograms(query, GetDtoOptions(request), CancellationToken.None).ConfigureAwait(false);
  691. return ToOptimizedResult(result);
  692. }
  693. public object Post(GetPrograms request)
  694. {
  695. return Get(request);
  696. }
  697. public async Task<object> Get(GetRecordings request)
  698. {
  699. var options = GetDtoOptions(request);
  700. options.DeviceId = AuthorizationContext.GetAuthorizationInfo(Request).DeviceId;
  701. var result = await _liveTvManager.GetRecordings(new RecordingQuery
  702. {
  703. ChannelId = request.ChannelId,
  704. UserId = request.UserId,
  705. GroupId = request.GroupId,
  706. StartIndex = request.StartIndex,
  707. Limit = request.Limit,
  708. Status = request.Status,
  709. SeriesTimerId = request.SeriesTimerId,
  710. IsInProgress = request.IsInProgress
  711. }, options, CancellationToken.None).ConfigureAwait(false);
  712. return ToOptimizedResult(result);
  713. }
  714. public async Task<object> Get(GetRecording request)
  715. {
  716. var user = string.IsNullOrEmpty(request.UserId) ? null : _userManager.GetUserById(request.UserId);
  717. var options = new DtoOptions();
  718. options.DeviceId = AuthorizationContext.GetAuthorizationInfo(Request).DeviceId;
  719. var result = await _liveTvManager.GetRecording(request.Id, options, CancellationToken.None, user).ConfigureAwait(false);
  720. return ToOptimizedSerializedResultUsingCache(result);
  721. }
  722. public async Task<object> Get(GetTimer request)
  723. {
  724. var result = await _liveTvManager.GetTimer(request.Id, CancellationToken.None).ConfigureAwait(false);
  725. return ToOptimizedSerializedResultUsingCache(result);
  726. }
  727. public async Task<object> Get(GetTimers request)
  728. {
  729. var result = await _liveTvManager.GetTimers(new TimerQuery
  730. {
  731. ChannelId = request.ChannelId,
  732. SeriesTimerId = request.SeriesTimerId,
  733. IsActive = request.IsActive
  734. }, CancellationToken.None).ConfigureAwait(false);
  735. return ToOptimizedSerializedResultUsingCache(result);
  736. }
  737. public void Delete(DeleteRecording request)
  738. {
  739. AssertUserCanManageLiveTv();
  740. var task = _liveTvManager.DeleteRecording(request.Id);
  741. Task.WaitAll(task);
  742. }
  743. public void Delete(CancelTimer request)
  744. {
  745. AssertUserCanManageLiveTv();
  746. var task = _liveTvManager.CancelTimer(request.Id);
  747. Task.WaitAll(task);
  748. }
  749. public void Post(UpdateTimer request)
  750. {
  751. AssertUserCanManageLiveTv();
  752. var task = _liveTvManager.UpdateTimer(request, CancellationToken.None);
  753. Task.WaitAll(task);
  754. }
  755. public async Task<object> Get(GetSeriesTimers request)
  756. {
  757. var result = await _liveTvManager.GetSeriesTimers(new SeriesTimerQuery
  758. {
  759. SortOrder = request.SortOrder,
  760. SortBy = request.SortBy
  761. }, CancellationToken.None).ConfigureAwait(false);
  762. return ToOptimizedSerializedResultUsingCache(result);
  763. }
  764. public async Task<object> Get(GetSeriesTimer request)
  765. {
  766. var result = await _liveTvManager.GetSeriesTimer(request.Id, CancellationToken.None).ConfigureAwait(false);
  767. return ToOptimizedSerializedResultUsingCache(result);
  768. }
  769. public void Delete(CancelSeriesTimer request)
  770. {
  771. AssertUserCanManageLiveTv();
  772. var task = _liveTvManager.CancelSeriesTimer(request.Id);
  773. Task.WaitAll(task);
  774. }
  775. public void Post(UpdateSeriesTimer request)
  776. {
  777. AssertUserCanManageLiveTv();
  778. var task = _liveTvManager.UpdateSeriesTimer(request, CancellationToken.None);
  779. Task.WaitAll(task);
  780. }
  781. public async Task<object> Get(GetDefaultTimer request)
  782. {
  783. if (string.IsNullOrEmpty(request.ProgramId))
  784. {
  785. var result = await _liveTvManager.GetNewTimerDefaults(CancellationToken.None).ConfigureAwait(false);
  786. return ToOptimizedSerializedResultUsingCache(result);
  787. }
  788. else
  789. {
  790. var result = await _liveTvManager.GetNewTimerDefaults(request.ProgramId, CancellationToken.None).ConfigureAwait(false);
  791. return ToOptimizedSerializedResultUsingCache(result);
  792. }
  793. }
  794. public async Task<object> Get(GetProgram request)
  795. {
  796. var user = string.IsNullOrEmpty(request.UserId) ? null : _userManager.GetUserById(request.UserId);
  797. var result = await _liveTvManager.GetProgram(request.Id, CancellationToken.None, user).ConfigureAwait(false);
  798. return ToOptimizedSerializedResultUsingCache(result);
  799. }
  800. public void Post(CreateSeriesTimer request)
  801. {
  802. AssertUserCanManageLiveTv();
  803. var task = _liveTvManager.CreateSeriesTimer(request, CancellationToken.None);
  804. Task.WaitAll(task);
  805. }
  806. public void Post(CreateTimer request)
  807. {
  808. AssertUserCanManageLiveTv();
  809. var task = _liveTvManager.CreateTimer(request, CancellationToken.None);
  810. Task.WaitAll(task);
  811. }
  812. public async Task<object> Get(GetRecordingGroups request)
  813. {
  814. var result = await _liveTvManager.GetRecordingGroups(new RecordingGroupQuery
  815. {
  816. UserId = request.UserId
  817. }, CancellationToken.None).ConfigureAwait(false);
  818. return ToOptimizedSerializedResultUsingCache(result);
  819. }
  820. public async Task<object> Get(GetRecordingGroup request)
  821. {
  822. var result = await _liveTvManager.GetRecordingGroups(new RecordingGroupQuery
  823. {
  824. }, CancellationToken.None).ConfigureAwait(false);
  825. var group = result.Items.FirstOrDefault(i => string.Equals(i.Id, request.Id, StringComparison.OrdinalIgnoreCase));
  826. return ToOptimizedSerializedResultUsingCache(group);
  827. }
  828. public object Get(GetGuideInfo request)
  829. {
  830. return ToOptimizedResult(_liveTvManager.GetGuideInfo());
  831. }
  832. public void Post(ResetTuner request)
  833. {
  834. AssertUserCanManageLiveTv();
  835. var task = _liveTvManager.ResetTuner(request.Id, CancellationToken.None);
  836. Task.WaitAll(task);
  837. }
  838. }
  839. }