First MP export draft.
1.1 --- a/MainForm.cs Fri May 15 13:23:52 2015 +0200
1.2 +++ b/MainForm.cs Fri May 15 15:16:18 2015 +0200
1.3 @@ -25,6 +25,7 @@
1.4 private void buttonGenerate_Click(object sender, EventArgs e)
1.5 {
1.6 List<Channel> channels=KingOfSat.Parse("http://en.kingofsat.net/pack-skygermany.php");
1.7 + MediaPortal.Export(channels,"channels.xml");
1.8 }
1.9 }
1.10 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/MediaPortal.cs Fri May 15 15:16:18 2015 +0200
2.3 @@ -0,0 +1,246 @@
2.4 +using System;
2.5 +using System.Collections.Generic;
2.6 +using System.Diagnostics;
2.7 +using System.Linq;
2.8 +using System.Text;
2.9 +using System.Threading.Tasks;
2.10 +using System.Xml;
2.11 +
2.12 +namespace SatChanGen
2.13 +{
2.14 + class MediaPortal
2.15 + {
2.16 +
2.17 + public static string Polarisation(Channel aChannel)
2.18 + {
2.19 + switch (aChannel.Polarisation)
2.20 + {
2.21 + case "H":
2.22 + return "1";
2.23 + case "V":
2.24 + return "2";
2.25 + case "L": //Check that on KingOfSat
2.26 + return "3";
2.27 + case "R": //Check that on KingOfSat
2.28 + return "4";
2.29 +
2.30 + default:
2.31 + {
2.32 + Debug.Write("WARNING: Unknown Polarisation " + aChannel.Polarisation + " for " + aChannel.Name + "\n");
2.33 + return "-1";
2.34 + }
2.35 + }
2.36 +
2.37 + /*
2.38 + "Not Set",
2.39 + "Not Defined",
2.40 + "Horizontal",
2.41 + "Vertical",
2.42 + "Circular Left",
2.43 + "Circular Right"
2.44 + */
2.45 + }
2.46 +
2.47 + public static string Modulation(Channel aChannel)
2.48 + {
2.49 + //Those can be worked out from TvLibrary FormDVBSTuningDetail.Designer.cs
2.50 +
2.51 + switch (aChannel.Modulation)
2.52 + {
2.53 + case "QPSK":
2.54 + return "20";
2.55 + case "8PSK":
2.56 + return "27";
2.57 + default:
2.58 + {
2.59 + Debug.Write("WARNING: Unknown modulation " + aChannel.Modulation + " for " + aChannel.Name + "\n");
2.60 + return "-1";
2.61 + }
2.62 + }
2.63 +
2.64 +
2.65 + /*
2.66 + "Not Set",
2.67 + "Not Defined",
2.68 + "16 QAM",
2.69 + "32 QAM",
2.70 + "64 QAM",
2.71 + "80 QAM",
2.72 + "96 QAM",
2.73 + "112 QAM",
2.74 + "128 QAM",
2.75 + "160 QAM",
2.76 + "192 QAM",
2.77 + "224 QAM",
2.78 + "256 QAM",
2.79 + "320 QAM",
2.80 + "384 QAM",
2.81 + "448 QAM",
2.82 + "512 QAM",
2.83 + "640 QAM",
2.84 + "768 QAM",
2.85 + "896 QAM",
2.86 + "1024 QAM",
2.87 + "QPSK",
2.88 + "BPSK",
2.89 + "OQPSK",
2.90 + "8 VSB",
2.91 + "16 VSB",
2.92 + "Analog Amplitude",
2.93 + "Analog Frequency",
2.94 + "8 PSK",
2.95 + "RF",
2.96 + "16 APSK",
2.97 + "32 APSK",
2.98 + "QPSK2 (DVB-S2)",
2.99 + "8 PSK2 (DVB-S2)",
2.100 + "DirectTV"
2.101 + */
2.102 + }
2.103 +
2.104 +
2.105 + public static string FEC(Channel aChannel)
2.106 + {
2.107 + //Those can be worked out from TvLibrary FormDVBSTuningDetail.Designer.cs
2.108 +
2.109 + switch (aChannel.FEC)
2.110 + {
2.111 + case "1/2":
2.112 + return "1";
2.113 + case "2/3":
2.114 + return "2";
2.115 + case "3/4":
2.116 + return "3";
2.117 + case "3/5":
2.118 + return "4";
2.119 + case "4/5":
2.120 + return "5";
2.121 + case "5/6":
2.122 + return "6";
2.123 + case "5/11":
2.124 + return "7";
2.125 + case "7/8":
2.126 + return "8";
2.127 + case "1/4":
2.128 + return "9";
2.129 + case "1/3":
2.130 + return "10";
2.131 + case "2/5":
2.132 + return "11";
2.133 + case "6/7":
2.134 + return "12";
2.135 + case "8/9":
2.136 + return "13";
2.137 + case "9/10":
2.138 + return "14";
2.139 +
2.140 + default:
2.141 + {
2.142 + Debug.Write("WARNING: Unknown FEC " + aChannel.FEC + " for " + aChannel.Name + "\n");
2.143 + return "-1";
2.144 + }
2.145 + }
2.146 +
2.147 +
2.148 + }
2.149 +
2.150 + public static void Export(List<Channel> aChannels, string aFileName)
2.151 + {
2.152 + XmlDocument xmlDoc = new XmlDocument();
2.153 + XmlNode rootElement = xmlDoc.CreateElement("tvserver");
2.154 + AddAttribute(rootElement, "version", "1.0");
2.155 + xmlDoc.AppendChild(rootElement);
2.156 + //Create our channel element
2.157 + XmlNode nodechannels = xmlDoc.CreateElement("channels");
2.158 + rootElement.AppendChild(nodechannels);
2.159 +
2.160 + int channelId = 0;
2.161 + foreach (Channel channel in aChannels)
2.162 + {
2.163 + channelId++;
2.164 + XmlNode nodechannel = xmlDoc.CreateElement("channel");
2.165 + AddAttribute(nodechannel, "GrabEpg", "True");
2.166 + AddAttribute(nodechannel, "IdChannel", channelId);
2.167 + AddAttribute(nodechannel, "IsRadio", "False");
2.168 + AddAttribute(nodechannel, "IsTv", "True");
2.169 + //AddAttribute(nodechannel, "LastGrabTime", channel.LastGrabTime);
2.170 + //AddAttribute(nodechannel, "SortOrder", channel.SortOrder);
2.171 + //AddAttribute(nodechannel, "TimesWatched", channel.TimesWatched);
2.172 + //AddAttribute(nodechannel, "TotalTimeWatched", channel.TotalTimeWatched);
2.173 + AddAttribute(nodechannel, "VisibleInGuide", "True");
2.174 + AddAttribute(nodechannel, "DisplayName", channel.Name);
2.175 + AddAttribute(nodechannel, "ChannelNumber", channelId);
2.176 +
2.177 +
2.178 + XmlNode nodeTuningDetails = xmlDoc.CreateElement("TuningDetails");
2.179 + XmlNode nodeTune = xmlDoc.CreateElement("tune");
2.180 + AddAttribute(nodeTune, "IdChannel", channelId);
2.181 + AddAttribute(nodeTune, "IdTuning", channelId);
2.182 + AddAttribute(nodeTune, "Bandwidth", "8"); //Weird
2.183 + AddAttribute(nodeTune, "ChannelNumber", "10000");
2.184 + AddAttribute(nodeTune, "ChannelType", "3"); //Bad hard coding, does it means DVB-S
2.185 + AddAttribute(nodeTune, "CountryId", "31"); //Is that Germany?
2.186 + AddAttribute(nodeTune, "Diseqc", "0"); //Disabled
2.187 + AddAttribute(nodeTune, "FreeToAir", "False"); //Can we get that from KingOfSat? Does it matter?
2.188 + AddAttribute(nodeTune, "Frequency", ((Int32)(Convert.ToDouble(channel.Frequency)*1000)).ToString());
2.189 + AddAttribute(nodeTune, "MajorChannel", "-1");
2.190 + AddAttribute(nodeTune, "MinorChannel", "-1");
2.191 + AddAttribute(nodeTune, "Modulation", Modulation(channel));
2.192 + AddAttribute(nodeTune, "Name", channel.Name);
2.193 + AddAttribute(nodeTune, "NetworkId", channel.NetworkID);
2.194 + AddAttribute(nodeTune, "PmtPid", channel.PMT);
2.195 + AddAttribute(nodeTune, "Polarisation", Polarisation(channel));
2.196 + AddAttribute(nodeTune, "Provider", channel.Provider); //Does that matter? Should really be SKY or CSAT
2.197 + AddAttribute(nodeTune, "ServiceId", channel.SID);
2.198 + AddAttribute(nodeTune, "SwitchingFrequency", "11700000"); //Does it matter?
2.199 + AddAttribute(nodeTune, "Symbolrate", channel.SymbolRate);
2.200 + AddAttribute(nodeTune, "TransportId", channel.TransponderID);
2.201 + AddAttribute(nodeTune, "TuningSource", "0"); //Is that needed?
2.202 + AddAttribute(nodeTune, "VideoSource", "0"); //Is that needed?
2.203 + AddAttribute(nodeTune, "AudioSource", "0"); //Is that needed?
2.204 + AddAttribute(nodeTune, "IsVCRSignal", "False");
2.205 + AddAttribute(nodeTune, "SatIndex", "-1");
2.206 + AddAttribute(nodeTune, "InnerFecRate", FEC(channel));
2.207 + AddAttribute(nodeTune, "Band", "0"); //Needed?
2.208 + AddAttribute(nodeTune, "Pilot", "-1");
2.209 + AddAttribute(nodeTune, "RollOff", "-1");
2.210 + AddAttribute(nodeTune, "Url", "");
2.211 + AddAttribute(nodeTune, "Bitrate", "0"); //Should we bother putting it in there?
2.212 + nodeTuningDetails.AppendChild(nodeTune);
2.213 +
2.214 + nodechannel.AppendChild(nodeTuningDetails);
2.215 +
2.216 + nodechannels.AppendChild(nodechannel);
2.217 + }
2.218 +
2.219 +
2.220 +
2.221 + xmlDoc.Save(aFileName);
2.222 + }
2.223 +
2.224 + private static void AddAttribute(XmlNode node, string tagName, string tagValue)
2.225 + {
2.226 + XmlAttribute attr = node.OwnerDocument.CreateAttribute(tagName);
2.227 + attr.InnerText = tagValue;
2.228 + node.Attributes.Append(attr);
2.229 + }
2.230 +
2.231 + private static void AddAttribute(XmlNode node, string tagName, int tagValue)
2.232 + {
2.233 + AddAttribute(node, tagName, tagValue.ToString());
2.234 + }
2.235 +
2.236 + // store DateTime Values as strings. Improves readability
2.237 + private static void AddAttribute(XmlNode node, string tagName, DateTime tagValue)
2.238 + {
2.239 + AddAttribute(node, tagName,
2.240 + String.Format("{0}-{1}-{2} {3}:{4}:{5}", tagValue.Year, tagValue.Month, tagValue.Day, tagValue.Hour,
2.241 + tagValue.Minute, tagValue.Second));
2.242 + }
2.243 +
2.244 + private static void AddAttribute(XmlNode node, string tagName, bool tagValue)
2.245 + {
2.246 + AddAttribute(node, tagName, tagValue.ToString());
2.247 + }
2.248 + }
2.249 +}
3.1 --- a/SatChanGen.csproj Fri May 15 13:23:52 2015 +0200
3.2 +++ b/SatChanGen.csproj Fri May 15 15:16:18 2015 +0200
3.3 @@ -48,6 +48,7 @@
3.4 </ItemGroup>
3.5 <ItemGroup>
3.6 <Compile Include="Channel.cs" />
3.7 + <Compile Include="MediaPortal.cs" />
3.8 <Compile Include="KingOfSat.cs" />
3.9 <Compile Include="MainForm.cs">
3.10 <SubType>Form</SubType>