SatIndex.cs
author StephaneLenclud
Sat, 06 Oct 2018 14:07:31 +0200
changeset 9 b77b09f680e7
parent 8 adff2dec03a0
permissions -rw-r--r--
SatIndex grabber now working.
StephaneLenclud@9
     1
using CsQuery;
StephaneLenclud@9
     2
using System;
StephaneLenclud@8
     3
using System.Collections.Generic;
StephaneLenclud@9
     4
using System.Diagnostics;
StephaneLenclud@8
     5
using System.Linq;
StephaneLenclud@9
     6
using System.Net;
StephaneLenclud@8
     7
using System.Text;
StephaneLenclud@9
     8
using System.Text.RegularExpressions;
StephaneLenclud@8
     9
using System.Threading.Tasks;
StephaneLenclud@8
    10
StephaneLenclud@8
    11
namespace SatChanGen
StephaneLenclud@8
    12
{
StephaneLenclud@8
    13
    class SatIndex
StephaneLenclud@8
    14
    {
StephaneLenclud@9
    15
        public static Channel ParseChannel(string aUrl)
StephaneLenclud@9
    16
        {
StephaneLenclud@9
    17
            Channel channel = new Channel();
StephaneLenclud@9
    18
StephaneLenclud@9
    19
            string satIndex = new WebClient().DownloadString(aUrl);
StephaneLenclud@9
    20
            //Debug.Write(satIndex);
StephaneLenclud@9
    21
            CQ dom = satIndex;
StephaneLenclud@9
    22
StephaneLenclud@9
    23
            channel.Name = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Name')").Next().Text());
StephaneLenclud@9
    24
            //Convert from default encoding to UTF8
StephaneLenclud@9
    25
            //We spend a lot of time trying to get this right until we found our answer in the following thread.
StephaneLenclud@9
    26
            //http://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c
StephaneLenclud@9
    27
            //byte[] bytes = Encoding.Default.GetBytes(channel.Name);
StephaneLenclud@9
    28
            //channel.Name = Encoding.UTF8.GetString(bytes);
StephaneLenclud@9
    29
            //
StephaneLenclud@9
    30
            channel.Satellite = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Satellit')").Next().Text());
StephaneLenclud@9
    31
            channel.OrbitalPosition = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Position')").Next().Text());
StephaneLenclud@9
    32
            // Frequency, remove dots and unit
StephaneLenclud@9
    33
            channel.Frequency = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Frequenz')").Next().Text());
StephaneLenclud@9
    34
            channel.Frequency = channel.Frequency.Replace(" MHz", "").Replace(".", "");
StephaneLenclud@9
    35
            // Just get 'H' or 'V' I guess
StephaneLenclud@9
    36
            channel.Polarisation = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Polarisation')").Next().Text()).Substring(0,1);
StephaneLenclud@9
    37
            channel.Transponder = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Transponder:')").Next().Text());
StephaneLenclud@9
    38
            channel.TransponderID = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Transponder ID')").Next().Text()).Replace(".", "");
StephaneLenclud@9
    39
            channel.Beam = "Astra";
StephaneLenclud@9
    40
            channel.Standard = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Art')").Next().Text());
StephaneLenclud@9
    41
            channel.Modulation = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Modulation')").Next().Text());
StephaneLenclud@9
    42
            channel.SymbolRate = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Symbolrate')").Next().Text());
StephaneLenclud@9
    43
            channel.SymbolRate = channel.SymbolRate.Replace(" kSym/s", "").Replace(".", "");
StephaneLenclud@9
    44
            channel.FEC = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('FEC')").Next().Text());
StephaneLenclud@9
    45
            channel.Provider = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Provider')").Next().Text());
StephaneLenclud@9
    46
StephaneLenclud@9
    47
            channel.Bitrate = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Video Bitrate')").Next().Text());
StephaneLenclud@9
    48
            channel.NetworkID = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Netzwerk ID')").Next().Text());
StephaneLenclud@9
    49
StephaneLenclud@9
    50
            channel.SID = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Service ID')").Next().Text());
StephaneLenclud@9
    51
            channel.VPID = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Video Pid')").Next().Text());
StephaneLenclud@9
    52
            channel.PCR = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('PCR Pid')").Next().Text());
StephaneLenclud@9
    53
            channel.PMT = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('PMT Pid')").Next().Text());
StephaneLenclud@9
    54
            channel.TXT = WebUtility.HtmlDecode(dom.Find("td.chdet1:contains('Videotext Pid')").Next().Text()).Replace(" (kein Videotext)","");
StephaneLenclud@9
    55
StephaneLenclud@9
    56
            // We should get 4 entries:
StephaneLenclud@9
    57
            // - Category
StephaneLenclud@9
    58
            // - Country
StephaneLenclud@9
    59
            // - HD/SD TV
StephaneLenclud@9
    60
            // - Free/Pay TV
StephaneLenclud@9
    61
            CQ properties = dom.Find(".standart2");
StephaneLenclud@9
    62
            channel.Category = WebUtility.HtmlDecode(properties[0].InnerText).Trim();
StephaneLenclud@9
    63
            channel.Country = WebUtility.HtmlDecode(properties[1].InnerText).Trim();
StephaneLenclud@9
    64
StephaneLenclud@9
    65
            return channel;
StephaneLenclud@9
    66
        }
StephaneLenclud@9
    67
StephaneLenclud@9
    68
StephaneLenclud@9
    69
        //*[@id="container"]/div[2]/table[3]/tbody/tr/td/table[2]/tbody/tr/td
StephaneLenclud@9
    70
        public static List<Channel> Parse(IProgress<ProgressReport> aProgress, List<Channel> aChannels, string aUrl, string aOrbitalPosition, bool aUseChannelIdForName = false, string aCategoryOverride = "")
StephaneLenclud@9
    71
        {
StephaneLenclud@9
    72
            //Create our list of channels
StephaneLenclud@9
    73
            List<Channel> channels = new List<Channel>();
StephaneLenclud@9
    74
            //To avoid duplicated name
StephaneLenclud@9
    75
            Dictionary<string, int> names = new Dictionary<string, int>();
StephaneLenclud@9
    76
StephaneLenclud@9
    77
            string satIndex = new WebClient().DownloadString(aUrl);
StephaneLenclud@9
    78
            //Debug.Write(satIndex);
StephaneLenclud@9
    79
StephaneLenclud@9
    80
            CQ dom = satIndex;
StephaneLenclud@9
    81
StephaneLenclud@9
    82
            CQ channelsTd = dom.Find(".freq1");
StephaneLenclud@9
    83
StephaneLenclud@9
    84
            ProgressReport report = new ProgressReport();
StephaneLenclud@9
    85
            report.Max = channelsTd.Count();
StephaneLenclud@9
    86
            report.Value = 0;
StephaneLenclud@9
    87
            aProgress.Report(report);
StephaneLenclud@9
    88
StephaneLenclud@9
    89
            foreach ( IDomObject td in channelsTd)
StephaneLenclud@9
    90
            {
StephaneLenclud@9
    91
                string channelUrl = "https://www.satindex.de" + td.FirstChild.GetAttribute("href");
StephaneLenclud@9
    92
StephaneLenclud@9
    93
                Channel channel = ParseChannel(channelUrl);
StephaneLenclud@9
    94
StephaneLenclud@9
    95
                //Make sure our channel name looks descent
StephaneLenclud@9
    96
                channel.Name = CleanChannelName(channel.Name);
StephaneLenclud@9
    97
                //Make sure the resulting name is unique to avoid having multiple tuning detail for a single channel
StephaneLenclud@9
    98
                if (names.ContainsKey(channel.Name))
StephaneLenclud@9
    99
                {
StephaneLenclud@9
   100
                    names[channel.Name]++;
StephaneLenclud@9
   101
                    channel.Name += " " + names[channel.Name];
StephaneLenclud@9
   102
                }
StephaneLenclud@9
   103
                else
StephaneLenclud@9
   104
                {
StephaneLenclud@9
   105
                    names.Add(channel.Name, 1);
StephaneLenclud@9
   106
                }
StephaneLenclud@9
   107
                
StephaneLenclud@9
   108
                // Add it to our collection
StephaneLenclud@9
   109
                channels.Add(channel);
StephaneLenclud@9
   110
                // Report progress
StephaneLenclud@9
   111
                report.Value++;
StephaneLenclud@9
   112
                aProgress.Report(report);
StephaneLenclud@9
   113
            }
StephaneLenclud@9
   114
StephaneLenclud@9
   115
            return channels;
StephaneLenclud@9
   116
StephaneLenclud@9
   117
StephaneLenclud@9
   118
            //Get all the Frequency tables in our page
StephaneLenclud@9
   119
            // Why is this not working? 
StephaneLenclud@9
   120
            //CQ sats = dom["#container > div:nth-child(2) > table:nth-child(16) > tbody > tr > td > table:nth-child(8) > tbody > tr > td > table"];
StephaneLenclud@9
   121
            // As a workaround we did the following
StephaneLenclud@9
   122
            CQ sats = dom["#container"]["div:nth-child(2)"]["table:nth-child(16)"]["tbody"]["tr"]["td"]["table:nth-child(8)"]["tbody"]["tr"]["td"]["table"];
StephaneLenclud@9
   123
StephaneLenclud@9
   124
            List<IDomObject> transponders = sats.ToList();
StephaneLenclud@9
   125
StephaneLenclud@9
   126
StephaneLenclud@9
   127
StephaneLenclud@9
   128
            foreach (IDomObject frq in transponders)
StephaneLenclud@9
   129
            {
StephaneLenclud@9
   130
                Channel common = new Channel();
StephaneLenclud@9
   131
StephaneLenclud@9
   132
                //Parse channel details
StephaneLenclud@9
   133
                //common.OrbitalPosition = aOrbitalPosition;
StephaneLenclud@9
   134
                //string wsm1 = WebUtility.HtmlDecode(frq.Cq().Find(".wsm1").Get(0).InnerText).Trim();
StephaneLenclud@9
   135
StephaneLenclud@9
   136
                /*
StephaneLenclud@9
   137
                common.Satellite = "Astra 19.2° East";
StephaneLenclud@9
   138
                common.Frequency = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(3)").Get(0).InnerText);
StephaneLenclud@9
   139
                common.Polarisation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(4)").Get(0).InnerText);
StephaneLenclud@9
   140
                common.Transponder = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(5) > a").Get(0).InnerText);
StephaneLenclud@9
   141
                common.Beam = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(6) > a").Get(0).InnerText);
StephaneLenclud@9
   142
                common.Standard = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(7)").Get(0).InnerText);
StephaneLenclud@9
   143
                common.Modulation = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(8)").Get(0).InnerText);
StephaneLenclud@9
   144
                common.SymbolRate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a").Get(0).InnerText);
StephaneLenclud@9
   145
                common.FEC = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(9) > a:nth-child(2)").Get(0).InnerText);
StephaneLenclud@9
   146
                try
StephaneLenclud@9
   147
                {
StephaneLenclud@9
   148
                    common.Provider = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10) > b").Get(0).InnerText);
StephaneLenclud@9
   149
                }
StephaneLenclud@9
   150
                catch (Exception)
StephaneLenclud@9
   151
                {
StephaneLenclud@9
   152
                }
StephaneLenclud@9
   153
StephaneLenclud@9
   154
                common.Bitrate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10)").Get(0).InnerText);
StephaneLenclud@9
   155
                if (common.Bitrate.Substring(0, ", ".Length) == ", ")
StephaneLenclud@9
   156
                {
StephaneLenclud@9
   157
                    common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length);
StephaneLenclud@9
   158
                }
StephaneLenclud@9
   159
                //
StephaneLenclud@9
   160
                common.NetworkID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(11)").Get(0).InnerText);
StephaneLenclud@9
   161
                //common.NetworkID = common.NetworkID.Substring("NID:".Length, common.NetworkID.Length - "NID:".Length);
StephaneLenclud@9
   162
                //
StephaneLenclud@9
   163
                common.TransponderID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(12)").Get(0).InnerText);
StephaneLenclud@9
   164
                //common.TransponderID = common.TransponderID.Substring("TID:".Length, common.TransponderID.Length - "TID:".Length);
StephaneLenclud@9
   165
StephaneLenclud@9
   166
                //We got common properties for the coming channels
StephaneLenclud@9
   167
                //Debug.Write(common.ToString());
StephaneLenclud@9
   168
StephaneLenclud@9
   169
                //Now get all the channels for that frequency
StephaneLenclud@9
   170
                //Channel common = new Channel();
StephaneLenclud@9
   171
                */
StephaneLenclud@9
   172
StephaneLenclud@9
   173
                CQ channelsTableRows = frq.Cq().Find("tbody").Children("tr");
StephaneLenclud@9
   174
StephaneLenclud@9
   175
StephaneLenclud@9
   176
                //CQ channelsDiv = frq.Cq().Next("div");
StephaneLenclud@9
   177
                //CQ channelsTableRows = channelsDiv.Find("table.fl > tbody").Children("tr");
StephaneLenclud@9
   178
StephaneLenclud@9
   179
                foreach (IDomObject row in channelsTableRows)
StephaneLenclud@9
   180
                {
StephaneLenclud@9
   181
                    Channel channel = new Channel();
StephaneLenclud@9
   182
                    //Initialize this channel with common properties on this frequency
StephaneLenclud@9
   183
                    channel.Copy(common);
StephaneLenclud@9
   184
StephaneLenclud@9
   185
                    //Try and parse channel name
StephaneLenclud@9
   186
                    CQ cqChannelName = row.Cq().Find("td:nth-child(3) > a");
StephaneLenclud@9
   187
                    if (cqChannelName.Length == 0)
StephaneLenclud@9
   188
                    {
StephaneLenclud@9
   189
                        cqChannelName = row.Cq().Find("td:nth-child(3) > i");
StephaneLenclud@9
   190
                        if (cqChannelName.Length == 0)
StephaneLenclud@9
   191
                        {
StephaneLenclud@9
   192
                            //Can't get channel name
StephaneLenclud@9
   193
                            Debug.Write("WARNING: Can't find channel name! Skipping this channel");
StephaneLenclud@9
   194
                            continue;
StephaneLenclud@9
   195
                        }
StephaneLenclud@9
   196
                    }
StephaneLenclud@9
   197
StephaneLenclud@9
   198
                    string channelName = "";
StephaneLenclud@9
   199
                    if (cqChannelName.Get(0).HasAttribute("title") && aUseChannelIdForName)
StephaneLenclud@9
   200
                    {
StephaneLenclud@9
   201
                        //We want to use the channel ID
StephaneLenclud@9
   202
                        channelName = cqChannelName.Get(0).GetAttribute("title");
StephaneLenclud@9
   203
                    }
StephaneLenclud@9
   204
                    else
StephaneLenclud@9
   205
                    {
StephaneLenclud@9
   206
                        channelName = cqChannelName.Get(0).InnerText;
StephaneLenclud@9
   207
                    }
StephaneLenclud@9
   208
StephaneLenclud@9
   209
                    //Decode HTML
StephaneLenclud@9
   210
                    channel.Name = WebUtility.HtmlDecode(channelName);
StephaneLenclud@9
   211
                    //Convert from default encoding to UTF8
StephaneLenclud@9
   212
                    //We spend a lot of time trying to get this right until we found our answer in the following thread.
StephaneLenclud@9
   213
                    //http://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c
StephaneLenclud@9
   214
                    byte[] bytes = Encoding.Default.GetBytes(channel.Name);
StephaneLenclud@9
   215
                    channel.Name = Encoding.UTF8.GetString(bytes);
StephaneLenclud@9
   216
StephaneLenclud@9
   217
StephaneLenclud@9
   218
StephaneLenclud@9
   219
                    if (channel.Name == "Name" || channel.Name == "Sorted by name")
StephaneLenclud@9
   220
                    {
StephaneLenclud@9
   221
                        //Skipping header rows
StephaneLenclud@9
   222
                        continue;
StephaneLenclud@9
   223
                    }
StephaneLenclud@9
   224
StephaneLenclud@9
   225
                    //Make sure our channel name looks descent
StephaneLenclud@9
   226
                    channel.Name = CleanChannelName(channel.Name);
StephaneLenclud@9
   227
                    //Make sure the resulting name is unique to avoid having multiple tuning detail for a single channel
StephaneLenclud@9
   228
                    if (names.ContainsKey(channel.Name))
StephaneLenclud@9
   229
                    {
StephaneLenclud@9
   230
                        names[channel.Name]++;
StephaneLenclud@9
   231
                        channel.Name += " " + names[channel.Name];
StephaneLenclud@9
   232
                    }
StephaneLenclud@9
   233
                    else
StephaneLenclud@9
   234
                    {
StephaneLenclud@9
   235
                        names.Add(channel.Name, 1);
StephaneLenclud@9
   236
                    }
StephaneLenclud@9
   237
StephaneLenclud@9
   238
                    //
StephaneLenclud@9
   239
                    //We don't want channels we already have
StephaneLenclud@9
   240
                    Channel existingChannel = aChannels.Find(c => c.Name == channel.Name);
StephaneLenclud@9
   241
                    if (existingChannel != null)
StephaneLenclud@9
   242
                    {
StephaneLenclud@9
   243
                        continue;
StephaneLenclud@9
   244
                    }
StephaneLenclud@9
   245
StephaneLenclud@9
   246
StephaneLenclud@9
   247
                    //So we have a channel name get the other properties then
StephaneLenclud@9
   248
                    channel.Country = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(4)").Get(0).InnerText).Trim();
StephaneLenclud@9
   249
                    channel.Category = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(5)").Get(0).InnerText).Trim();
StephaneLenclud@9
   250
                    if (channel.Category == "")
StephaneLenclud@9
   251
                    {
StephaneLenclud@9
   252
                        channel.Category = "Other";
StephaneLenclud@9
   253
                    }
StephaneLenclud@9
   254
StephaneLenclud@9
   255
                    //Override category if needed
StephaneLenclud@9
   256
                    if (aCategoryOverride != "")
StephaneLenclud@9
   257
                    {
StephaneLenclud@9
   258
                        channel.Category = aCategoryOverride;
StephaneLenclud@9
   259
                    }
StephaneLenclud@9
   260
StephaneLenclud@9
   261
                    //Skip the packages
StephaneLenclud@9
   262
                    //Skip the encryptions
StephaneLenclud@9
   263
                    channel.SID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(8)").Get(0).InnerText).Trim();
StephaneLenclud@9
   264
                    channel.VPID = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(9)").Get(0).InnerText).Trim();
StephaneLenclud@9
   265
                    //Skip audios
StephaneLenclud@9
   266
                    channel.PMT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim();
StephaneLenclud@9
   267
                    channel.PCR = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim();
StephaneLenclud@9
   268
                    channel.TXT = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(11)").Get(0).InnerText).Trim();
StephaneLenclud@9
   269
StephaneLenclud@9
   270
                    //Append that new channel to our list
StephaneLenclud@9
   271
                    channels.Add(channel);
StephaneLenclud@9
   272
StephaneLenclud@9
   273
                    //Show it in debug output
StephaneLenclud@9
   274
                    Debug.Write(channel);
StephaneLenclud@9
   275
                } //For each channel
StephaneLenclud@9
   276
            } //For each frequency
StephaneLenclud@9
   277
StephaneLenclud@9
   278
            return channels;
StephaneLenclud@9
   279
        }
StephaneLenclud@9
   280
StephaneLenclud@9
   281
        //
StephaneLenclud@9
   282
        public static string CleanChannelName(string aName)
StephaneLenclud@9
   283
        {
StephaneLenclud@9
   284
            aName = aName.Trim();
StephaneLenclud@9
   285
            string[] remove = { " Germany", " Deutschland", " (Germany)", " (Deutschland)" };
StephaneLenclud@9
   286
StephaneLenclud@9
   287
            foreach (string item in remove)
StephaneLenclud@9
   288
            {
StephaneLenclud@9
   289
                //if (aName.EndsWith(item))
StephaneLenclud@9
   290
                if (aName.Contains(item))
StephaneLenclud@9
   291
                {
StephaneLenclud@9
   292
                    aName = aName.Substring(0, aName.LastIndexOf(item));
StephaneLenclud@9
   293
                    break; //only allow one match at most
StephaneLenclud@9
   294
                }
StephaneLenclud@9
   295
            }
StephaneLenclud@9
   296
StephaneLenclud@9
   297
            string[] removePrefix = { "Id: " };
StephaneLenclud@9
   298
StephaneLenclud@9
   299
            foreach (string item in removePrefix)
StephaneLenclud@9
   300
            {
StephaneLenclud@9
   301
                if (aName.StartsWith(item))
StephaneLenclud@9
   302
                {
StephaneLenclud@9
   303
                    aName = aName.Substring(item.Length, aName.Length - item.Length);
StephaneLenclud@9
   304
                    break; //only allow one match at most
StephaneLenclud@9
   305
                }
StephaneLenclud@9
   306
            }
StephaneLenclud@9
   307
StephaneLenclud@9
   308
StephaneLenclud@9
   309
StephaneLenclud@9
   310
            aName = aName.Trim();
StephaneLenclud@9
   311
            return aName;
StephaneLenclud@9
   312
        }
StephaneLenclud@9
   313
StephaneLenclud@9
   314
        //
StephaneLenclud@9
   315
        public static List<Channel> CleanChannelList(List<Channel> aChannels)
StephaneLenclud@9
   316
        {
StephaneLenclud@9
   317
            //Create our list of channels
StephaneLenclud@9
   318
            List<Channel> channels = new List<Channel>();
StephaneLenclud@9
   319
StephaneLenclud@9
   320
            foreach (Channel channel in aChannels)
StephaneLenclud@9
   321
            {
StephaneLenclud@9
   322
                Channel hdChannel = aChannels.Find(c => c.Name == channel.Name + " HD");
StephaneLenclud@9
   323
                if (hdChannel == null
StephaneLenclud@9
   324
                    && !(channel.Name.Contains("Bundesliga") && !channel.Name.Contains("HD")) //We don't want non HD bundesliga
StephaneLenclud@9
   325
                    && !(channel.Name.StartsWith("Sky Sport") && !channel.Name.Contains("HD")) //We don't want non HD Sky Sport
StephaneLenclud@9
   326
                    )
StephaneLenclud@9
   327
                {
StephaneLenclud@9
   328
StephaneLenclud@9
   329
                    if (channel.Category == "Allgemein"
StephaneLenclud@9
   330
                        && channel.Name.Contains("Sky"))
StephaneLenclud@9
   331
                    {
StephaneLenclud@9
   332
                        channel.Category = "Movies & Series";
StephaneLenclud@9
   333
                    }
StephaneLenclud@9
   334
StephaneLenclud@9
   335
                    if (channel.Name == "SYFY HD")
StephaneLenclud@9
   336
                    {
StephaneLenclud@9
   337
                        channel.Category = "Movies & Series";
StephaneLenclud@9
   338
                    }
StephaneLenclud@9
   339
StephaneLenclud@9
   340
                    // Patch Bundesliga channel names by removing Sport, cause they are way too long names
StephaneLenclud@9
   341
                    if (channel.Name.Contains("Bundesliga"))
StephaneLenclud@9
   342
                    {
StephaneLenclud@9
   343
                        channel.Name = channel.Name.Replace("Sport ", "");
StephaneLenclud@9
   344
                    }
StephaneLenclud@9
   345
StephaneLenclud@9
   346
                    //Patch some missing or bad categories
StephaneLenclud@9
   347
                    if (channel.Name.Contains("Bundesliga")
StephaneLenclud@9
   348
                        || channel.Name.Contains("Sport"))
StephaneLenclud@9
   349
                    {
StephaneLenclud@9
   350
                        channel.Category = "Sport";
StephaneLenclud@9
   351
                    }
StephaneLenclud@9
   352
StephaneLenclud@9
   353
                    if (channel.Name.Contains("Sky Select"))
StephaneLenclud@9
   354
                    {
StephaneLenclud@9
   355
                        channel.Category = "Pay per view";
StephaneLenclud@9
   356
                    }
StephaneLenclud@9
   357
StephaneLenclud@9
   358
                    if (channel.Name.Contains("TNT")
StephaneLenclud@9
   359
                        || channel.Name.Contains("13th"))
StephaneLenclud@9
   360
                    {
StephaneLenclud@9
   361
                        channel.Category = "Movies & Series";
StephaneLenclud@9
   362
                    }
StephaneLenclud@9
   363
StephaneLenclud@9
   364
                    if (channel.Category =="Kinderprogramm")
StephaneLenclud@9
   365
                    {
StephaneLenclud@9
   366
                        channel.Category = "Kids";
StephaneLenclud@9
   367
                    }
StephaneLenclud@9
   368
StephaneLenclud@9
   369
                    if (channel.Category == "Hinweistafel")
StephaneLenclud@9
   370
                    {
StephaneLenclud@9
   371
                        channel.Category = "General";
StephaneLenclud@9
   372
                    }
StephaneLenclud@9
   373
StephaneLenclud@9
   374
                    if (channel.Name.StartsWith("Sky Atlantic")
StephaneLenclud@9
   375
                        || channel.Name.StartsWith("SyFy")
StephaneLenclud@9
   376
                        || channel.Name.StartsWith("Fox"))
StephaneLenclud@9
   377
                    {
StephaneLenclud@9
   378
                        channel.Category = "Series";
StephaneLenclud@9
   379
                    }
StephaneLenclud@9
   380
StephaneLenclud@9
   381
                    //Collapse some categories
StephaneLenclud@9
   382
                    if (channel.Category == "Entertainment"                        
StephaneLenclud@9
   383
                        || channel.Category == "Kultur"
StephaneLenclud@9
   384
                        || channel.Category == "Verschiedenes")
StephaneLenclud@9
   385
                    {
StephaneLenclud@9
   386
                        channel.Category = "General";
StephaneLenclud@9
   387
                    }
StephaneLenclud@9
   388
StephaneLenclud@9
   389
                    if (channel.Category == "Musik"
StephaneLenclud@9
   390
                        || channel.Name.Contains("Music")
StephaneLenclud@9
   391
                        || channel.Name.Contains("Musik"))
StephaneLenclud@9
   392
                    {
StephaneLenclud@9
   393
                        channel.Category = "Music";
StephaneLenclud@9
   394
                    }
StephaneLenclud@9
   395
StephaneLenclud@9
   396
StephaneLenclud@9
   397
StephaneLenclud@9
   398
                    if (channel.Category == "Porn"
StephaneLenclud@9
   399
                        || channel.Category == "Erotik"
StephaneLenclud@9
   400
                        || channel.Name.Contains("Blue Movie")
StephaneLenclud@9
   401
                        || Regex.IsMatch(channel.Name,"Sex", RegexOptions.IgnoreCase)
StephaneLenclud@9
   402
                        || Regex.IsMatch(channel.Name, "Erotik", RegexOptions.IgnoreCase)
StephaneLenclud@9
   403
                        || Regex.IsMatch(channel.Name, "Girl", RegexOptions.IgnoreCase)
StephaneLenclud@9
   404
                        || Regex.IsMatch(channel.Name, "Eros", RegexOptions.IgnoreCase)
StephaneLenclud@9
   405
                        || Regex.IsMatch(channel.Name, "Gay", RegexOptions.IgnoreCase)
StephaneLenclud@9
   406
                        || Regex.IsMatch(channel.Name, "frauen", RegexOptions.IgnoreCase)
StephaneLenclud@9
   407
                        || Regex.IsMatch(channel.Name, "Maenner", RegexOptions.IgnoreCase)
StephaneLenclud@9
   408
                        || Regex.IsMatch(channel.Name, "bunny", RegexOptions.IgnoreCase)
StephaneLenclud@9
   409
                        || Regex.IsMatch(channel.Name, "date", RegexOptions.IgnoreCase)
StephaneLenclud@9
   410
                        )
StephaneLenclud@9
   411
                    {
StephaneLenclud@9
   412
                        channel.Category = "Erotic";
StephaneLenclud@9
   413
                    }
StephaneLenclud@9
   414
StephaneLenclud@9
   415
                    if (channel.Category == "Presentations"
StephaneLenclud@9
   416
                        || channel.Category == "Nachrichten")
StephaneLenclud@9
   417
                    {
StephaneLenclud@9
   418
                        channel.Category = "News";
StephaneLenclud@9
   419
                    }
StephaneLenclud@9
   420
StephaneLenclud@9
   421
                    if (channel.Category == "History"
StephaneLenclud@9
   422
                        || channel.Category == "Dokus / Reportagen")
StephaneLenclud@9
   423
                    {
StephaneLenclud@9
   424
                        channel.Category = "Documentaries";
StephaneLenclud@9
   425
                    }
StephaneLenclud@9
   426
StephaneLenclud@9
   427
                    if (channel.Category == "Travel"
StephaneLenclud@9
   428
                        || channel.Category == "Urlaub / Reisen")
StephaneLenclud@9
   429
                    {
StephaneLenclud@9
   430
                        channel.Category = "Documentaries";
StephaneLenclud@9
   431
                    }
StephaneLenclud@9
   432
StephaneLenclud@9
   433
StephaneLenclud@9
   434
                    if (channel.Category == "Lifestyle"
StephaneLenclud@9
   435
                        || channel.Category == "Allgemein"
StephaneLenclud@9
   436
                        || channel.Category == "Other"
StephaneLenclud@9
   437
                        || channel.Category == "Cultural")
StephaneLenclud@9
   438
                    {
StephaneLenclud@9
   439
                        channel.Category = "General";
StephaneLenclud@9
   440
                    }
StephaneLenclud@9
   441
StephaneLenclud@9
   442
                    if (channel.Category == "Movies"
StephaneLenclud@9
   443
                        || channel.Category == "Spielfilme")
StephaneLenclud@9
   444
                    {
StephaneLenclud@9
   445
                        channel.Category = "Movies & Series";
StephaneLenclud@9
   446
                    }
StephaneLenclud@9
   447
StephaneLenclud@9
   448
                    if (channel.Category == "Series")
StephaneLenclud@9
   449
                    {
StephaneLenclud@9
   450
                        channel.Category = "Movies & Series";
StephaneLenclud@9
   451
                    }
StephaneLenclud@9
   452
StephaneLenclud@9
   453
                    if (channel.Category == "Regional Programm")
StephaneLenclud@9
   454
                    {
StephaneLenclud@9
   455
                        channel.Category = "Regional";
StephaneLenclud@9
   456
                    }
StephaneLenclud@9
   457
StephaneLenclud@9
   458
                    //No corresponding HD channel, keep it then
StephaneLenclud@9
   459
                    channels.Add(channel);
StephaneLenclud@9
   460
                }
StephaneLenclud@9
   461
                else
StephaneLenclud@9
   462
                {
StephaneLenclud@9
   463
                    Debug.Write("WARNING: Found HD channel for " + channel.Name + ". Discarding it!\n");
StephaneLenclud@9
   464
                }
StephaneLenclud@9
   465
            }
StephaneLenclud@9
   466
StephaneLenclud@9
   467
            return channels;
StephaneLenclud@9
   468
        }
StephaneLenclud@8
   469
    }
StephaneLenclud@8
   470
}