LiveTvService.cs 57 KB

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