# HG changeset patch # User StephaneLenclud # Date 1431722493 -7200 # Node ID 8372aa8d6292f6f70d202d4fb784f9cceca1d655 # Parent 01a00603ec28d2dabf5350d25e5a6b1feb1c980e Adding channel name clean up. Adding card mapping support but it's not working. diff -r 01a00603ec28 -r 8372aa8d6292 .editorconfig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.editorconfig Fri May 15 22:41:33 2015 +0200 @@ -0,0 +1,12 @@ +; Top-most EditorConfig file +root = true + +; Unix-style newlines +[*] +end_of_line = crlf + +; 4-column tab indentation +[*.cs] +indent_style = space +indent_size = 4 + diff -r 01a00603ec28 -r 8372aa8d6292 KingOfSat.cs --- a/KingOfSat.cs Fri May 15 17:28:51 2015 +0200 +++ b/KingOfSat.cs Fri May 15 22:41:33 2015 +0200 @@ -65,7 +65,7 @@ common.Bitrate = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(10)").Get(0).InnerText); if (common.Bitrate.Substring(0, ", ".Length) == ", ") { - common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length); + common.Bitrate = common.Bitrate.Substring(", ".Length, common.Bitrate.Length - ", ".Length); } // common.NetworkID = WebUtility.HtmlDecode(frq.Cq().Find("tbody > tr > td:nth-child(11)").Get(0).InnerText); @@ -109,6 +109,9 @@ continue; } + //Make sure our channel name looks descent + channel.Name = CleanChannelName(channel.Name); + //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(); @@ -131,5 +134,23 @@ return channels; } + + // + public static string CleanChannelName(string aName) + { + aName.Trim(); + string[] remove = { "Germany", "Deutschland", "(Germany)", "(Deutschland)" }; + + foreach (string item in remove) + { + if (aName.EndsWith(item)) + { + aName = aName.Substring(0, aName.LastIndexOf(item)); + break; //only allow one match at most + } + } + aName.Trim(); + return aName; + } } } diff -r 01a00603ec28 -r 8372aa8d6292 MainForm.cs --- a/MainForm.cs Fri May 15 17:28:51 2015 +0200 +++ b/MainForm.cs Fri May 15 22:41:33 2015 +0200 @@ -24,8 +24,17 @@ private void buttonGenerate_Click(object sender, EventArgs e) { + //List channels = new List(); List channels=KingOfSat.Parse("http://en.kingofsat.net/pack-skygermany.php","19.2°E"); - MediaPortal.Export(channels,"channels.xml"); + + //Declare tuner cards so that we don't need to create mapping manually after import + List tuners = new List() + { + "3", + "4" + }; + + MediaPortal.Export(channels, tuners, "channels.xml",false); } } } diff -r 01a00603ec28 -r 8372aa8d6292 MediaPortal.cs --- a/MediaPortal.cs Fri May 15 17:28:51 2015 +0200 +++ b/MediaPortal.cs Fri May 15 22:41:33 2015 +0200 @@ -144,7 +144,7 @@ } - public static void Export(List aChannels, string aFileName) + public static void Export(List aChannels, List aTunerCards, string aFileName, bool aAddMapping) { XmlDocument xmlDoc = new XmlDocument(); XmlNode rootElement = xmlDoc.CreateElement("tvserver"); @@ -155,6 +155,7 @@ rootElement.AppendChild(nodechannels); int channelId = 0; + int channelMapId = 0; foreach (Channel channel in aChannels) { channelId++; @@ -163,14 +164,29 @@ AddAttribute(nodechannel, "IdChannel", channelId); AddAttribute(nodechannel, "IsRadio", "False"); AddAttribute(nodechannel, "IsTv", "True"); - AddAttribute(nodechannel, "LastGrabTime", "2000-1-1 0:0:0"); + AddAttribute(nodechannel, "LastGrabTime", "2000-1-1 0:0:0"); //AddAttribute(nodechannel, "SortOrder", channel.SortOrder); - //sAddAttribute(nodechannel, "TimesWatched", "0"); - AddAttribute(nodechannel, "TotalTimeWatched", "2000-1-1 0:0:0"); + //sAddAttribute(nodechannel, "TimesWatched", "0"); + AddAttribute(nodechannel, "TotalTimeWatched", "2000-1-1 0:0:0"); AddAttribute(nodechannel, "VisibleInGuide", "True"); AddAttribute(nodechannel, "DisplayName", channel.Name); AddAttribute(nodechannel, "ChannelNumber", channelId); + if (aAddMapping) + { + //I don't think we can get mapping to work without having corresponding server and card definition elements + XmlNode nodeMaps = xmlDoc.CreateElement("mappings"); + foreach (string tuner in aTunerCards) + { + channelMapId++; + XmlNode nodeMap = xmlDoc.CreateElement("map"); + AddAttribute(nodeMap, "IdCard", tuner); + AddAttribute(nodeMap, "IdChannel", channelId); + AddAttribute(nodeMap, "IdChannelMap", channelMapId); + nodeMaps.AppendChild(nodeMap); + } + nodechannel.AppendChild(nodeMaps); + } XmlNode nodeTuningDetails = xmlDoc.CreateElement("TuningDetails"); XmlNode nodeTune = xmlDoc.CreateElement("tune");