First full parsing of KingOfSat channel list.
authorStephaneLenclud
Fri, 15 May 2015 13:23:52 +0200
changeset 1f203331a8f4a
parent 0 1d4344872495
child 2 d73e99c5333c
First full parsing of KingOfSat channel list.
Channel.cs
KingOfSat.cs
MainForm.cs
SatChanGen.csproj
     1.1 --- a/Channel.cs	Thu May 14 22:43:17 2015 +0200
     1.2 +++ b/Channel.cs	Fri May 15 13:23:52 2015 +0200
     1.3 @@ -10,6 +10,9 @@
     1.4  {
     1.5  	class Channel
     1.6  	{
     1.7 +		//Sky Atlantic HD
     1.8 +		public string Name { get; set; }
     1.9 +		//------------------------------------------------------
    1.10  		//19.2E
    1.11  		public string OrbitalPosition { get; set; }
    1.12  		//Astra 1M
    1.13 @@ -39,8 +42,6 @@
    1.14  		//1053
    1.15  		public string TransponderID { get; set; }
    1.16  		//------------------------------------------------------
    1.17 -		//Sky Atlantic HD
    1.18 -		public string Name { get; set; }
    1.19  		//Germany
    1.20  		public string Country { get; set; }
    1.21  		//Entertainment
    1.22 @@ -65,7 +66,7 @@
    1.23  		//////
    1.24  		public override string ToString()
    1.25  		{
    1.26 -			string res = "";
    1.27 +			string res = "============[Channel]============\n";
    1.28  			PropertyInfo[] properties = typeof(Channel).GetProperties();
    1.29  			foreach (PropertyInfo property in properties)
    1.30  			{
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/KingOfSat.cs	Fri May 15 13:23:52 2015 +0200
     2.3 @@ -0,0 +1,130 @@
     2.4 +using System;
     2.5 +using System.Collections.Generic;
     2.6 +using System.Linq;
     2.7 +using System.Text;
     2.8 +using System.Threading.Tasks;
     2.9 +using CsQuery;
    2.10 +using System.Diagnostics;
    2.11 +using System.Net;
    2.12 +
    2.13 +namespace SatChanGen
    2.14 +{
    2.15 +	class KingOfSat
    2.16 +	{
    2.17 +		//
    2.18 +		// Summary:
    2.19 +		//     Create a new CQ object wrapping a single element.
    2.20 +		//
    2.21 +		// Parameters:
    2.22 +		//   aUrl:
    2.23 +		//     URL to a KingOfSat channel list. Typically a package list.
    2.24 +		//
    2.25 +		// Return:
    2.26 +		//   List of channels parsed.		
    2.27 +		public static List<Channel> Parse(string aUrl)
    2.28 +		{
    2.29 +			string kos = new WebClient().DownloadString(aUrl);
    2.30 +			//Debug.Write(kos);
    2.31 +
    2.32 +			CQ dom = kos;
    2.33 +
    2.34 +			//Get all the Frequency elements in our page
    2.35 +			CQ sats = dom[".frq"];
    2.36 +
    2.37 +			//Create our list of channels
    2.38 +			List<Channel> channels = new List<Channel>();
    2.39 +
    2.40 +			foreach (IDomObject frq in sats.ToList())
    2.41 +			{
    2.42 +				Channel common = new Channel();
    2.43 +
    2.44 +				//Parse channel details
    2.45 +				common.OrbitalPosition = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td > a > font").Get(0).InnerText);
    2.46 +				common.Satellite = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(2) > a").Get(0).InnerText);
    2.47 +				common.Frequency = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(3)").Get(0).InnerText);
    2.48 +				common.Polarisation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(4)").Get(0).InnerText);
    2.49 +				common.Transponder = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(5) > a").Get(0).InnerText);
    2.50 +				common.Beam = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(6) > a").Get(0).InnerText);
    2.51 +				common.Standard = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(7)").Get(0).InnerText);
    2.52 +				common.Modulation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(8)").Get(0).InnerText);
    2.53 +				common.SymbolRate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a").Get(0).InnerText);
    2.54 +				common.FEC = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a:nth-child(2)").Get(0).InnerText);
    2.55 +				try
    2.56 +				{
    2.57 +					common.Provider = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10) > b").Get(0).InnerText);
    2.58 +				}
    2.59 +				catch (Exception)
    2.60 +				{
    2.61 +				}
    2.62 +
    2.63 +				common.Bitrate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10)").Get(0).InnerText);
    2.64 +				if (common.Bitrate.Substring(0, ", ".Length) == ", ")
    2.65 +				{
    2.66 +					common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length);
    2.67 +				}
    2.68 +				//
    2.69 +				common.NetworkID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(11)").Get(0).InnerText);
    2.70 +				common.NetworkID = common.NetworkID.Substring("NID:".Length, common.NetworkID.Length - "NID:".Length);
    2.71 +				//
    2.72 +				common.TransponderID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(12)").Get(0).InnerText);
    2.73 +				common.TransponderID = common.TransponderID.Substring("TID:".Length, common.TransponderID.Length - "TID:".Length);
    2.74 +
    2.75 +				//We got common properties for the coming channels
    2.76 +				//Debug.Write(common.ToString());
    2.77 +
    2.78 +				//Now get all the channels for that frequency
    2.79 +				//Channel common = new Channel();
    2.80 +
    2.81 +				CQ channelsDiv = frq.Cq().Next("div");
    2.82 +				CQ channelsTableRows = channelsDiv.Find("table.fl > tbody").Children("tr");
    2.83 +
    2.84 +				foreach (IDomObject row in channelsTableRows)
    2.85 +				{
    2.86 +					Channel channel = new Channel();
    2.87 +					//Initialize this channel with common properties on this frequency
    2.88 +					channel = common;
    2.89 +
    2.90 +					//Try and parse channel name
    2.91 +					CQ cqChannelName = row.Cq().Find("td:nth-child(3) > a");
    2.92 +					if (cqChannelName.Length == 0)
    2.93 +					{
    2.94 +						cqChannelName = row.Cq().Find("td:nth-child(3) > i");
    2.95 +						if (cqChannelName.Length == 0)
    2.96 +						{
    2.97 +							//Can't get channel name
    2.98 +							Debug.Write("WARNING: Can't find channel name! Skipping this channel");
    2.99 +							continue;
   2.100 +						}
   2.101 +					}
   2.102 +
   2.103 +					channel.Name = WebUtility.HtmlDecode(cqChannelName.Get(0).InnerText).Trim();
   2.104 +					if (channel.Name == "Name")
   2.105 +					{
   2.106 +						//Skipping header rows
   2.107 +						continue;
   2.108 +					}
   2.109 +
   2.110 +					//So we have a channel name get the other properties then
   2.111 +					channel.Country = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(4)").Get(0).InnerText).Trim();
   2.112 +					channel.Category = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(5)").Get(0).InnerText).Trim();
   2.113 +					//Skip the packages
   2.114 +					//Skip the encryptions
   2.115 +					channel.SID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(8)").Get(0).InnerText).Trim();
   2.116 +					channel.VPID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(9)").Get(0).InnerText).Trim();
   2.117 +					//Skip audios
   2.118 +					channel.PMT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim();
   2.119 +					channel.PCR = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim();
   2.120 +					channel.TXT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim();
   2.121 +
   2.122 +					//Append that new channel to our list
   2.123 +					channels.Add(channel);
   2.124 +
   2.125 +					//Show it in debug output
   2.126 +					Debug.Write(channel);
   2.127 +				} //For each channel
   2.128 +			} //For each frequency
   2.129 +
   2.130 +			return channels;
   2.131 +		}
   2.132 +	}
   2.133 +}
     3.1 --- a/MainForm.cs	Thu May 14 22:43:17 2015 +0200
     3.2 +++ b/MainForm.cs	Fri May 15 13:23:52 2015 +0200
     3.3 @@ -24,87 +24,7 @@
     3.4  
     3.5          private void buttonGenerate_Click(object sender, EventArgs e)
     3.6          {
     3.7 -
     3.8 -            string kos = new WebClient().DownloadString("http://en.kingofsat.net/pack-skygermany.php");
     3.9 -            //Debug.Write(kos);
    3.10 -
    3.11 -            CQ dom = kos;
    3.12 -
    3.13 -			//Get all the Frequency elements in our page
    3.14 -            CQ sats = dom[".frq"];
    3.15 -
    3.16 -            foreach (IDomObject frq in sats.ToList())
    3.17 -            {
    3.18 -	            Debug.Write("=====================\n");
    3.19 -	            Channel common=new Channel();
    3.20 -
    3.21 -				//Parse channel details
    3.22 -	            common.OrbitalPosition = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td > a > font").Get(0).InnerText);
    3.23 -				common.Satellite = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(2) > a").Get(0).InnerText);
    3.24 -				common.Frequency = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(3)").Get(0).InnerText);
    3.25 -				common.Polarisation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(4)").Get(0).InnerText);
    3.26 -				common.Transponder = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(5) > a").Get(0).InnerText);
    3.27 -				common.Beam = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(6) > a").Get(0).InnerText);
    3.28 -				common.Standard = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(7)").Get(0).InnerText);
    3.29 -				common.Modulation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(8)").Get(0).InnerText);
    3.30 -				common.SymbolRate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a").Get(0).InnerText);
    3.31 -				common.FEC = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a:nth-child(2)").Get(0).InnerText);
    3.32 -	            try
    3.33 -	            {
    3.34 -					common.Provider = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10) > b").Get(0).InnerText);
    3.35 -	            }
    3.36 -	            catch (Exception)
    3.37 -	            {			
    3.38 -	            }
    3.39 -
    3.40 -				common.Bitrate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10)").Get(0).InnerText);
    3.41 -	            if (common.Bitrate.Substring(0, ", ".Length) == ", ")
    3.42 -	            {
    3.43 -					common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length);
    3.44 -	            }
    3.45 -				//
    3.46 -				common.NetworkID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(11)").Get(0).InnerText);
    3.47 -				common.NetworkID = common.NetworkID.Substring("NID:".Length, common.NetworkID.Length - "NID:".Length);
    3.48 -				//
    3.49 -				common.TransponderID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(12)").Get(0).InnerText);
    3.50 -				common.TransponderID = common.TransponderID.Substring("TID:".Length, common.TransponderID.Length - "TID:".Length);
    3.51 -
    3.52 -				//Now get all the channels for that frequency
    3.53 -				//Channel common = new Channel();
    3.54 -
    3.55 -								
    3.56 -				Debug.Write(common.ToString());
    3.57 -
    3.58 -            }
    3.59 -
    3.60 -            //Debug.Write(sats.Text());
    3.61 -
    3.62 -            /*
    3.63 -            CQ dom = "<div>Hello world! <b>I am feeling bold!</b> What about <b>you?</b></div>";
    3.64 -
    3.65 -
    3.66 -            CQ bold = dom["b"];               /// find all "b" nodes (there are two in this example)
    3.67 -
    3.68 -            
    3.69 -  //> bold.ToList()
    3.70 -  //> Count = 2
    3.71 -  //> [0]: {<b>...</b>}
    3.72 -  //> [1]: {<b>...</b>}
    3.73 -
    3.74 -  //> bold.First().RenderSelection()
    3.75 -  //> "<b>I am feeling bold!</b>"
    3.76 -            
    3.77 -            string boldText = bold.Text();        /// jQuery text method;
    3.78 -
    3.79 -  //> boldText
    3.80 -  //> "I am feeling bold! you?"
    3.81 -
    3.82 -            bold.Remove();                        /// jQuery Remove method
    3.83 -
    3.84 -            string html = dom.Render();
    3.85 -
    3.86 -            Debug.Write(html);
    3.87 -            */
    3.88 +	        List<Channel> channels=KingOfSat.Parse("http://en.kingofsat.net/pack-skygermany.php");
    3.89          }
    3.90      }
    3.91  }
     4.1 --- a/SatChanGen.csproj	Thu May 14 22:43:17 2015 +0200
     4.2 +++ b/SatChanGen.csproj	Fri May 15 13:23:52 2015 +0200
     4.3 @@ -48,6 +48,7 @@
     4.4    </ItemGroup>
     4.5    <ItemGroup>
     4.6      <Compile Include="Channel.cs" />
     4.7 +    <Compile Include="KingOfSat.cs" />
     4.8      <Compile Include="MainForm.cs">
     4.9        <SubType>Form</SubType>
    4.10      </Compile>