LiveTvService.cs 57 KB

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