diff --git a/ChanSort.Api/Model/ChannelList.cs b/ChanSort.Api/Model/ChannelList.cs index cb12524..1462a0d 100644 --- a/ChanSort.Api/Model/ChannelList.cs +++ b/ChanSort.Api/Model/ChannelList.cs @@ -134,6 +134,13 @@ namespace ChanSort.Api } #endregion + #region GetChannelsByNewOrder() + public IList GetChannelsByNewOrder() + { + return this.channels.OrderBy(c => c.NewProgramNr).ToList(); + } + #endregion + #region RemoveChannel() public void RemoveChannel(ChannelInfo channel) { diff --git a/ChanSort.Loader.VDR/ChanSort.Loader.VDR.csproj b/ChanSort.Loader.VDR/ChanSort.Loader.VDR.csproj new file mode 100644 index 0000000..14b1ee3 --- /dev/null +++ b/ChanSort.Loader.VDR/ChanSort.Loader.VDR.csproj @@ -0,0 +1,87 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {74A18C6F-09FF-413E-90D9-827066FA5B36} + Library + Properties + ChanSort.Loader.VDR + ChanSort.Loader.VDR + v4.0 + + + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + ..\Debug\ + DEBUG;TRACE + full + x86 + prompt + true + true + false + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + true + true + + + + + + + + + + + + + + + + + + + + + {DCCFFA08-472B-4D17-BB90-8F513FC01392} + ChanSort.Api + + + + + \ No newline at end of file diff --git a/ChanSort.Loader.VDR/Channels.cs b/ChanSort.Loader.VDR/Channels.cs new file mode 100644 index 0000000..76826b6 --- /dev/null +++ b/ChanSort.Loader.VDR/Channels.cs @@ -0,0 +1,330 @@ +using System; +using System.Collections.Generic; +using System.Text; +using ChanSort.Api; + +namespace ChanSort.Loader.VDR +{ + internal class Channels : ChannelInfo + { + private const int MAXAPIDS = 32; // audio + private const int MAXDPIDS = 16; // dolby (AC3 + DTS) + + public string confLine { get; private set; } + + private int vtype; + private int[] apids = new int[MAXAPIDS+1]; // list is zero-terminated + private int[] atypes = new int[MAXAPIDS + 1]; // list is zero-terminated + private string[] alangs = new string[MAXAPIDS]; + + private int[] dpids = new int[MAXDPIDS + 1]; // list is zero-terminated + private int[] dtypes = new int[MAXAPIDS + 1]; // list is zero-terminated + private string[] dlangs = new string[MAXDPIDS]; + + #region ctor() + internal Channels(int pos, String line, DataRoot dataRoot) + { + this.confLine = line; + this.RecordIndex = this.RecordOrder = this.OldProgramNr = pos+1; + + try + { + if (line[0] == ':') + { + this.Name = Convert.ToString(line.Split(':').GetValue(1)); + return; + } + + var fields = line.Split(':'); + + // field 0 - ChannelName[,ShotName][;ProviderName] + if (fields[0].IndexOf(',') >= 0 || fields[0].IndexOf(';') >= 0) + { + if (fields[0].IndexOf(',') >= 0) + { + this.Name = fields[0].Substring(0, fields[0].LastIndexOf(',')); + if (fields[0].IndexOf(';') >= 0) + this.ShortName = fields[0].Split(';').GetValue(0).ToString().Substring(fields[0].LastIndexOf(',')+1); + else + this.ShortName = fields[0].Substring(fields[0].LastIndexOf(',')+1); + } + else + this.Name = Convert.ToString(fields[0].Split(';').GetValue(0)); + + if (fields[0].IndexOf(';') >= 0) + this.Provider = Convert.ToString(fields[0].Split(';').GetValue(1)); + } + else + this.Name = Convert.ToString(fields[0]); + + if (fields.Length >= 9) + { + // field 1 - Freqency + // DVB-S - Frequency in MHz. + // DVB-C/T - Frequency in MHz, kHz or Hz. + // analogue- Frequency in MHz. (analogTV plugin) + + int freq = Convert.ToInt32(fields[1]); + // TODO - corrent DVB-C/T to MHz + this.FreqInMhz = freq; + + // field 2 - Params + ParseParams(Convert.ToString(fields[2])); + + // field 3 - Source + string ntype = Convert.ToString(fields[3]); + switch (ntype[0]) + { + case 'S': + this.SignalSource |= SignalSource.DvbS; + this.Satellite = ntype.Substring(1,ntype.Length -1); + this.SatPosition = ntype.Substring(1, ntype.Length - 1); + break; + + case 'C': + this.SignalSource |= SignalSource.DvbC; + this.Satellite = "DVB-C"; + break; + + case 'T': + this.SignalSource |= SignalSource.DvbT; + this.Satellite = "DVB-T"; + break; + + } + + // field 4 - SymbolRate + this.SymbolRate = Convert.ToInt32(fields[4]); + + // field 5 - Video-PID[+PCR-PID][=Stream-Type] + vtype = 0; + string tmp = fields[5]; + if (tmp.IndexOf('=') >= 0 || tmp.IndexOf('+') >= 0) + { + this.SignalSource |= SignalSource.Tv; + if (tmp.IndexOf('+') >= 0) + { + this.VideoPid = Convert.ToInt32(fields[5].Split('+').GetValue(0)); + if (tmp.IndexOf('=') >= 0) + vtype = Convert.ToInt32(fields[5].Split('=').GetValue(1)); + } + else + { + this.VideoPid = Convert.ToInt32(fields[5].Split('=').GetValue(0)); + vtype = Convert.ToInt32(fields[5].Split('=').GetValue(1)); + } + } + else if (tmp == "0" || tmp == "1") + { + this.SignalSource |= SignalSource.Radio; + if (tmp == "1") + this.Encrypted = true; + } + else + this.VideoPid = Convert.ToInt32(fields[5]); + + if (this.VideoPid != 0 && vtype == 0) + vtype = 2; // default is MPEG-2 + + // field 6 - Audio-PID[=Language-ID][@Stream-Type][;Dolby-PID[=Language-ID][@Stream-Type]] + int NumApids = 0; + int NumDpids = 0; + + apids[0] = 0; + atypes[0] = 0; + dpids[0] = 0; + dtypes[0] = 0; + + // example field: 5102=deu@3,5103=deu;5106 + // 101=deu@3;103=deu@106 + + foreach (string f1 in fields[6].Split(',')) + { + int i = 0; + foreach (string apid in f1.Split(';')) + { + if(i == 0) // apids + { + atypes[NumApids] = 4; // backwards compatibility + + if (apid.IndexOf('=') >= 0) + { + apids[NumApids] = Convert.ToInt32(apid.Split('=').GetValue(0)); + if (apid.IndexOf('@') >= 0) + { + tmp = Convert.ToString(apid.Split('=').GetValue(1)); + alangs[NumApids] = Convert.ToString(tmp.Split('@').GetValue(0)); + atypes[NumApids] = Convert.ToInt32(tmp.Split('@').GetValue(1)); + } + else + alangs[NumApids] = Convert.ToString(apid.Split('=').GetValue(1)); + } + else if (apid.IndexOf('@') >= 0) + { + apids[NumApids] = Convert.ToInt32(apid.Split('@').GetValue(0)); + atypes[NumApids] = Convert.ToInt32(apid.Split('@').GetValue(1)); + } + else + apids[NumApids] = Convert.ToInt32(apid); + + NumApids++; + } + else // dpids + { + //dtypes[NumDpids] + //dlangs[NumDpids] + //dpids[NumDpids] + NumDpids++; + } + i++; + } + } + + this.AudioPid = apids[0]; + this.ServiceType = getServiceType(); + + // field 7 - Teletext-PID (TPID) + + // field 8 - Conditional Access-ID (CAID) + if (Convert.ToString(fields[8]) == "0") + this.Encrypted = false; + else + this.Encrypted = true; + + // field 9 - Service ID (SID) + this.ServiceId = Convert.ToInt32(fields[9]); + + // field 10 - Network ID (NID) + this.OriginalNetworkId = Convert.ToInt32(fields[10]); + + // field 11 - Transport Steam ID (TID) + this.TransportStreamId = Convert.ToInt32(fields[11]); + + // field 12 - Radio ID (RID) + } + } + catch (Exception e) + { + Console.WriteLine("{0} Exception caught.", e); + } + } + + #endregion + + #region ParseParams + private void ParseParams(String Params) + { + Params = Params.ToUpper(); + for (int i = 0; i < Params.Length; i++) + { + switch (Params[i]) + { + case 'B': + // Bandwidth in MHz (1712 in kHz) (1712, 5, 6, 7, 8, 10) + break; + + case 'C': + // Code rate high priority (FEC) (0, 12, 23, 34, 35, 45, 56, 67, 78, 89, 910) + break; + + case 'D': + // coDe rate low priority (FEC) (0, 12, 23, 34, 35, 45, 56, 67, 78, 89, 910) + break; + + case 'G': + // Guard interval (4, 8, 16, 32, 128, 19128, 19256) + break; + + case 'H': + // Horizontal Polarization + break; + + case 'I': + // Inversion (0, 1) + break; + + case 'L': + // Left circular polarization + break; + + case 'M': + // Modulation (2, 5, 6, 7, 10, 11, 12, 16, 32, 64, 128, 256, 999) + break; + + case 'O': + // rollOff (0, 20, 25, 35) + break; + + case 'P': + // stream id (0-255) + break; + + case 'R': + // Right circular polarization + break; + + case 'S': + // delivery System (0, 1) + break; + + case 'T': + // Transmission mode (1, 2, 4, 8, 16, 32) + break; + + case 'V': + // Vertical Polarization + break; + + case 'Y': + // hierarchY (0, 1, 2, 4) + break; + + default: + break; + } + } + } + + #endregion + + private int getServiceType() + { + if ((this.SignalSource & SignalSource.Radio) != 0) + return 2; + + // we cant get real ServiceType, but we can try to poke a little bit around :D + switch (vtype) + { + case 2: // 2 = MPEG2 + return 1; + + case 27: // 27 = H264 + return 25; + + case 16: // 16 = MPEG4 + return 22; + + default: + return 0; + + } + + //SERVICETYPE;Number;Description + //SERVICETYPE;01;SD-TV - SD MPEG1 + //SERVICETYPE;02;Radio + //SERVICETYPE;12;Data/Test + //SERVICETYPE;22;SD-TV + //SERVICETYPE;25;HD-TV + //SERVICETYPE;211;Option + + // case 0x01: 01 // SD MPEG1 + // case 0x11: 17 // MPEG2-HD + // case 0x16: 22 // H264/AVC-SD + // case 0x19: 25 // H264/AVC-HD + // return SignalSource.Tv; + // case 0x02: + // case 0x0A: + // return SignalSource.Radio; + } + } +} diff --git a/ChanSort.Loader.VDR/Properties/AssemblyInfo.cs b/ChanSort.Loader.VDR/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c2200ee --- /dev/null +++ b/ChanSort.Loader.VDR/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ChanSort.Loader.VDR")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ChanSort.Loader.VDR")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ebf84b90-20d8-4cdb-bda0-d711070fe551")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ChanSort.Loader.VDR/Serializer.cs b/ChanSort.Loader.VDR/Serializer.cs new file mode 100644 index 0000000..1bb8cb2 --- /dev/null +++ b/ChanSort.Loader.VDR/Serializer.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Text; +using System.Windows.Forms; +using ChanSort.Api; + +namespace ChanSort.Loader.VDR +{ + class Serializer : SerializerBase + { + private const string ERR_FileFormat = "File uses an unknown format"; + + private readonly ChannelList allChannels = new ChannelList(SignalSource.DvbT | SignalSource.DvbC | SignalSource.DvbS | SignalSource.AnalogC | SignalSource.AnalogT | SignalSource.Tv | SignalSource.Radio, "All"); + + #region ctor() + public Serializer(string inputFile) : base(inputFile) + { + DepencencyChecker.AssertVc2010RedistPackageX86Installed(); + + this.Features.ChannelNameEdit = false; + this.DataRoot.SortedFavorites = false; + //this.DataRoot.SupportedFavorites = new Favorites(); + + this.DataRoot.AddChannelList(this.allChannels); + } + #endregion + + public override string DisplayName { get { return "VDR channels .conf Loader"; } } + + #region Load() + public override void Load() + { + this.ReadChannels(); + } + #endregion + + #region ReadChannels() + private void ReadChannels() + { + string line; + int pos = 0; + + using (StreamReader file = new StreamReader(this.FileName)) + { + while ((line = file.ReadLine()) != null) + { + ChannelInfo channel = new Channels(pos, line, this.DataRoot); + this.DataRoot.AddChannel(this.allChannels, channel); + pos++; + } + } + } + #endregion + + #region Save() + public override void Save(string tvOutputFile) + { + if (tvOutputFile != this.FileName) + { + File.Copy(this.FileName, tvOutputFile); + this.FileName = tvOutputFile; + } + + using (StreamWriter file = new StreamWriter(tvOutputFile)) + { + foreach (Channels channelInfo in this.allChannels.GetChannelsByNewOrder()) + { + file.WriteLine(channelInfo.confLine); + } + } + } + #endregion + + #region GetFileInformation() + public override string GetFileInformation() + { + StringBuilder sb = new StringBuilder(); + sb.Append(base.GetFileInformation()); + return sb.ToString(); + } + #endregion + } +} diff --git a/ChanSort.Loader.VDR/SerializerPlugin.cs b/ChanSort.Loader.VDR/SerializerPlugin.cs new file mode 100644 index 0000000..e7d93d4 --- /dev/null +++ b/ChanSort.Loader.VDR/SerializerPlugin.cs @@ -0,0 +1,15 @@ +using ChanSort.Api; + +namespace ChanSort.Loader.VDR +{ + public class SerializerPlugin : ISerializerPlugin + { + public string PluginName { get { return "VDR Channels *.conf"; } } + public string FileFilter { get { return "*.conf"; } } + + public SerializerBase CreateSerializer(string inputFile) + { + return new Serializer(inputFile); + } + } +} diff --git a/makeDistribZip.cmd b/makeDistribZip.cmd index b530d50..336c548 100644 --- a/makeDistribZip.cmd +++ b/makeDistribZip.cmd @@ -1,6 +1,5 @@ @echo off -c:\cygwin\bin\date "+%%Y-%%m-%%d">%TEMP%\date.txt -set /p curdate=<%temp%\date.txt +set curdate=%date:~6,4%-%date:~3,2%-%date:~0,2% set target=%cd%\..\ChanSort_%curdate% set DXversion=13.2 mkdir "%target%" 2>nul