# HG changeset patch # User StephaneLenclud # Date 1431884208 -7200 # Node ID 3061de2306d91ff681cccd18d9963d6e2cda81f5 # Parent 29ccfbf98e54c06851d9122f65d137c7f19a40fa Fixing character encoding issues. diff -r 29ccfbf98e54 -r 3061de2306d9 KingOfSat.cs --- a/KingOfSat.cs Sat May 16 01:31:32 2015 +0200 +++ b/KingOfSat.cs Sun May 17 19:36:48 2015 +0200 @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using CsQuery; using System.Diagnostics; using System.Net; @@ -106,10 +105,13 @@ } string channelNameInnerText = cqChannelName.Get(0).InnerText; - channel.Name = WebUtility.HtmlDecode(channelNameInnerText).Trim(); - //Encoding decoder = Encoding.UTF8; - //channel.Name = decoder.GetString(channel.Name); - //channel.Name = channelNameInnerText.Trim(); //Make up your mind :) + //We spend a lot of time trying to get this right until we found our answer in the following thread. + //http://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c + //Decode HTML + channel.Name = WebUtility.HtmlDecode(channelNameInnerText); + //Convert from default encoding to UTF8 + byte[] bytes = Encoding.Default.GetBytes(channel.Name); + channel.Name = Encoding.UTF8.GetString(bytes); if (channel.Name == "Name") { //Skipping header rows @@ -122,7 +124,7 @@ if (names.ContainsKey(channel.Name)) { names[channel.Name]++; - channel.Name += " " + names[channel.Name]; + channel.Name += " " + names[channel.Name]; } else { @@ -132,7 +134,7 @@ // //We don't want channels we already have Channel existingChannel = aChannels.Find(c => c.Name == channel.Name); - if (existingChannel!=null) + if (existingChannel != null) { continue; } @@ -141,7 +143,7 @@ //So we have a channel name get the other properties then channel.Country = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(4)").Get(0).InnerText).Trim(); channel.Category = WebUtility.HtmlDecode(row.Cq().Find("td:nth-child(5)").Get(0).InnerText).Trim(); - if (channel.Category=="") + if (channel.Category == "") { channel.Category = "Other"; } @@ -193,7 +195,7 @@ foreach (Channel channel in aChannels) { Channel hdChannel = aChannels.Find(c => c.Name == channel.Name + " HD"); - if (hdChannel==null + if (hdChannel == null && !(channel.Name.Contains("Bundesliga") && !channel.Name.Contains("HD")) //We don't want non HD bundesliga && !(channel.Name.StartsWith("Sky Sport") && !channel.Name.Contains("HD")) //We don't want non HD Sky Sport )