# HG changeset patch # User StephaneLenclud # Date 1431689032 -7200 # Node ID f203331a8f4afcdd8f4a418a81ee7220775f0516 # Parent 1d43448724954d06e2aa1247d266045a777a917f First full parsing of KingOfSat channel list. diff -r 1d4344872495 -r f203331a8f4a Channel.cs --- a/Channel.cs Thu May 14 22:43:17 2015 +0200 +++ b/Channel.cs Fri May 15 13:23:52 2015 +0200 @@ -10,6 +10,9 @@ { class Channel { + //Sky Atlantic HD + public string Name { get; set; } + //------------------------------------------------------ //19.2E public string OrbitalPosition { get; set; } //Astra 1M @@ -39,8 +42,6 @@ //1053 public string TransponderID { get; set; } //------------------------------------------------------ - //Sky Atlantic HD - public string Name { get; set; } //Germany public string Country { get; set; } //Entertainment @@ -65,7 +66,7 @@ ////// public override string ToString() { - string res = ""; + string res = "============[Channel]============\n"; PropertyInfo[] properties = typeof(Channel).GetProperties(); foreach (PropertyInfo property in properties) { diff -r 1d4344872495 -r f203331a8f4a KingOfSat.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KingOfSat.cs Fri May 15 13:23:52 2015 +0200 @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CsQuery; +using System.Diagnostics; +using System.Net; + +namespace SatChanGen +{ + class KingOfSat + { + // + // Summary: + // Create a new CQ object wrapping a single element. + // + // Parameters: + // aUrl: + // URL to a KingOfSat channel list. Typically a package list. + // + // Return: + // List of channels parsed. + public static List Parse(string aUrl) + { + string kos = new WebClient().DownloadString(aUrl); + //Debug.Write(kos); + + CQ dom = kos; + + //Get all the Frequency elements in our page + CQ sats = dom[".frq"]; + + //Create our list of channels + List channels = new List(); + + foreach (IDomObject frq in sats.ToList()) + { + Channel common = new Channel(); + + //Parse channel details + common.OrbitalPosition = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td > a > font").Get(0).InnerText); + common.Satellite = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(2) > a").Get(0).InnerText); + common.Frequency = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(3)").Get(0).InnerText); + common.Polarisation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(4)").Get(0).InnerText); + common.Transponder = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(5) > a").Get(0).InnerText); + common.Beam = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(6) > a").Get(0).InnerText); + common.Standard = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(7)").Get(0).InnerText); + common.Modulation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(8)").Get(0).InnerText); + common.SymbolRate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a").Get(0).InnerText); + common.FEC = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a:nth-child(2)").Get(0).InnerText); + try + { + common.Provider = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10) > b").Get(0).InnerText); + } + catch (Exception) + { + } + + common.Bitrate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10)").Get(0).InnerText); + if (common.Bitrate.Substring(0, ", ".Length) == ", ") + { + common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length); + } + // + common.NetworkID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(11)").Get(0).InnerText); + common.NetworkID = common.NetworkID.Substring("NID:".Length, common.NetworkID.Length - "NID:".Length); + // + common.TransponderID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(12)").Get(0).InnerText); + common.TransponderID = common.TransponderID.Substring("TID:".Length, common.TransponderID.Length - "TID:".Length); + + //We got common properties for the coming channels + //Debug.Write(common.ToString()); + + //Now get all the channels for that frequency + //Channel common = new Channel(); + + CQ channelsDiv = frq.Cq().Next("div"); + CQ channelsTableRows = channelsDiv.Find("table.fl > tbody").Children("tr"); + + foreach (IDomObject row in channelsTableRows) + { + Channel channel = new Channel(); + //Initialize this channel with common properties on this frequency + channel = common; + + //Try and parse channel name + CQ cqChannelName = row.Cq().Find("td:nth-child(3) > a"); + if (cqChannelName.Length == 0) + { + cqChannelName = row.Cq().Find("td:nth-child(3) > i"); + if (cqChannelName.Length == 0) + { + //Can't get channel name + Debug.Write("WARNING: Can't find channel name! Skipping this channel"); + continue; + } + } + + channel.Name = WebUtility.HtmlDecode(cqChannelName.Get(0).InnerText).Trim(); + if (channel.Name == "Name") + { + //Skipping header rows + continue; + } + + //So we have a channel name get the other properties then + channel.Country = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(4)").Get(0).InnerText).Trim(); + channel.Category = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(5)").Get(0).InnerText).Trim(); + //Skip the packages + //Skip the encryptions + channel.SID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(8)").Get(0).InnerText).Trim(); + channel.VPID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(9)").Get(0).InnerText).Trim(); + //Skip audios + channel.PMT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim(); + channel.PCR = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim(); + channel.TXT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim(); + + //Append that new channel to our list + channels.Add(channel); + + //Show it in debug output + Debug.Write(channel); + } //For each channel + } //For each frequency + + return channels; + } + } +} diff -r 1d4344872495 -r f203331a8f4a MainForm.cs --- a/MainForm.cs Thu May 14 22:43:17 2015 +0200 +++ b/MainForm.cs Fri May 15 13:23:52 2015 +0200 @@ -24,87 +24,7 @@ private void buttonGenerate_Click(object sender, EventArgs e) { - - string kos = new WebClient().DownloadString("http://en.kingofsat.net/pack-skygermany.php"); - //Debug.Write(kos); - - CQ dom = kos; - - //Get all the Frequency elements in our page - CQ sats = dom[".frq"]; - - foreach (IDomObject frq in sats.ToList()) - { - Debug.Write("=====================\n"); - Channel common=new Channel(); - - //Parse channel details - common.OrbitalPosition = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td > a > font").Get(0).InnerText); - common.Satellite = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(2) > a").Get(0).InnerText); - common.Frequency = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(3)").Get(0).InnerText); - common.Polarisation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(4)").Get(0).InnerText); - common.Transponder = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(5) > a").Get(0).InnerText); - common.Beam = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(6) > a").Get(0).InnerText); - common.Standard = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(7)").Get(0).InnerText); - common.Modulation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(8)").Get(0).InnerText); - common.SymbolRate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a").Get(0).InnerText); - common.FEC = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a:nth-child(2)").Get(0).InnerText); - try - { - common.Provider = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10) > b").Get(0).InnerText); - } - catch (Exception) - { - } - - common.Bitrate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10)").Get(0).InnerText); - if (common.Bitrate.Substring(0, ", ".Length) == ", ") - { - common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length); - } - // - common.NetworkID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(11)").Get(0).InnerText); - common.NetworkID = common.NetworkID.Substring("NID:".Length, common.NetworkID.Length - "NID:".Length); - // - common.TransponderID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(12)").Get(0).InnerText); - common.TransponderID = common.TransponderID.Substring("TID:".Length, common.TransponderID.Length - "TID:".Length); - - //Now get all the channels for that frequency - //Channel common = new Channel(); - - - Debug.Write(common.ToString()); - - } - - //Debug.Write(sats.Text()); - - /* - CQ dom = "
Hello world! I am feeling bold! What about you?
"; - - - CQ bold = dom["b"]; /// find all "b" nodes (there are two in this example) - - - //> bold.ToList() - //> Count = 2 - //> [0]: {...} - //> [1]: {...} - - //> bold.First().RenderSelection() - //> "I am feeling bold!" - - string boldText = bold.Text(); /// jQuery text method; - - //> boldText - //> "I am feeling bold! you?" - - bold.Remove(); /// jQuery Remove method - - string html = dom.Render(); - - Debug.Write(html); - */ + List channels=KingOfSat.Parse("http://en.kingofsat.net/pack-skygermany.php"); } } } diff -r 1d4344872495 -r f203331a8f4a SatChanGen.csproj --- a/SatChanGen.csproj Thu May 14 22:43:17 2015 +0200 +++ b/SatChanGen.csproj Fri May 15 13:23:52 2015 +0200 @@ -48,6 +48,7 @@ + Form