Fixing character encoding issues.
authorStephaneLenclud
Sun, 17 May 2015 19:36:48 +0200
changeset 63061de2306d9
parent 5 29ccfbf98e54
child 7 bf908f6c7758
Fixing character encoding issues.
KingOfSat.cs
     1.1 --- a/KingOfSat.cs	Sat May 16 01:31:32 2015 +0200
     1.2 +++ b/KingOfSat.cs	Sun May 17 19:36:48 2015 +0200
     1.3 @@ -2,7 +2,6 @@
     1.4  using System.Collections.Generic;
     1.5  using System.Linq;
     1.6  using System.Text;
     1.7 -using System.Threading.Tasks;
     1.8  using CsQuery;
     1.9  using System.Diagnostics;
    1.10  using System.Net;
    1.11 @@ -106,10 +105,13 @@
    1.12                      }
    1.13  
    1.14                      string channelNameInnerText = cqChannelName.Get(0).InnerText;
    1.15 -                    channel.Name = WebUtility.HtmlDecode(channelNameInnerText).Trim();
    1.16 -                    //Encoding decoder = Encoding.UTF8;
    1.17 -                    //channel.Name = decoder.GetString(channel.Name);
    1.18 -                    //channel.Name = channelNameInnerText.Trim(); //Make up your mind :)
    1.19 +                    //We spend a lot of time trying to get this right until we found our answer in the following thread.
    1.20 +                    //http://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c
    1.21 +                    //Decode HTML
    1.22 +                    channel.Name = WebUtility.HtmlDecode(channelNameInnerText);
    1.23 +                    //Convert from default encoding to UTF8
    1.24 +                    byte[] bytes = Encoding.Default.GetBytes(channel.Name);
    1.25 +                    channel.Name = Encoding.UTF8.GetString(bytes);
    1.26                      if (channel.Name == "Name")
    1.27                      {
    1.28                          //Skipping header rows
    1.29 @@ -122,7 +124,7 @@
    1.30                      if (names.ContainsKey(channel.Name))
    1.31                      {
    1.32                          names[channel.Name]++;
    1.33 -                        channel.Name += " " + names[channel.Name]; 
    1.34 +                        channel.Name += " " + names[channel.Name];
    1.35                      }
    1.36                      else
    1.37                      {
    1.38 @@ -132,7 +134,7 @@
    1.39                      //
    1.40                      //We don't want channels we already have
    1.41                      Channel existingChannel = aChannels.Find(c => c.Name == channel.Name);
    1.42 -                    if (existingChannel!=null)
    1.43 +                    if (existingChannel != null)
    1.44                      {
    1.45                          continue;
    1.46                      }
    1.47 @@ -141,7 +143,7 @@
    1.48                      //So we have a channel name get the other properties then
    1.49                      channel.Country = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(4)").Get(0).InnerText).Trim();
    1.50                      channel.Category = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(5)").Get(0).InnerText).Trim();
    1.51 -                    if (channel.Category=="")
    1.52 +                    if (channel.Category == "")
    1.53                      {
    1.54                          channel.Category = "Other";
    1.55                      }
    1.56 @@ -193,7 +195,7 @@
    1.57              foreach (Channel channel in aChannels)
    1.58              {
    1.59                  Channel hdChannel = aChannels.Find(c => c.Name == channel.Name + " HD");
    1.60 -                if (hdChannel==null
    1.61 +                if (hdChannel == null
    1.62                      && !(channel.Name.Contains("Bundesliga") && !channel.Name.Contains("HD")) //We don't want non HD bundesliga
    1.63                      && !(channel.Name.StartsWith("Sky Sport") && !channel.Name.Contains("HD")) //We don't want non HD Sky Sport
    1.64                      )