StephaneLenclud@1: using System; StephaneLenclud@1: using System.Collections.Generic; StephaneLenclud@1: using System.Linq; StephaneLenclud@1: using System.Text; StephaneLenclud@1: using System.Threading.Tasks; StephaneLenclud@1: using CsQuery; StephaneLenclud@1: using System.Diagnostics; StephaneLenclud@1: using System.Net; StephaneLenclud@1: StephaneLenclud@1: namespace SatChanGen StephaneLenclud@1: { StephaneLenclud@1: class KingOfSat StephaneLenclud@1: { StephaneLenclud@1: // StephaneLenclud@1: // Summary: StephaneLenclud@1: // Create a new CQ object wrapping a single element. StephaneLenclud@1: // StephaneLenclud@1: // Parameters: StephaneLenclud@1: // aUrl: StephaneLenclud@1: // URL to a KingOfSat channel list. Typically a package list. StephaneLenclud@1: // StephaneLenclud@1: // Return: StephaneLenclud@1: // List of channels parsed. StephaneLenclud@3: public static List Parse(string aUrl, string aOrbitalPosition) StephaneLenclud@1: { StephaneLenclud@1: string kos = new WebClient().DownloadString(aUrl); StephaneLenclud@1: //Debug.Write(kos); StephaneLenclud@1: StephaneLenclud@1: CQ dom = kos; StephaneLenclud@1: StephaneLenclud@1: //Get all the Frequency elements in our page StephaneLenclud@1: CQ sats = dom[".frq"]; StephaneLenclud@1: StephaneLenclud@1: //Create our list of channels StephaneLenclud@1: List channels = new List(); StephaneLenclud@1: StephaneLenclud@1: foreach (IDomObject frq in sats.ToList()) StephaneLenclud@1: { StephaneLenclud@1: Channel common = new Channel(); StephaneLenclud@1: StephaneLenclud@1: //Parse channel details StephaneLenclud@3: common.OrbitalPosition = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td > a > font").Get(0).InnerText).Trim(); StephaneLenclud@3: if (common.OrbitalPosition != aOrbitalPosition) StephaneLenclud@3: { StephaneLenclud@3: //Wrong sat, skip StephaneLenclud@3: continue; StephaneLenclud@3: } StephaneLenclud@1: common.Satellite = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(2) > a").Get(0).InnerText); StephaneLenclud@1: common.Frequency = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(3)").Get(0).InnerText); StephaneLenclud@1: common.Polarisation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(4)").Get(0).InnerText); StephaneLenclud@1: common.Transponder = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(5) > a").Get(0).InnerText); StephaneLenclud@1: common.Beam = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(6) > a").Get(0).InnerText); StephaneLenclud@1: common.Standard = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(7)").Get(0).InnerText); StephaneLenclud@1: common.Modulation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(8)").Get(0).InnerText); StephaneLenclud@1: common.SymbolRate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a").Get(0).InnerText); StephaneLenclud@1: common.FEC = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a:nth-child(2)").Get(0).InnerText); StephaneLenclud@1: try StephaneLenclud@1: { StephaneLenclud@1: common.Provider = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10) > b").Get(0).InnerText); StephaneLenclud@1: } StephaneLenclud@1: catch (Exception) StephaneLenclud@1: { StephaneLenclud@1: } StephaneLenclud@1: StephaneLenclud@1: common.Bitrate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10)").Get(0).InnerText); StephaneLenclud@1: if (common.Bitrate.Substring(0, ", ".Length) == ", ") StephaneLenclud@1: { StephaneLenclud@1: common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length); StephaneLenclud@1: } StephaneLenclud@1: // StephaneLenclud@1: common.NetworkID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(11)").Get(0).InnerText); StephaneLenclud@1: common.NetworkID = common.NetworkID.Substring("NID:".Length, common.NetworkID.Length - "NID:".Length); StephaneLenclud@1: // StephaneLenclud@1: common.TransponderID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(12)").Get(0).InnerText); StephaneLenclud@1: common.TransponderID = common.TransponderID.Substring("TID:".Length, common.TransponderID.Length - "TID:".Length); StephaneLenclud@1: StephaneLenclud@1: //We got common properties for the coming channels StephaneLenclud@1: //Debug.Write(common.ToString()); StephaneLenclud@1: StephaneLenclud@1: //Now get all the channels for that frequency StephaneLenclud@1: //Channel common = new Channel(); StephaneLenclud@1: StephaneLenclud@1: CQ channelsDiv = frq.Cq().Next("div"); StephaneLenclud@1: CQ channelsTableRows = channelsDiv.Find("table.fl > tbody").Children("tr"); StephaneLenclud@1: StephaneLenclud@1: foreach (IDomObject row in channelsTableRows) StephaneLenclud@1: { StephaneLenclud@1: Channel channel = new Channel(); StephaneLenclud@1: //Initialize this channel with common properties on this frequency StephaneLenclud@3: channel.Copy(common); StephaneLenclud@1: StephaneLenclud@1: //Try and parse channel name StephaneLenclud@1: CQ cqChannelName = row.Cq().Find("td:nth-child(3) > a"); StephaneLenclud@1: if (cqChannelName.Length == 0) StephaneLenclud@1: { StephaneLenclud@1: cqChannelName = row.Cq().Find("td:nth-child(3) > i"); StephaneLenclud@1: if (cqChannelName.Length == 0) StephaneLenclud@1: { StephaneLenclud@1: //Can't get channel name StephaneLenclud@1: Debug.Write("WARNING: Can't find channel name! Skipping this channel"); StephaneLenclud@1: continue; StephaneLenclud@1: } StephaneLenclud@1: } StephaneLenclud@1: StephaneLenclud@1: channel.Name = WebUtility.HtmlDecode(cqChannelName.Get(0).InnerText).Trim(); StephaneLenclud@1: if (channel.Name == "Name") StephaneLenclud@1: { StephaneLenclud@1: //Skipping header rows StephaneLenclud@1: continue; StephaneLenclud@1: } StephaneLenclud@1: StephaneLenclud@1: //So we have a channel name get the other properties then StephaneLenclud@1: channel.Country = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(4)").Get(0).InnerText).Trim(); StephaneLenclud@1: channel.Category = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(5)").Get(0).InnerText).Trim(); StephaneLenclud@1: //Skip the packages StephaneLenclud@1: //Skip the encryptions StephaneLenclud@1: channel.SID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(8)").Get(0).InnerText).Trim(); StephaneLenclud@1: channel.VPID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(9)").Get(0).InnerText).Trim(); StephaneLenclud@1: //Skip audios StephaneLenclud@1: channel.PMT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim(); StephaneLenclud@1: channel.PCR = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim(); StephaneLenclud@1: channel.TXT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim(); StephaneLenclud@1: StephaneLenclud@1: //Append that new channel to our list StephaneLenclud@1: channels.Add(channel); StephaneLenclud@1: StephaneLenclud@1: //Show it in debug output StephaneLenclud@1: Debug.Write(channel); StephaneLenclud@1: } //For each channel StephaneLenclud@1: } //For each frequency StephaneLenclud@1: StephaneLenclud@1: return channels; StephaneLenclud@1: } StephaneLenclud@1: } StephaneLenclud@1: }