public async Task <string> GetEPGItemDescription(EPGItem epgItem) { if (!string.IsNullOrEmpty(epgItem.Description)) { return(epgItem.Description); } epgItem.Description = await GetEPGProgramDetailDescription(epgItem.EPGId); return(epgItem.Description); }
public async Task <string> GetEPGItemDescription(EPGItem epgItem) { // https://api.o2tv.cz/unity/api/v1/programs/29909804/ _log.Debug("Getting epg program detail"); await Login(); if (_status != StatusEnum.Logged) { return(null); } try { var headerPostData = GetUnityHeaderData(); var url = $"https://api.o2tv.cz/unity/api/v1/programs/{epgItem.EPGId}/"; var response = await SendRequest(url, "GET", null, headerPostData); var responseJson = JObject.Parse(response); /* Response: * * { * "name": "Evropský fotbal (233/2019)", * "channelKey": "O2 Sport HD", * "shortDescription": "Fotbalový magazín z nejlepších evropských soutěží (Bundesliga, LaLiga, Premier League, Serie A)", * "logoUrl": "/assets/images/tv-logos/original/o2-sport-hd.png", * "npvr": true, * "epgId": 29909804, * "timeShift": false, * "picture": "/img/epg/o2_sport_hd/29909804/double.jpg", * "end": 1622199600000, * "start": 1622197800000, * "images": [ * { * "name": "tvprofi", * "cover": "/img/epg/o2_sport_hd/29909804/profi_cover.jpg", * "land": "/img/epg/o2_sport_hd/29909804/profi_land.jpg", * "coverMini": "/img/epg/o2_sport_hd/29909804/profi_cover_mini.jpg", * "landMini": "/img/epg/o2_sport_hd/29909804/profi_land_mini.jpg" * } * ], * "longDescription": "", * "genreInfo": { * "genres": [ * { * "name": "Fotbal" * } * ] * }, * "contentType": "sport", * "availableTo": 1622802600000 * } * */ var shortDescription = String.Empty; var longDescription = String.Empty; if (responseJson.HasValue("shortDescription")) { shortDescription = responseJson.GetStringValue("shortDescription"); } if (responseJson.HasValue("longDescription")) { longDescription = responseJson.GetStringValue("longDescription"); } var res = shortDescription; if ((shortDescription != String.Empty) && (longDescription != String.Empty)) { return(shortDescription + Environment.NewLine + longDescription); } else { return(shortDescription + longDescription); } } catch (WebException wex) { _log.Error(wex, "Error while getting epg program detail"); //_status = StatusEnum.ConnectionNotAvailable; return(null); } catch (Exception ex) { _log.Error(ex, "Error while getting epg program detail"); //_status = StatusEnum.GeneralError; return(null); } }
public async Task <Dictionary <string, List <EPGItem> > > GetChannelsEPG() { _log.Debug("Getting channels EPG"); var res = new Dictionary <string, List <EPGItem> >(); await Login(); if (_status != StatusEnum.Logged) { return(res); } try { foreach (var channelKey in _session.LiveChannels) { var channelKeyUrlEncoded = System.Web.HttpUtility.UrlEncode(channelKey); res.Add(channelKey, new List <EPGItem>()); var headerPostData = GetUnityHeaderData(); var fromUT = DateTimeToO2UnixTime(DateTime.Now.AddHours(-5)); var toUT = DateTimeToO2UnixTime(DateTime.Now.AddHours(+5)); var url = $"https://api.o2tv.cz/unity/api/v1/epg/depr/?channelKey={channelKeyUrlEncoded}&from={fromUT}&to={toUT}"; var response = await SendRequest(url, "GET", null, headerPostData); var responseJson = JObject.Parse(response); if (!responseJson.HasValue("epg")) { throw new Exception($"Invalid response: {response}"); } var epgJson = responseJson.GetValue("epg") as JObject; if (!epgJson.HasValue("items")) { throw new Exception($"Invalid response: {response}"); } foreach (JObject epgItem in epgJson.GetValue("items")) { if (!epgItem.HasValue("channel")) { throw new Exception($"Invalid response: {response}"); } if (!epgItem.HasValue("programs")) { throw new Exception($"Invalid response: {response}"); } foreach (JObject program in epgItem.GetValue("programs")) { if ( !program.HasValue("epgId") || !program.HasValue("start") || !program.HasValue("end") || !program.HasValue("name") ) { throw new Exception($"Invalid response: {response}"); } var startString = program.GetStringValue("start"); var startInt = Int64.Parse(startString); var finishString = program.GetStringValue("end"); var finishInt = Int64.Parse(finishString); var startDate = O2UnixTimeToDateTime(startInt); var finishDate = O2UnixTimeToDateTime(finishInt); if (finishDate < DateTime.Now) { continue; // program has already finished } var item = new EPGItem() { ChannelId = channelKey, Title = program.GetStringValue("name"), Start = startDate, Finish = finishDate, EPGId = program.GetStringValue("epgId") }; res[channelKey].Add(item); } } /* * Response: * * { * "epg": { * "totalCount": 1, * "offset": 0, * "items": [ * { * "channel": { * "channelKey": "ČT sport HD", * "name": "ČT sport HD", * "logoUrl": "/assets/images/tv-logos/original/ct-sport-hd.png", * "weight": 76, * "npvr": true, * "o2tv": true, * "defaultGroup": false, * "live": false, * "npvrForStartedProgram": true, * "npvrForEndedProgram": true, * "storedMediaDuration": 10100, * "epgStartOverlap": 1000, * "epgEndOverlap": 900000 * }, * "programs": [ * { * "epgId": 29896663, * "start": 1622130000000, * "end": 1622133600000, * "npvr": true, * "timeShift": false, * "name": "USA - Lotyšsko, Hokej", * "availableTo": 1622734800000 * }, * { * "epgId": 29896664, * "start": 1622133600000, * "end": 1622144400000, * "npvr": true, * "timeShift": false, * "name": "Švédsko - Česko, Hokej", * "availableTo": 1622738400000 * }, * ....... */ } } catch (WebException wex) { _log.Error(wex, "Error while getting channels epg"); //_status = StatusEnum.ConnectionNotAvailable; } catch (Exception ex) { _log.Error(ex, "Error while getting channels epg"); //_status = StatusEnum.GeneralError; } return(res); }
public async Task <List <EPGItem> > GetEPG() { if (((DateTime.Now - _cachedEPGRefreshTime).TotalMinutes < 60) && _cachedEPG != null && _cachedEPG.Count > 0) { return(_cachedEPG); } var res = new List <EPGItem>(); await Login(); if (_status != StatusEnum.Logged) { return(res); } try { var headerParams = new Dictionary <string, string>(); headerParams.Add("X-SessionKey", _session_key); var channels = await GetChanels(); var channelEPGIDs = new List <string>(); // first channel is not loaded channelEPGIDs.Add($"channel:0"); var chCount = 0; var totalChCount = 0; foreach (var ch in channels) { channelEPGIDs.Add($"channel:{ch.EPGId}"); chCount++; totalChCount++; if (chCount >= 10 || totalChCount == channels.Count) { chCount = 0; var channelEPGIDsAsCommaSeparatedString = string.Join(",", channelEPGIDs); var epgResponse = await SendRequest($"https://as.kuki.cz/api-v2/dashboard?rowGuidList=channel:{channelEPGIDsAsCommaSeparatedString}", "GET", null, headerParams); foreach (Match rgm in Regex.Matches(epgResponse, "\"guid\":\"epg:")) { var pos = epgResponse.IndexOf("\"sourceLogo\"", rgm.Index); var partJson = "{" + epgResponse.Substring(rgm.Index, pos - rgm.Index - 1) + "}"; var epg = JObject.Parse(partJson); var ident = epg["ident"].ToString(); var title = epg["label"].ToString(); var times = $"{epg["startDate"]}{DateTime.Now.Year} {epg["start"]}"; var timef = $"{epg["endDate"]}{DateTime.Now.Year} {epg["end"]}"; var desc = String.Empty; var guid = epg["guid"].ToString(); var item = new EPGItem() { ChannelId = ident, Title = title, Start = DateTime.ParseExact(times, "d.M.yyyy HH:mm", CultureInfo.InvariantCulture), Finish = DateTime.ParseExact(timef, "d.M.yyyy HH:mm", CultureInfo.InvariantCulture), EPGId = guid.Substring(4) }; // excluding old programs if (item.Finish < DateTime.Now) { continue; } res.Add(item); } channelEPGIDs.Clear(); channelEPGIDs.Add($"channel:0"); } } } catch (WebException wex) { _log.Error(wex, "Error while getting epg"); _status = StatusEnum.ConnectionNotAvailable; } catch (Exception ex) { _log.Error(ex, "Error while getting epg"); _status = StatusEnum.GeneralError; } _cachedEPG = res; _cachedEPGRefreshTime = DateTime.Now; return(res); }
public void AddEPGItem(EPGItem epgItem) { _EPGItems.Add(epgItem); NotifyEPGChange(); }
/// <summary> /// Getting actual EPG /// </summary> public async Task <List <EPGItem> > GetEPG() { _log.Debug($"Refreshing EPG"); var result = new List <EPGItem>(); await Login(); try { var ps = new Dictionary <string, string>() { { "PHPSESSID", _session.PHPSESSID }, { "detail", "1" }, { "duration", "180" } }; var epgString = await SendRequest("epg", ps); var epgJson = JObject.Parse(epgString); // has session expired? if (epgJson.HasValue("status") && epgJson.GetStringValue("status") == "0" && epgJson.HasValue("error") && epgJson.GetStringValue("error") == "not logged") { _log.Info("Received status 0, login again"); _session.PHPSESSID = null; await Login(true); if (Status == StatusEnum.Logged) { ps["PHPSESSID"] = _session.PHPSESSID; epgString = await SendRequest("epg", ps); epgJson = JObject.Parse(epgString); } else { _log.Info($"Login again failed (status: {Status})"); return(result); } } if (epgJson.HasValue("status") && epgJson.GetStringValue("status") == "1" && epgJson.HasValue("channels")) { foreach (var epgCh in epgJson.GetValue("channels")) { // id from path (channels.ct1") var chId = epgCh.Path.Substring(9); foreach (var epg in epgJson.GetValue("channels")[chId]) { var title = epg["title"].ToString(); var times = epg["startTime"].ToString(); var timef = epg["endTime"].ToString(); var desc = epg["description"].ToString(); var epgEventId = epg["eventId"].ToString(); var item = new EPGItem() { ChannelId = chId, EPGId = epgEventId, Title = title, Start = DateTime.ParseExact(times, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture), Finish = DateTime.ParseExact(timef, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture), Description = desc }; result.Add(item); } ; } } } catch (WebException wex) { _log.Error(wex, "EPG loading failed"); _status = StatusEnum.ConnectionNotAvailable; } catch (Exception ex) { _log.Error(ex, "EPG loading failed"); _status = StatusEnum.GeneralError; } return(result); }
public async Task <string> GetEPGItemDescription(EPGItem epgItem) { return(epgItem.Description); }
public async Task <string> GetEPGItemDescription(EPGItem epgItem) { return(String.Empty); }
public async Task <string> GetEPGItemDescription(EPGItem epgItem) { return(await _service.GetEPGItemDescription(epgItem)); }