author | StephaneLenclud |
Fri, 15 May 2015 15:16:18 +0200 | |
changeset 2 | d73e99c5333c |
child 3 | 01a00603ec28 |
permissions | -rw-r--r-- |
StephaneLenclud@1 | 1 |
using System; |
StephaneLenclud@1 | 2 |
using System.Collections.Generic; |
StephaneLenclud@1 | 3 |
using System.Linq; |
StephaneLenclud@1 | 4 |
using System.Text; |
StephaneLenclud@1 | 5 |
using System.Threading.Tasks; |
StephaneLenclud@1 | 6 |
using CsQuery; |
StephaneLenclud@1 | 7 |
using System.Diagnostics; |
StephaneLenclud@1 | 8 |
using System.Net; |
StephaneLenclud@1 | 9 |
|
StephaneLenclud@1 | 10 |
namespace SatChanGen |
StephaneLenclud@1 | 11 |
{ |
StephaneLenclud@1 | 12 |
class KingOfSat |
StephaneLenclud@1 | 13 |
{ |
StephaneLenclud@1 | 14 |
// |
StephaneLenclud@1 | 15 |
// Summary: |
StephaneLenclud@1 | 16 |
// Create a new CQ object wrapping a single element. |
StephaneLenclud@1 | 17 |
// |
StephaneLenclud@1 | 18 |
// Parameters: |
StephaneLenclud@1 | 19 |
// aUrl: |
StephaneLenclud@1 | 20 |
// URL to a KingOfSat channel list. Typically a package list. |
StephaneLenclud@1 | 21 |
// |
StephaneLenclud@1 | 22 |
// Return: |
StephaneLenclud@1 | 23 |
// List of channels parsed. |
StephaneLenclud@1 | 24 |
public static List<Channel> Parse(string aUrl) |
StephaneLenclud@1 | 25 |
{ |
StephaneLenclud@1 | 26 |
string kos = new WebClient().DownloadString(aUrl); |
StephaneLenclud@1 | 27 |
//Debug.Write(kos); |
StephaneLenclud@1 | 28 |
|
StephaneLenclud@1 | 29 |
CQ dom = kos; |
StephaneLenclud@1 | 30 |
|
StephaneLenclud@1 | 31 |
//Get all the Frequency elements in our page |
StephaneLenclud@1 | 32 |
CQ sats = dom[".frq"]; |
StephaneLenclud@1 | 33 |
|
StephaneLenclud@1 | 34 |
//Create our list of channels |
StephaneLenclud@1 | 35 |
List<Channel> channels = new List<Channel>(); |
StephaneLenclud@1 | 36 |
|
StephaneLenclud@1 | 37 |
foreach (IDomObject frq in sats.ToList()) |
StephaneLenclud@1 | 38 |
{ |
StephaneLenclud@1 | 39 |
Channel common = new Channel(); |
StephaneLenclud@1 | 40 |
|
StephaneLenclud@1 | 41 |
//Parse channel details |
StephaneLenclud@1 | 42 |
common.OrbitalPosition = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td > a > font").Get(0).InnerText); |
StephaneLenclud@1 | 43 |
common.Satellite = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(2) > a").Get(0).InnerText); |
StephaneLenclud@1 | 44 |
common.Frequency = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(3)").Get(0).InnerText); |
StephaneLenclud@1 | 45 |
common.Polarisation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(4)").Get(0).InnerText); |
StephaneLenclud@1 | 46 |
common.Transponder = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(5) > a").Get(0).InnerText); |
StephaneLenclud@1 | 47 |
common.Beam = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(6) > a").Get(0).InnerText); |
StephaneLenclud@1 | 48 |
common.Standard = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(7)").Get(0).InnerText); |
StephaneLenclud@1 | 49 |
common.Modulation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(8)").Get(0).InnerText); |
StephaneLenclud@1 | 50 |
common.SymbolRate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a").Get(0).InnerText); |
StephaneLenclud@1 | 51 |
common.FEC = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a:nth-child(2)").Get(0).InnerText); |
StephaneLenclud@1 | 52 |
try |
StephaneLenclud@1 | 53 |
{ |
StephaneLenclud@1 | 54 |
common.Provider = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10) > b").Get(0).InnerText); |
StephaneLenclud@1 | 55 |
} |
StephaneLenclud@1 | 56 |
catch (Exception) |
StephaneLenclud@1 | 57 |
{ |
StephaneLenclud@1 | 58 |
} |
StephaneLenclud@1 | 59 |
|
StephaneLenclud@1 | 60 |
common.Bitrate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10)").Get(0).InnerText); |
StephaneLenclud@1 | 61 |
if (common.Bitrate.Substring(0, ", ".Length) == ", ") |
StephaneLenclud@1 | 62 |
{ |
StephaneLenclud@1 | 63 |
common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length); |
StephaneLenclud@1 | 64 |
} |
StephaneLenclud@1 | 65 |
// |
StephaneLenclud@1 | 66 |
common.NetworkID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(11)").Get(0).InnerText); |
StephaneLenclud@1 | 67 |
common.NetworkID = common.NetworkID.Substring("NID:".Length, common.NetworkID.Length - "NID:".Length); |
StephaneLenclud@1 | 68 |
// |
StephaneLenclud@1 | 69 |
common.TransponderID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(12)").Get(0).InnerText); |
StephaneLenclud@1 | 70 |
common.TransponderID = common.TransponderID.Substring("TID:".Length, common.TransponderID.Length - "TID:".Length); |
StephaneLenclud@1 | 71 |
|
StephaneLenclud@1 | 72 |
//We got common properties for the coming channels |
StephaneLenclud@1 | 73 |
//Debug.Write(common.ToString()); |
StephaneLenclud@1 | 74 |
|
StephaneLenclud@1 | 75 |
//Now get all the channels for that frequency |
StephaneLenclud@1 | 76 |
//Channel common = new Channel(); |
StephaneLenclud@1 | 77 |
|
StephaneLenclud@1 | 78 |
CQ channelsDiv = frq.Cq().Next("div"); |
StephaneLenclud@1 | 79 |
CQ channelsTableRows = channelsDiv.Find("table.fl > tbody").Children("tr"); |
StephaneLenclud@1 | 80 |
|
StephaneLenclud@1 | 81 |
foreach (IDomObject row in channelsTableRows) |
StephaneLenclud@1 | 82 |
{ |
StephaneLenclud@1 | 83 |
Channel channel = new Channel(); |
StephaneLenclud@1 | 84 |
//Initialize this channel with common properties on this frequency |
StephaneLenclud@1 | 85 |
channel = common; |
StephaneLenclud@1 | 86 |
|
StephaneLenclud@1 | 87 |
//Try and parse channel name |
StephaneLenclud@1 | 88 |
CQ cqChannelName = row.Cq().Find("td:nth-child(3) > a"); |
StephaneLenclud@1 | 89 |
if (cqChannelName.Length == 0) |
StephaneLenclud@1 | 90 |
{ |
StephaneLenclud@1 | 91 |
cqChannelName = row.Cq().Find("td:nth-child(3) > i"); |
StephaneLenclud@1 | 92 |
if (cqChannelName.Length == 0) |
StephaneLenclud@1 | 93 |
{ |
StephaneLenclud@1 | 94 |
//Can't get channel name |
StephaneLenclud@1 | 95 |
Debug.Write("WARNING: Can't find channel name! Skipping this channel"); |
StephaneLenclud@1 | 96 |
continue; |
StephaneLenclud@1 | 97 |
} |
StephaneLenclud@1 | 98 |
} |
StephaneLenclud@1 | 99 |
|
StephaneLenclud@1 | 100 |
channel.Name = WebUtility.HtmlDecode(cqChannelName.Get(0).InnerText).Trim(); |
StephaneLenclud@1 | 101 |
if (channel.Name == "Name") |
StephaneLenclud@1 | 102 |
{ |
StephaneLenclud@1 | 103 |
//Skipping header rows |
StephaneLenclud@1 | 104 |
continue; |
StephaneLenclud@1 | 105 |
} |
StephaneLenclud@1 | 106 |
|
StephaneLenclud@1 | 107 |
//So we have a channel name get the other properties then |
StephaneLenclud@1 | 108 |
channel.Country = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(4)").Get(0).InnerText).Trim(); |
StephaneLenclud@1 | 109 |
channel.Category = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(5)").Get(0).InnerText).Trim(); |
StephaneLenclud@1 | 110 |
//Skip the packages |
StephaneLenclud@1 | 111 |
//Skip the encryptions |
StephaneLenclud@1 | 112 |
channel.SID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(8)").Get(0).InnerText).Trim(); |
StephaneLenclud@1 | 113 |
channel.VPID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(9)").Get(0).InnerText).Trim(); |
StephaneLenclud@1 | 114 |
//Skip audios |
StephaneLenclud@1 | 115 |
channel.PMT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim(); |
StephaneLenclud@1 | 116 |
channel.PCR = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim(); |
StephaneLenclud@1 | 117 |
channel.TXT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim(); |
StephaneLenclud@1 | 118 |
|
StephaneLenclud@1 | 119 |
//Append that new channel to our list |
StephaneLenclud@1 | 120 |
channels.Add(channel); |
StephaneLenclud@1 | 121 |
|
StephaneLenclud@1 | 122 |
//Show it in debug output |
StephaneLenclud@1 | 123 |
Debug.Write(channel); |
StephaneLenclud@1 | 124 |
} //For each channel |
StephaneLenclud@1 | 125 |
} //For each frequency |
StephaneLenclud@1 | 126 |
|
StephaneLenclud@1 | 127 |
return channels; |
StephaneLenclud@1 | 128 |
} |
StephaneLenclud@1 | 129 |
} |
StephaneLenclud@1 | 130 |
} |