KingOfSat.cs
author StephaneLenclud
Fri, 15 May 2015 17:28:51 +0200
changeset 3 01a00603ec28
parent 1 f203331a8f4a
child 4 8372aa8d6292
permissions -rw-r--r--
First verified MediaPortal export.
Adding orbital position filter.
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@3
    24
		public static List<Channel> Parse(string aUrl, string aOrbitalPosition)
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@3
    42
				common.OrbitalPosition = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td > a > font").Get(0).InnerText).Trim();
StephaneLenclud@3
    43
			    if (common.OrbitalPosition != aOrbitalPosition)
StephaneLenclud@3
    44
			    {
StephaneLenclud@3
    45
                    //Wrong sat, skip
StephaneLenclud@3
    46
			        continue;
StephaneLenclud@3
    47
			    }
StephaneLenclud@1
    48
				common.Satellite = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(2) > a").Get(0).InnerText);
StephaneLenclud@1
    49
				common.Frequency = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(3)").Get(0).InnerText);
StephaneLenclud@1
    50
				common.Polarisation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(4)").Get(0).InnerText);
StephaneLenclud@1
    51
				common.Transponder = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(5) > a").Get(0).InnerText);
StephaneLenclud@1
    52
				common.Beam = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(6) > a").Get(0).InnerText);
StephaneLenclud@1
    53
				common.Standard = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(7)").Get(0).InnerText);
StephaneLenclud@1
    54
				common.Modulation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(8)").Get(0).InnerText);
StephaneLenclud@1
    55
				common.SymbolRate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a").Get(0).InnerText);
StephaneLenclud@1
    56
				common.FEC = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a:nth-child(2)").Get(0).InnerText);
StephaneLenclud@1
    57
				try
StephaneLenclud@1
    58
				{
StephaneLenclud@1
    59
					common.Provider = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10) > b").Get(0).InnerText);
StephaneLenclud@1
    60
				}
StephaneLenclud@1
    61
				catch (Exception)
StephaneLenclud@1
    62
				{
StephaneLenclud@1
    63
				}
StephaneLenclud@1
    64
StephaneLenclud@1
    65
				common.Bitrate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10)").Get(0).InnerText);
StephaneLenclud@1
    66
				if (common.Bitrate.Substring(0, ", ".Length) == ", ")
StephaneLenclud@1
    67
				{
StephaneLenclud@1
    68
					common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length);
StephaneLenclud@1
    69
				}
StephaneLenclud@1
    70
				//
StephaneLenclud@1
    71
				common.NetworkID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(11)").Get(0).InnerText);
StephaneLenclud@1
    72
				common.NetworkID = common.NetworkID.Substring("NID:".Length, common.NetworkID.Length - "NID:".Length);
StephaneLenclud@1
    73
				//
StephaneLenclud@1
    74
				common.TransponderID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(12)").Get(0).InnerText);
StephaneLenclud@1
    75
				common.TransponderID = common.TransponderID.Substring("TID:".Length, common.TransponderID.Length - "TID:".Length);
StephaneLenclud@1
    76
StephaneLenclud@1
    77
				//We got common properties for the coming channels
StephaneLenclud@1
    78
				//Debug.Write(common.ToString());
StephaneLenclud@1
    79
StephaneLenclud@1
    80
				//Now get all the channels for that frequency
StephaneLenclud@1
    81
				//Channel common = new Channel();
StephaneLenclud@1
    82
StephaneLenclud@1
    83
				CQ channelsDiv = frq.Cq().Next("div");
StephaneLenclud@1
    84
				CQ channelsTableRows = channelsDiv.Find("table.fl > tbody").Children("tr");
StephaneLenclud@1
    85
StephaneLenclud@1
    86
				foreach (IDomObject row in channelsTableRows)
StephaneLenclud@1
    87
				{
StephaneLenclud@1
    88
					Channel channel = new Channel();
StephaneLenclud@1
    89
					//Initialize this channel with common properties on this frequency
StephaneLenclud@3
    90
                    channel.Copy(common);
StephaneLenclud@1
    91
StephaneLenclud@1
    92
					//Try and parse channel name
StephaneLenclud@1
    93
					CQ cqChannelName = row.Cq().Find("td:nth-child(3) > a");
StephaneLenclud@1
    94
					if (cqChannelName.Length == 0)
StephaneLenclud@1
    95
					{
StephaneLenclud@1
    96
						cqChannelName = row.Cq().Find("td:nth-child(3) > i");
StephaneLenclud@1
    97
						if (cqChannelName.Length == 0)
StephaneLenclud@1
    98
						{
StephaneLenclud@1
    99
							//Can't get channel name
StephaneLenclud@1
   100
							Debug.Write("WARNING: Can't find channel name! Skipping this channel");
StephaneLenclud@1
   101
							continue;
StephaneLenclud@1
   102
						}
StephaneLenclud@1
   103
					}
StephaneLenclud@1
   104
StephaneLenclud@1
   105
					channel.Name = WebUtility.HtmlDecode(cqChannelName.Get(0).InnerText).Trim();
StephaneLenclud@1
   106
					if (channel.Name == "Name")
StephaneLenclud@1
   107
					{
StephaneLenclud@1
   108
						//Skipping header rows
StephaneLenclud@1
   109
						continue;
StephaneLenclud@1
   110
					}
StephaneLenclud@1
   111
StephaneLenclud@1
   112
					//So we have a channel name get the other properties then
StephaneLenclud@1
   113
					channel.Country = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(4)").Get(0).InnerText).Trim();
StephaneLenclud@1
   114
					channel.Category = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(5)").Get(0).InnerText).Trim();
StephaneLenclud@1
   115
					//Skip the packages
StephaneLenclud@1
   116
					//Skip the encryptions
StephaneLenclud@1
   117
					channel.SID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(8)").Get(0).InnerText).Trim();
StephaneLenclud@1
   118
					channel.VPID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(9)").Get(0).InnerText).Trim();
StephaneLenclud@1
   119
					//Skip audios
StephaneLenclud@1
   120
					channel.PMT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim();
StephaneLenclud@1
   121
					channel.PCR = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim();
StephaneLenclud@1
   122
					channel.TXT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim();
StephaneLenclud@1
   123
StephaneLenclud@1
   124
					//Append that new channel to our list
StephaneLenclud@1
   125
					channels.Add(channel);
StephaneLenclud@1
   126
StephaneLenclud@1
   127
					//Show it in debug output
StephaneLenclud@1
   128
					Debug.Write(channel);
StephaneLenclud@1
   129
				} //For each channel
StephaneLenclud@1
   130
			} //For each frequency
StephaneLenclud@1
   131
StephaneLenclud@1
   132
			return channels;
StephaneLenclud@1
   133
		}
StephaneLenclud@1
   134
	}
StephaneLenclud@1
   135
}