SchedulesDirect.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. using MediaBrowser.Common;
  2. using MediaBrowser.Common.Net;
  3. using MediaBrowser.Controller.LiveTv;
  4. using MediaBrowser.Model.Dto;
  5. using MediaBrowser.Model.LiveTv;
  6. using MediaBrowser.Model.Logging;
  7. using MediaBrowser.Model.Serialization;
  8. using System;
  9. using System.Collections.Concurrent;
  10. using System.Collections.Generic;
  11. using System.Globalization;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. namespace MediaBrowser.Server.Implementations.LiveTv.Listings
  17. {
  18. public class SchedulesDirect : IListingsProvider
  19. {
  20. private readonly ILogger _logger;
  21. private readonly IJsonSerializer _jsonSerializer;
  22. private readonly IHttpClient _httpClient;
  23. private readonly SemaphoreSlim _tokenSemaphore = new SemaphoreSlim(1, 1);
  24. private readonly IApplicationHost _appHost;
  25. private const string ApiUrl = "https://json.schedulesdirect.org/20141201";
  26. private readonly ConcurrentDictionary<string, ScheduleDirect.Station> _channelPair =
  27. new ConcurrentDictionary<string, ScheduleDirect.Station>();
  28. public SchedulesDirect(ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient, IApplicationHost appHost)
  29. {
  30. _logger = logger;
  31. _jsonSerializer = jsonSerializer;
  32. _httpClient = httpClient;
  33. _appHost = appHost;
  34. }
  35. private string UserAgent
  36. {
  37. get { return "Emby/" + _appHost.ApplicationVersion; }
  38. }
  39. private List<string> GetScheduleRequestDates(DateTime startDateUtc, DateTime endDateUtc)
  40. {
  41. List<string> dates = new List<string>();
  42. var start = new List<DateTime> { startDateUtc, startDateUtc.ToLocalTime() }.Min();
  43. var end = new List<DateTime> { endDateUtc, endDateUtc.ToLocalTime() }.Max();
  44. while (start.DayOfYear <= end.Day)
  45. {
  46. dates.Add(start.ToString("yyyy-MM-dd"));
  47. start = start.AddDays(1);
  48. }
  49. return dates;
  50. }
  51. public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
  52. {
  53. List<ProgramInfo> programsInfo = new List<ProgramInfo>();
  54. var token = await GetToken(info, cancellationToken);
  55. if (string.IsNullOrWhiteSpace(token))
  56. {
  57. return programsInfo;
  58. }
  59. if (string.IsNullOrWhiteSpace(info.ListingsId))
  60. {
  61. return programsInfo;
  62. }
  63. var httpOptions = new HttpRequestOptions()
  64. {
  65. Url = ApiUrl + "/schedules",
  66. UserAgent = UserAgent,
  67. CancellationToken = cancellationToken
  68. };
  69. httpOptions.RequestHeaders["token"] = token;
  70. var dates = GetScheduleRequestDates(startDateUtc, endDateUtc);
  71. ScheduleDirect.Station station = null;
  72. if (!_channelPair.TryGetValue(channelNumber, out station))
  73. {
  74. return programsInfo;
  75. }
  76. string stationID = station.stationID;
  77. _logger.Info("Channel Station ID is: " + stationID);
  78. List<ScheduleDirect.RequestScheduleForChannel> requestList =
  79. new List<ScheduleDirect.RequestScheduleForChannel>()
  80. {
  81. new ScheduleDirect.RequestScheduleForChannel()
  82. {
  83. stationID = stationID,
  84. date = dates
  85. }
  86. };
  87. var requestString = _jsonSerializer.SerializeToString(requestList);
  88. _logger.Debug("Request string for schedules is: " + requestString);
  89. httpOptions.RequestContent = requestString;
  90. using (var response = await _httpClient.Post(httpOptions))
  91. {
  92. StreamReader reader = new StreamReader(response.Content);
  93. string responseString = reader.ReadToEnd();
  94. var dailySchedules = _jsonSerializer.DeserializeFromString<List<ScheduleDirect.Day>>(responseString);
  95. _logger.Debug("Found " + dailySchedules.Count() + " programs on " + channelNumber + " ScheduleDirect");
  96. httpOptions = new HttpRequestOptions()
  97. {
  98. Url = ApiUrl + "/programs",
  99. UserAgent = UserAgent,
  100. CancellationToken = cancellationToken
  101. };
  102. httpOptions.RequestHeaders["token"] = token;
  103. List<string> programsID = new List<string>();
  104. programsID = dailySchedules.SelectMany(d => d.programs.Select(s => s.programID)).Distinct().ToList();
  105. var requestBody = "[\"" + string.Join("\", \"", programsID) + "\"]";
  106. httpOptions.RequestContent = requestBody;
  107. using (var innerResponse = await _httpClient.Post(httpOptions))
  108. {
  109. StreamReader innerReader = new StreamReader(innerResponse.Content);
  110. responseString = innerReader.ReadToEnd();
  111. var programDetails =
  112. _jsonSerializer.DeserializeFromString<List<ScheduleDirect.ProgramDetails>>(
  113. responseString);
  114. var programDict = programDetails.ToDictionary(p => p.programID, y => y);
  115. var images = await GetImageForPrograms(programDetails.Where(p => p.hasImageArtwork).Select(p => p.programID).ToList(), cancellationToken);
  116. var schedules = dailySchedules.SelectMany(d => d.programs);
  117. foreach (ScheduleDirect.Program schedule in schedules)
  118. {
  119. _logger.Debug("Proccesing Schedule for statio ID " + stationID +
  120. " which corresponds to channel " + channelNumber + " and program id " +
  121. schedule.programID + " which says it has images? " +
  122. programDict[schedule.programID].hasImageArtwork);
  123. var imageIndex = images.FindIndex(i => i.programID == schedule.programID.Substring(0, 10));
  124. if (imageIndex > -1)
  125. {
  126. programDict[schedule.programID].images = GetProgramLogo(ApiUrl, images[imageIndex]);
  127. }
  128. programsInfo.Add(GetProgram(channelNumber, schedule, programDict[schedule.programID]));
  129. }
  130. _logger.Info("Finished with EPGData");
  131. }
  132. }
  133. return programsInfo;
  134. }
  135. public async Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> channels,
  136. CancellationToken cancellationToken)
  137. {
  138. if (string.IsNullOrWhiteSpace(info.ListingsId))
  139. {
  140. throw new Exception("ListingsId required");
  141. }
  142. var token = await GetToken(info, cancellationToken);
  143. if (string.IsNullOrWhiteSpace(token))
  144. {
  145. throw new Exception("token required");
  146. }
  147. _channelPair.Clear();
  148. var httpOptions = new HttpRequestOptions()
  149. {
  150. Url = ApiUrl + "/lineups/" + info.ListingsId,
  151. UserAgent = UserAgent,
  152. CancellationToken = cancellationToken
  153. };
  154. httpOptions.RequestHeaders["token"] = token;
  155. using (var response = await _httpClient.Get(httpOptions))
  156. {
  157. var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Channel>(response);
  158. _logger.Info("Found " + root.map.Count() + " channels on the lineup on ScheduleDirect");
  159. _logger.Info("Mapping Stations to Channel");
  160. foreach (ScheduleDirect.Map map in root.map)
  161. {
  162. var channel = (map.channel ?? (map.atscMajor + "." + map.atscMinor)).TrimStart('0');
  163. _logger.Debug("Found channel: " + channel + " in Schedules Direct");
  164. var schChannel = root.stations.FirstOrDefault(item => item.stationID == map.stationID);
  165. if (!_channelPair.ContainsKey(channel) && channel != "0.0" && schChannel != null)
  166. {
  167. _channelPair.TryAdd(channel, schChannel);
  168. }
  169. }
  170. _logger.Info("Added " + _channelPair.Count() + " channels to the dictionary");
  171. foreach (ChannelInfo channel in channels)
  172. {
  173. // Helper.logger.Info("Modifyin channel " + channel.Number);
  174. if (_channelPair.ContainsKey(channel.Number))
  175. {
  176. string channelName;
  177. if (_channelPair[channel.Number].logo != null)
  178. {
  179. channel.ImageUrl = _channelPair[channel.Number].logo.URL;
  180. channel.HasImage = true;
  181. }
  182. if (_channelPair[channel.Number].affiliate != null)
  183. {
  184. channelName = _channelPair[channel.Number].affiliate;
  185. }
  186. else
  187. {
  188. channelName = _channelPair[channel.Number].name;
  189. }
  190. channel.Name = channelName;
  191. }
  192. else
  193. {
  194. _logger.Info("Schedules Direct doesnt have data for channel: " + channel.Number + " " +
  195. channel.Name);
  196. }
  197. }
  198. }
  199. }
  200. private ProgramInfo GetProgram(string channel, ScheduleDirect.Program programInfo,
  201. ScheduleDirect.ProgramDetails details)
  202. {
  203. //_logger.Debug("Show type is: " + (details.showType ?? "No ShowType"));
  204. DateTime startAt = DateTime.ParseExact(programInfo.airDateTime, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'",
  205. CultureInfo.InvariantCulture);
  206. DateTime endAt = startAt.AddSeconds(programInfo.duration);
  207. ProgramAudio audioType = ProgramAudio.Stereo;
  208. bool hdtv = false;
  209. bool repeat = (programInfo.@new == null);
  210. string newID = programInfo.programID + "T" + startAt.Ticks + "C" + channel;
  211. if (programInfo.audioProperties != null)
  212. {
  213. if (programInfo.audioProperties.Exists(item => string.Equals(item, "dd 5.1", StringComparison.OrdinalIgnoreCase)))
  214. {
  215. audioType = ProgramAudio.DolbyDigital;
  216. }
  217. else if (programInfo.audioProperties.Exists(item => string.Equals(item, "dd", StringComparison.OrdinalIgnoreCase)))
  218. {
  219. audioType = ProgramAudio.DolbyDigital;
  220. }
  221. else if (programInfo.audioProperties.Exists(item => string.Equals(item, "stereo", StringComparison.OrdinalIgnoreCase)))
  222. {
  223. audioType = ProgramAudio.Stereo;
  224. }
  225. else
  226. {
  227. audioType = ProgramAudio.Mono;
  228. }
  229. }
  230. if ((programInfo.videoProperties != null))
  231. {
  232. hdtv = programInfo.videoProperties.Exists(item => item == "hdtv");
  233. }
  234. string desc = "";
  235. if (details.descriptions != null)
  236. {
  237. if (details.descriptions.description1000 != null)
  238. {
  239. desc = details.descriptions.description1000[0].description;
  240. }
  241. else if (details.descriptions.description100 != null)
  242. {
  243. desc = details.descriptions.description100[0].description;
  244. }
  245. }
  246. ScheduleDirect.Gracenote gracenote;
  247. string episodeTitle = null;
  248. if (details.metadata != null)
  249. {
  250. gracenote = details.metadata.Find(x => x.Gracenote != null).Gracenote;
  251. if ((details.showType ?? "No ShowType") == "Series")
  252. {
  253. episodeTitle = "Season: " + gracenote.season + " Episode: " + gracenote.episode;
  254. }
  255. }
  256. if (details.episodeTitle150 != null)
  257. {
  258. episodeTitle = ((episodeTitle ?? string.Empty) + " " + details.episodeTitle150).Trim();
  259. }
  260. var imageLink = "";
  261. if (details.hasImageArtwork)
  262. {
  263. imageLink = details.images;
  264. }
  265. var info = new ProgramInfo
  266. {
  267. ChannelId = channel,
  268. Id = newID,
  269. Overview = desc,
  270. StartDate = startAt,
  271. EndDate = endAt,
  272. Name = details.titles[0].title120 ?? "Unkown",
  273. OfficialRating = "0",
  274. CommunityRating = null,
  275. EpisodeTitle = episodeTitle,
  276. Audio = audioType,
  277. IsHD = hdtv,
  278. IsRepeat = repeat,
  279. IsSeries =
  280. ((details.showType ?? "No ShowType") == "Series") ||
  281. (details.showType ?? "No ShowType") == "Miniseries",
  282. ImageUrl = imageLink,
  283. HasImage = details.hasImageArtwork,
  284. IsNews = false,
  285. IsKids = false,
  286. IsSports =
  287. ((details.showType ?? "No ShowType") == "Sports non-event") ||
  288. (details.showType ?? "No ShowType") == "Sports event",
  289. IsLive = false,
  290. IsMovie =
  291. (details.showType ?? "No ShowType") == "Feature Film" ||
  292. (details.showType ?? "No ShowType") == "TV Movie" ||
  293. (details.showType ?? "No ShowType") == "Short Film",
  294. IsPremiere = false,
  295. };
  296. if (!string.IsNullOrWhiteSpace(details.originalAirDate))
  297. {
  298. info.OriginalAirDate = DateTime.Parse(details.originalAirDate);
  299. }
  300. if (details.genres != null)
  301. {
  302. info.Genres = details.genres.Where(g => !string.IsNullOrWhiteSpace(g)).ToList();
  303. info.IsNews = details.genres.Contains("news", StringComparer.OrdinalIgnoreCase);
  304. info.IsKids = false;
  305. }
  306. return info;
  307. }
  308. private string GetProgramLogo(string apiUrl, ScheduleDirect.ShowImages images)
  309. {
  310. string url = "";
  311. if (images.data != null)
  312. {
  313. var smallImages = images.data.Where(i => i.size == "Sm").ToList();
  314. if (smallImages.Any())
  315. {
  316. images.data = smallImages;
  317. }
  318. var logoIndex = images.data.FindIndex(i => i.category == "Logo");
  319. if (logoIndex == -1)
  320. {
  321. logoIndex = 0;
  322. }
  323. if (images.data[logoIndex].uri.Contains("http"))
  324. {
  325. url = images.data[logoIndex].uri;
  326. }
  327. else
  328. {
  329. url = apiUrl + "/image/" + images.data[logoIndex].uri;
  330. }
  331. //_logger.Debug("URL for image is : " + url);
  332. }
  333. return url;
  334. }
  335. private async Task<List<ScheduleDirect.ShowImages>> GetImageForPrograms(List<string> programIds,
  336. CancellationToken cancellationToken)
  337. {
  338. var imageIdString = "[";
  339. programIds.ForEach(i =>
  340. {
  341. if (!imageIdString.Contains(i.Substring(0, 10)))
  342. {
  343. imageIdString += "\"" + i.Substring(0, 10) + "\",";
  344. }
  345. ;
  346. });
  347. imageIdString = imageIdString.TrimEnd(',') + "]";
  348. _logger.Debug("Json for show images = " + imageIdString);
  349. var httpOptions = new HttpRequestOptions()
  350. {
  351. Url = ApiUrl + "/metadata/programs",
  352. UserAgent = UserAgent,
  353. CancellationToken = cancellationToken,
  354. RequestContent = imageIdString
  355. };
  356. List<ScheduleDirect.ShowImages> images;
  357. using (var innerResponse2 = await _httpClient.Post(httpOptions))
  358. {
  359. images = _jsonSerializer.DeserializeFromStream<List<ScheduleDirect.ShowImages>>(
  360. innerResponse2.Content);
  361. }
  362. return images;
  363. }
  364. public async Task<List<NameIdPair>> GetHeadends(ListingsProviderInfo info, string country, string location, CancellationToken cancellationToken)
  365. {
  366. var token = await GetToken(info, cancellationToken);
  367. var lineups = new List<NameIdPair>();
  368. if (string.IsNullOrWhiteSpace(token))
  369. {
  370. return lineups;
  371. }
  372. _logger.Info("Headends on account ");
  373. var options = new HttpRequestOptions()
  374. {
  375. Url = ApiUrl + "/headends?country=" + country + "&postalcode=" + location,
  376. UserAgent = UserAgent,
  377. CancellationToken = cancellationToken
  378. };
  379. options.RequestHeaders["token"] = token;
  380. try
  381. {
  382. using (Stream responce = await _httpClient.Get(options).ConfigureAwait(false))
  383. {
  384. var root = _jsonSerializer.DeserializeFromStream<List<ScheduleDirect.Headends>>(responce);
  385. _logger.Info("Lineups on account ");
  386. if (root != null)
  387. {
  388. foreach (ScheduleDirect.Headends headend in root)
  389. {
  390. _logger.Info("Headend: " + headend.headend);
  391. foreach (ScheduleDirect.Lineup lineup in headend.lineups)
  392. {
  393. _logger.Info("Headend: " + lineup.uri.Substring(18));
  394. lineups.Add(new NameIdPair()
  395. {
  396. Name = string.IsNullOrWhiteSpace(lineup.name) ? lineup.lineup : lineup.name,
  397. Id = lineup.uri.Substring(18)
  398. });
  399. }
  400. }
  401. }
  402. else
  403. {
  404. _logger.Info("No lineups on account");
  405. }
  406. }
  407. }
  408. catch (Exception ex)
  409. {
  410. _logger.Error("Error getting headends", ex);
  411. }
  412. return lineups;
  413. }
  414. private readonly ConcurrentDictionary<string, NameValuePair> _tokens = new ConcurrentDictionary<string, NameValuePair>();
  415. private async Task<string> GetToken(ListingsProviderInfo info, CancellationToken cancellationToken)
  416. {
  417. var username = info.Username;
  418. // Reset the token if there's no username
  419. if (string.IsNullOrWhiteSpace(username))
  420. {
  421. return null;
  422. }
  423. var password = info.Password;
  424. if (string.IsNullOrWhiteSpace(password))
  425. {
  426. return null;
  427. }
  428. NameValuePair savedToken = null;
  429. if (!_tokens.TryGetValue(username, out savedToken))
  430. {
  431. savedToken = new NameValuePair();
  432. _tokens.TryAdd(username, savedToken);
  433. }
  434. if (!string.IsNullOrWhiteSpace(savedToken.Name) && !string.IsNullOrWhiteSpace(savedToken.Value))
  435. {
  436. long ticks;
  437. if (long.TryParse(savedToken.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out ticks))
  438. {
  439. // If it's under 24 hours old we can still use it
  440. if ((DateTime.UtcNow.Ticks - ticks) < TimeSpan.FromHours(24).Ticks)
  441. {
  442. return savedToken.Name;
  443. }
  444. }
  445. }
  446. await _tokenSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
  447. try
  448. {
  449. var result = await GetTokenInternal(username, password, cancellationToken).ConfigureAwait(false);
  450. savedToken.Name = result;
  451. savedToken.Value = DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture);
  452. return result;
  453. }
  454. finally
  455. {
  456. _tokenSemaphore.Release();
  457. }
  458. }
  459. private async Task<string> GetTokenInternal(string username, string password,
  460. CancellationToken cancellationToken)
  461. {
  462. var httpOptions = new HttpRequestOptions()
  463. {
  464. Url = ApiUrl + "/token",
  465. UserAgent = UserAgent,
  466. RequestContent = "{\"username\":\"" + username + "\",\"password\":\"" + password + "\"}",
  467. CancellationToken = cancellationToken
  468. };
  469. //_logger.Info("Obtaining token from Schedules Direct from addres: " + httpOptions.Url + " with body " +
  470. // httpOptions.RequestContent);
  471. using (var responce = await _httpClient.Post(httpOptions))
  472. {
  473. var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Token>(responce.Content);
  474. if (root.message == "OK")
  475. {
  476. _logger.Info("Authenticated with Schedules Direct token: " + root.token);
  477. return root.token;
  478. }
  479. throw new ApplicationException("Could not authenticate with Schedules Direct Error: " + root.message);
  480. }
  481. }
  482. private async Task AddLineupToAccount(ListingsProviderInfo info, CancellationToken cancellationToken)
  483. {
  484. var token = await GetToken(info, cancellationToken);
  485. if (string.IsNullOrWhiteSpace(token))
  486. {
  487. throw new ArgumentException("Authentication required.");
  488. }
  489. if (string.IsNullOrWhiteSpace(info.ListingsId))
  490. {
  491. throw new ArgumentException("Listings Id required");
  492. }
  493. _logger.Info("Adding new LineUp ");
  494. var httpOptions = new HttpRequestOptions()
  495. {
  496. Url = ApiUrl + "/lineups/" + info.ListingsId,
  497. UserAgent = UserAgent,
  498. CancellationToken = cancellationToken
  499. };
  500. httpOptions.RequestHeaders["token"] = token;
  501. using (var response = await _httpClient.SendAsync(httpOptions, "PUT"))
  502. {
  503. }
  504. }
  505. public string Name
  506. {
  507. get { return "Schedules Direct"; }
  508. }
  509. public string Type
  510. {
  511. get { return "SchedulesDirect"; }
  512. }
  513. private async Task<bool> HasLineup(ListingsProviderInfo info, CancellationToken cancellationToken)
  514. {
  515. if (string.IsNullOrWhiteSpace(info.ListingsId))
  516. {
  517. throw new ArgumentException("Listings Id required");
  518. }
  519. var token = await GetToken(info, cancellationToken);
  520. if (string.IsNullOrWhiteSpace(token))
  521. {
  522. throw new Exception("token required");
  523. }
  524. _logger.Info("Headends on account ");
  525. var options = new HttpRequestOptions()
  526. {
  527. Url = ApiUrl + "/lineups",
  528. UserAgent = UserAgent,
  529. CancellationToken = cancellationToken
  530. };
  531. options.RequestHeaders["token"] = token;
  532. using (var response = await _httpClient.Get(options).ConfigureAwait(false))
  533. {
  534. var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Lineups>(response);
  535. return root.lineups.Any(i => string.Equals(info.ListingsId, i.lineup, StringComparison.OrdinalIgnoreCase));
  536. }
  537. }
  538. public async Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings)
  539. {
  540. if (validateLogin)
  541. {
  542. if (string.IsNullOrWhiteSpace(info.Username))
  543. {
  544. throw new ArgumentException("Username is required");
  545. }
  546. if (string.IsNullOrWhiteSpace(info.Password))
  547. {
  548. throw new ArgumentException("Password is required");
  549. }
  550. }
  551. if (validateListings)
  552. {
  553. if (string.IsNullOrWhiteSpace(info.ListingsId))
  554. {
  555. throw new ArgumentException("Listings Id required");
  556. }
  557. var hasLineup = await HasLineup(info, CancellationToken.None).ConfigureAwait(false);
  558. if (!hasLineup)
  559. {
  560. await AddLineupToAccount(info, CancellationToken.None).ConfigureAwait(false);
  561. }
  562. }
  563. }
  564. public Task<List<NameIdPair>> GetLineups(ListingsProviderInfo info, string country, string location)
  565. {
  566. return GetHeadends(info, country, location, CancellationToken.None);
  567. }
  568. public class ScheduleDirect
  569. {
  570. public class Token
  571. {
  572. public int code { get; set; }
  573. public string message { get; set; }
  574. public string serverID { get; set; }
  575. public string token { get; set; }
  576. }
  577. public class Lineup
  578. {
  579. public string lineup { get; set; }
  580. public string name { get; set; }
  581. public string transport { get; set; }
  582. public string location { get; set; }
  583. public string uri { get; set; }
  584. }
  585. public class Lineups
  586. {
  587. public int code { get; set; }
  588. public string serverID { get; set; }
  589. public string datetime { get; set; }
  590. public List<Lineup> lineups { get; set; }
  591. }
  592. public class Headends
  593. {
  594. public string headend { get; set; }
  595. public string transport { get; set; }
  596. public string location { get; set; }
  597. public List<Lineup> lineups { get; set; }
  598. }
  599. public class Map
  600. {
  601. public string stationID { get; set; }
  602. public string channel { get; set; }
  603. public int uhfVhf { get; set; }
  604. public int atscMajor { get; set; }
  605. public int atscMinor { get; set; }
  606. }
  607. public class Broadcaster
  608. {
  609. public string city { get; set; }
  610. public string state { get; set; }
  611. public string postalcode { get; set; }
  612. public string country { get; set; }
  613. }
  614. public class Logo
  615. {
  616. public string URL { get; set; }
  617. public int height { get; set; }
  618. public int width { get; set; }
  619. public string md5 { get; set; }
  620. }
  621. public class Station
  622. {
  623. public string stationID { get; set; }
  624. public string name { get; set; }
  625. public string callsign { get; set; }
  626. public List<string> broadcastLanguage { get; set; }
  627. public List<string> descriptionLanguage { get; set; }
  628. public Broadcaster broadcaster { get; set; }
  629. public string affiliate { get; set; }
  630. public Logo logo { get; set; }
  631. public bool? isCommercialFree { get; set; }
  632. }
  633. public class Metadata
  634. {
  635. public string lineup { get; set; }
  636. public string modified { get; set; }
  637. public string transport { get; set; }
  638. }
  639. public class Channel
  640. {
  641. public List<Map> map { get; set; }
  642. public List<Station> stations { get; set; }
  643. public Metadata metadata { get; set; }
  644. }
  645. public class RequestScheduleForChannel
  646. {
  647. public string stationID { get; set; }
  648. public List<string> date { get; set; }
  649. }
  650. public class Rating
  651. {
  652. public string body { get; set; }
  653. public string code { get; set; }
  654. }
  655. public class Multipart
  656. {
  657. public int partNumber { get; set; }
  658. public int totalParts { get; set; }
  659. }
  660. public class Program
  661. {
  662. public string programID { get; set; }
  663. public string airDateTime { get; set; }
  664. public int duration { get; set; }
  665. public string md5 { get; set; }
  666. public List<string> audioProperties { get; set; }
  667. public List<string> videoProperties { get; set; }
  668. public List<Rating> ratings { get; set; }
  669. public bool? @new { get; set; }
  670. public Multipart multipart { get; set; }
  671. }
  672. public class MetadataSchedule
  673. {
  674. public string modified { get; set; }
  675. public string md5 { get; set; }
  676. public string startDate { get; set; }
  677. public string endDate { get; set; }
  678. public int days { get; set; }
  679. }
  680. public class Day
  681. {
  682. public string stationID { get; set; }
  683. public List<Program> programs { get; set; }
  684. public MetadataSchedule metadata { get; set; }
  685. }
  686. //
  687. public class Title
  688. {
  689. public string title120 { get; set; }
  690. }
  691. public class EventDetails
  692. {
  693. public string subType { get; set; }
  694. }
  695. public class Description100
  696. {
  697. public string descriptionLanguage { get; set; }
  698. public string description { get; set; }
  699. }
  700. public class Description1000
  701. {
  702. public string descriptionLanguage { get; set; }
  703. public string description { get; set; }
  704. }
  705. public class DescriptionsProgram
  706. {
  707. public List<Description100> description100 { get; set; }
  708. public List<Description1000> description1000 { get; set; }
  709. }
  710. public class Gracenote
  711. {
  712. public int season { get; set; }
  713. public int episode { get; set; }
  714. }
  715. public class MetadataPrograms
  716. {
  717. public Gracenote Gracenote { get; set; }
  718. }
  719. public class ContentRating
  720. {
  721. public string body { get; set; }
  722. public string code { get; set; }
  723. }
  724. public class Cast
  725. {
  726. public string billingOrder { get; set; }
  727. public string role { get; set; }
  728. public string nameId { get; set; }
  729. public string personId { get; set; }
  730. public string name { get; set; }
  731. public string characterName { get; set; }
  732. }
  733. public class Crew
  734. {
  735. public string billingOrder { get; set; }
  736. public string role { get; set; }
  737. public string nameId { get; set; }
  738. public string personId { get; set; }
  739. public string name { get; set; }
  740. }
  741. public class QualityRating
  742. {
  743. public string ratingsBody { get; set; }
  744. public string rating { get; set; }
  745. public string minRating { get; set; }
  746. public string maxRating { get; set; }
  747. public string increment { get; set; }
  748. }
  749. public class Movie
  750. {
  751. public string year { get; set; }
  752. public int duration { get; set; }
  753. public List<QualityRating> qualityRating { get; set; }
  754. }
  755. public class Recommendation
  756. {
  757. public string programID { get; set; }
  758. public string title120 { get; set; }
  759. }
  760. public class ProgramDetails
  761. {
  762. public string programID { get; set; }
  763. public List<Title> titles { get; set; }
  764. public EventDetails eventDetails { get; set; }
  765. public DescriptionsProgram descriptions { get; set; }
  766. public string originalAirDate { get; set; }
  767. public List<string> genres { get; set; }
  768. public string episodeTitle150 { get; set; }
  769. public List<MetadataPrograms> metadata { get; set; }
  770. public List<ContentRating> contentRating { get; set; }
  771. public List<Cast> cast { get; set; }
  772. public List<Crew> crew { get; set; }
  773. public string showType { get; set; }
  774. public bool hasImageArtwork { get; set; }
  775. public string images { get; set; }
  776. public string imageID { get; set; }
  777. public string md5 { get; set; }
  778. public List<string> contentAdvisory { get; set; }
  779. public Movie movie { get; set; }
  780. public List<Recommendation> recommendations { get; set; }
  781. }
  782. public class Caption
  783. {
  784. public string content { get; set; }
  785. public string lang { get; set; }
  786. }
  787. public class ImageData
  788. {
  789. public string width { get; set; }
  790. public string height { get; set; }
  791. public string uri { get; set; }
  792. public string size { get; set; }
  793. public string aspect { get; set; }
  794. public string category { get; set; }
  795. public string text { get; set; }
  796. public string primary { get; set; }
  797. public string tier { get; set; }
  798. public Caption caption { get; set; }
  799. }
  800. public class ShowImages
  801. {
  802. public string programID { get; set; }
  803. public List<ImageData> data { get; set; }
  804. }
  805. }
  806. }
  807. }