MediaPortal.cs
author StephaneLenclud
Fri, 15 May 2015 15:16:18 +0200
changeset 2 d73e99c5333c
child 3 01a00603ec28
permissions -rw-r--r--
First MP export draft.
StephaneLenclud@2
     1
using System;
StephaneLenclud@2
     2
using System.Collections.Generic;
StephaneLenclud@2
     3
using System.Diagnostics;
StephaneLenclud@2
     4
using System.Linq;
StephaneLenclud@2
     5
using System.Text;
StephaneLenclud@2
     6
using System.Threading.Tasks;
StephaneLenclud@2
     7
using System.Xml;
StephaneLenclud@2
     8
StephaneLenclud@2
     9
namespace SatChanGen
StephaneLenclud@2
    10
{
StephaneLenclud@2
    11
	class MediaPortal
StephaneLenclud@2
    12
	{
StephaneLenclud@2
    13
StephaneLenclud@2
    14
		public static string Polarisation(Channel aChannel)
StephaneLenclud@2
    15
		{
StephaneLenclud@2
    16
			switch (aChannel.Polarisation)
StephaneLenclud@2
    17
			{
StephaneLenclud@2
    18
				case "H":
StephaneLenclud@2
    19
					return "1";
StephaneLenclud@2
    20
				case "V":
StephaneLenclud@2
    21
					return "2";
StephaneLenclud@2
    22
				case "L": //Check that on KingOfSat
StephaneLenclud@2
    23
					return "3";
StephaneLenclud@2
    24
				case "R": //Check that on KingOfSat
StephaneLenclud@2
    25
					return "4";
StephaneLenclud@2
    26
StephaneLenclud@2
    27
				default:
StephaneLenclud@2
    28
					{
StephaneLenclud@2
    29
						Debug.Write("WARNING: Unknown Polarisation " + aChannel.Polarisation + " for " + aChannel.Name + "\n");
StephaneLenclud@2
    30
						return "-1";
StephaneLenclud@2
    31
					}
StephaneLenclud@2
    32
			}
StephaneLenclud@2
    33
StephaneLenclud@2
    34
			/*
StephaneLenclud@2
    35
			"Not Set",
StephaneLenclud@2
    36
            "Not Defined",
StephaneLenclud@2
    37
            "Horizontal",
StephaneLenclud@2
    38
            "Vertical",
StephaneLenclud@2
    39
            "Circular Left",
StephaneLenclud@2
    40
            "Circular Right"
StephaneLenclud@2
    41
			 */
StephaneLenclud@2
    42
		}
StephaneLenclud@2
    43
StephaneLenclud@2
    44
		public static string Modulation(Channel aChannel)
StephaneLenclud@2
    45
		{
StephaneLenclud@2
    46
			//Those can be worked out from TvLibrary FormDVBSTuningDetail.Designer.cs
StephaneLenclud@2
    47
StephaneLenclud@2
    48
			switch (aChannel.Modulation)
StephaneLenclud@2
    49
			{
StephaneLenclud@2
    50
				case "QPSK":
StephaneLenclud@2
    51
					return "20";
StephaneLenclud@2
    52
				case "8PSK":
StephaneLenclud@2
    53
					return "27";
StephaneLenclud@2
    54
				default:
StephaneLenclud@2
    55
				{
StephaneLenclud@2
    56
					Debug.Write("WARNING: Unknown modulation " + aChannel.Modulation + " for " + aChannel.Name + "\n");
StephaneLenclud@2
    57
					return "-1";
StephaneLenclud@2
    58
				}
StephaneLenclud@2
    59
			}
StephaneLenclud@2
    60
StephaneLenclud@2
    61
StephaneLenclud@2
    62
			/*
StephaneLenclud@2
    63
			"Not Set",
StephaneLenclud@2
    64
			"Not Defined",
StephaneLenclud@2
    65
			"16 QAM",
StephaneLenclud@2
    66
			"32 QAM",
StephaneLenclud@2
    67
			"64 QAM",
StephaneLenclud@2
    68
			"80 QAM",
StephaneLenclud@2
    69
			"96 QAM",
StephaneLenclud@2
    70
			"112 QAM",
StephaneLenclud@2
    71
			"128 QAM",
StephaneLenclud@2
    72
			"160 QAM",
StephaneLenclud@2
    73
			"192 QAM",
StephaneLenclud@2
    74
			"224 QAM",
StephaneLenclud@2
    75
			"256 QAM",
StephaneLenclud@2
    76
			"320 QAM",
StephaneLenclud@2
    77
			"384 QAM",
StephaneLenclud@2
    78
			"448 QAM",
StephaneLenclud@2
    79
			"512 QAM",
StephaneLenclud@2
    80
			"640 QAM",
StephaneLenclud@2
    81
			"768 QAM",
StephaneLenclud@2
    82
			"896 QAM",
StephaneLenclud@2
    83
			"1024 QAM",
StephaneLenclud@2
    84
			"QPSK",
StephaneLenclud@2
    85
			"BPSK",
StephaneLenclud@2
    86
			"OQPSK",
StephaneLenclud@2
    87
			"8 VSB",
StephaneLenclud@2
    88
			"16 VSB",
StephaneLenclud@2
    89
			"Analog Amplitude",
StephaneLenclud@2
    90
			"Analog Frequency",
StephaneLenclud@2
    91
			"8 PSK",
StephaneLenclud@2
    92
			"RF",
StephaneLenclud@2
    93
			"16 APSK",
StephaneLenclud@2
    94
			"32 APSK",
StephaneLenclud@2
    95
			"QPSK2 (DVB-S2)",
StephaneLenclud@2
    96
			"8 PSK2 (DVB-S2)",
StephaneLenclud@2
    97
			"DirectTV"
StephaneLenclud@2
    98
			 */
StephaneLenclud@2
    99
		}
StephaneLenclud@2
   100
StephaneLenclud@2
   101
StephaneLenclud@2
   102
		public static string FEC(Channel aChannel)
StephaneLenclud@2
   103
		{
StephaneLenclud@2
   104
			//Those can be worked out from TvLibrary FormDVBSTuningDetail.Designer.cs
StephaneLenclud@2
   105
StephaneLenclud@2
   106
			switch (aChannel.FEC)
StephaneLenclud@2
   107
			{
StephaneLenclud@2
   108
				case "1/2":
StephaneLenclud@2
   109
					return "1";
StephaneLenclud@2
   110
				case "2/3":
StephaneLenclud@2
   111
					return "2";
StephaneLenclud@2
   112
				case "3/4":
StephaneLenclud@2
   113
					return "3";
StephaneLenclud@2
   114
				case "3/5":
StephaneLenclud@2
   115
					return "4";
StephaneLenclud@2
   116
				case "4/5":
StephaneLenclud@2
   117
					return "5";
StephaneLenclud@2
   118
				case "5/6":
StephaneLenclud@2
   119
					return "6";
StephaneLenclud@2
   120
				case "5/11":
StephaneLenclud@2
   121
					return "7";
StephaneLenclud@2
   122
				case "7/8":
StephaneLenclud@2
   123
					return "8";
StephaneLenclud@2
   124
				case "1/4":
StephaneLenclud@2
   125
					return "9";
StephaneLenclud@2
   126
				case "1/3":
StephaneLenclud@2
   127
					return "10";
StephaneLenclud@2
   128
				case "2/5":
StephaneLenclud@2
   129
					return "11";
StephaneLenclud@2
   130
				case "6/7":
StephaneLenclud@2
   131
					return "12";
StephaneLenclud@2
   132
				case "8/9":
StephaneLenclud@2
   133
					return "13";
StephaneLenclud@2
   134
				case "9/10":
StephaneLenclud@2
   135
					return "14";
StephaneLenclud@2
   136
StephaneLenclud@2
   137
				default:
StephaneLenclud@2
   138
				{
StephaneLenclud@2
   139
					Debug.Write("WARNING: Unknown FEC " + aChannel.FEC + " for " + aChannel.Name + "\n");
StephaneLenclud@2
   140
					return "-1";
StephaneLenclud@2
   141
				}
StephaneLenclud@2
   142
			}
StephaneLenclud@2
   143
StephaneLenclud@2
   144
StephaneLenclud@2
   145
		}
StephaneLenclud@2
   146
StephaneLenclud@2
   147
		public static void Export(List<Channel> aChannels, string aFileName)
StephaneLenclud@2
   148
		{
StephaneLenclud@2
   149
			XmlDocument xmlDoc = new XmlDocument();
StephaneLenclud@2
   150
			XmlNode rootElement = xmlDoc.CreateElement("tvserver");			
StephaneLenclud@2
   151
			AddAttribute(rootElement, "version", "1.0");
StephaneLenclud@2
   152
			xmlDoc.AppendChild(rootElement);
StephaneLenclud@2
   153
			//Create our channel element
StephaneLenclud@2
   154
			XmlNode nodechannels = xmlDoc.CreateElement("channels");			
StephaneLenclud@2
   155
			rootElement.AppendChild(nodechannels);
StephaneLenclud@2
   156
StephaneLenclud@2
   157
			int channelId = 0;
StephaneLenclud@2
   158
			foreach (Channel channel in aChannels)
StephaneLenclud@2
   159
			{
StephaneLenclud@2
   160
				channelId++;
StephaneLenclud@2
   161
				XmlNode nodechannel = xmlDoc.CreateElement("channel");
StephaneLenclud@2
   162
				AddAttribute(nodechannel, "GrabEpg", "True");
StephaneLenclud@2
   163
				AddAttribute(nodechannel, "IdChannel", channelId);
StephaneLenclud@2
   164
				AddAttribute(nodechannel, "IsRadio", "False");
StephaneLenclud@2
   165
				AddAttribute(nodechannel, "IsTv", "True");
StephaneLenclud@2
   166
				//AddAttribute(nodechannel, "LastGrabTime", channel.LastGrabTime);
StephaneLenclud@2
   167
				//AddAttribute(nodechannel, "SortOrder", channel.SortOrder);
StephaneLenclud@2
   168
				//AddAttribute(nodechannel, "TimesWatched", channel.TimesWatched);
StephaneLenclud@2
   169
				//AddAttribute(nodechannel, "TotalTimeWatched", channel.TotalTimeWatched);
StephaneLenclud@2
   170
				AddAttribute(nodechannel, "VisibleInGuide", "True");
StephaneLenclud@2
   171
				AddAttribute(nodechannel, "DisplayName", channel.Name);
StephaneLenclud@2
   172
				AddAttribute(nodechannel, "ChannelNumber", channelId);
StephaneLenclud@2
   173
StephaneLenclud@2
   174
StephaneLenclud@2
   175
				XmlNode nodeTuningDetails = xmlDoc.CreateElement("TuningDetails");
StephaneLenclud@2
   176
				XmlNode nodeTune = xmlDoc.CreateElement("tune");
StephaneLenclud@2
   177
				AddAttribute(nodeTune, "IdChannel", channelId);
StephaneLenclud@2
   178
				AddAttribute(nodeTune, "IdTuning", channelId);
StephaneLenclud@2
   179
				AddAttribute(nodeTune, "Bandwidth", "8"); //Weird
StephaneLenclud@2
   180
				AddAttribute(nodeTune, "ChannelNumber", "10000");
StephaneLenclud@2
   181
				AddAttribute(nodeTune, "ChannelType", "3"); //Bad hard coding, does it means DVB-S
StephaneLenclud@2
   182
				AddAttribute(nodeTune, "CountryId", "31"); //Is that Germany?
StephaneLenclud@2
   183
				AddAttribute(nodeTune, "Diseqc", "0"); //Disabled
StephaneLenclud@2
   184
				AddAttribute(nodeTune, "FreeToAir", "False"); //Can we get that from KingOfSat? Does it matter?
StephaneLenclud@2
   185
				AddAttribute(nodeTune, "Frequency", ((Int32)(Convert.ToDouble(channel.Frequency)*1000)).ToString());
StephaneLenclud@2
   186
				AddAttribute(nodeTune, "MajorChannel", "-1");
StephaneLenclud@2
   187
				AddAttribute(nodeTune, "MinorChannel", "-1");
StephaneLenclud@2
   188
				AddAttribute(nodeTune, "Modulation", Modulation(channel));
StephaneLenclud@2
   189
				AddAttribute(nodeTune, "Name", channel.Name);
StephaneLenclud@2
   190
				AddAttribute(nodeTune, "NetworkId", channel.NetworkID);
StephaneLenclud@2
   191
				AddAttribute(nodeTune, "PmtPid", channel.PMT);
StephaneLenclud@2
   192
				AddAttribute(nodeTune, "Polarisation", Polarisation(channel));
StephaneLenclud@2
   193
				AddAttribute(nodeTune, "Provider", channel.Provider); //Does that matter? Should really be SKY or CSAT
StephaneLenclud@2
   194
				AddAttribute(nodeTune, "ServiceId", channel.SID);
StephaneLenclud@2
   195
				AddAttribute(nodeTune, "SwitchingFrequency", "11700000"); //Does it matter?
StephaneLenclud@2
   196
				AddAttribute(nodeTune, "Symbolrate", channel.SymbolRate);
StephaneLenclud@2
   197
				AddAttribute(nodeTune, "TransportId", channel.TransponderID);
StephaneLenclud@2
   198
				AddAttribute(nodeTune, "TuningSource", "0"); //Is that needed?
StephaneLenclud@2
   199
				AddAttribute(nodeTune, "VideoSource", "0"); //Is that needed?
StephaneLenclud@2
   200
				AddAttribute(nodeTune, "AudioSource", "0"); //Is that needed?
StephaneLenclud@2
   201
				AddAttribute(nodeTune, "IsVCRSignal", "False");
StephaneLenclud@2
   202
				AddAttribute(nodeTune, "SatIndex", "-1");
StephaneLenclud@2
   203
				AddAttribute(nodeTune, "InnerFecRate", FEC(channel));
StephaneLenclud@2
   204
				AddAttribute(nodeTune, "Band", "0"); //Needed?
StephaneLenclud@2
   205
				AddAttribute(nodeTune, "Pilot", "-1");
StephaneLenclud@2
   206
				AddAttribute(nodeTune, "RollOff", "-1");
StephaneLenclud@2
   207
				AddAttribute(nodeTune, "Url", "");
StephaneLenclud@2
   208
				AddAttribute(nodeTune, "Bitrate", "0"); //Should we bother putting it in there?
StephaneLenclud@2
   209
				nodeTuningDetails.AppendChild(nodeTune);
StephaneLenclud@2
   210
					
StephaneLenclud@2
   211
				nodechannel.AppendChild(nodeTuningDetails);
StephaneLenclud@2
   212
StephaneLenclud@2
   213
				nodechannels.AppendChild(nodechannel);				
StephaneLenclud@2
   214
			}
StephaneLenclud@2
   215
StephaneLenclud@2
   216
StephaneLenclud@2
   217
StephaneLenclud@2
   218
			xmlDoc.Save(aFileName);
StephaneLenclud@2
   219
		}
StephaneLenclud@2
   220
StephaneLenclud@2
   221
		private static void AddAttribute(XmlNode node, string tagName, string tagValue)
StephaneLenclud@2
   222
		{
StephaneLenclud@2
   223
			XmlAttribute attr = node.OwnerDocument.CreateAttribute(tagName);
StephaneLenclud@2
   224
			attr.InnerText = tagValue;
StephaneLenclud@2
   225
			node.Attributes.Append(attr);
StephaneLenclud@2
   226
		}
StephaneLenclud@2
   227
StephaneLenclud@2
   228
		private static void AddAttribute(XmlNode node, string tagName, int tagValue)
StephaneLenclud@2
   229
		{
StephaneLenclud@2
   230
			AddAttribute(node, tagName, tagValue.ToString());
StephaneLenclud@2
   231
		}
StephaneLenclud@2
   232
StephaneLenclud@2
   233
		// store DateTime Values as strings. Improves readability
StephaneLenclud@2
   234
		private static void AddAttribute(XmlNode node, string tagName, DateTime tagValue)
StephaneLenclud@2
   235
		{
StephaneLenclud@2
   236
			AddAttribute(node, tagName,
StephaneLenclud@2
   237
						 String.Format("{0}-{1}-{2} {3}:{4}:{5}", tagValue.Year, tagValue.Month, tagValue.Day, tagValue.Hour,
StephaneLenclud@2
   238
									   tagValue.Minute, tagValue.Second));
StephaneLenclud@2
   239
		}
StephaneLenclud@2
   240
StephaneLenclud@2
   241
		private static void AddAttribute(XmlNode node, string tagName, bool tagValue)
StephaneLenclud@2
   242
		{
StephaneLenclud@2
   243
			AddAttribute(node, tagName, tagValue.ToString());
StephaneLenclud@2
   244
		}
StephaneLenclud@2
   245
	}
StephaneLenclud@2
   246
}