From a6c50f48a29e707e6d668a18afeef8192e66fb94 Mon Sep 17 00:00:00 2001 From: hbeham Date: Fri, 5 Jun 2015 06:08:40 +0200 Subject: [PATCH] complete support for Samsung J series (added DVB-T, analog and reference list support) --- source/ChanSort.Api/Lookup.csv | 126 +++++++++++- source/ChanSort.Api/Model/LookupData.cs | 62 +++--- source/ChanSort.Loader.LG/DtvChannel.cs | 2 +- source/ChanSort.Loader.Panasonic/DbChannel.cs | 4 +- .../ChanSort.Loader.Samsung/DigitalChannel.cs | 4 +- source/ChanSort.Loader.SamsungJ/DbChannel.cs | 41 ++-- .../ChanSort.Loader.SamsungJ/DbSerializer.cs | 186 +++++++++++++----- .../DbSerializerPlugin.cs | 2 +- source/ChanSort/AboutForm.resx | 16 +- source/ChanSort/MainForm.cs | 2 +- source/ChanSort/Properties/licenses.licx | 1 + source/changelog.md | 5 + 12 files changed, 323 insertions(+), 128 deletions(-) diff --git a/source/ChanSort.Api/Lookup.csv b/source/ChanSort.Api/Lookup.csv index ac22c82..01d024e 100644 --- a/source/ChanSort.Api/Lookup.csv +++ b/source/ChanSort.Api/Lookup.csv @@ -1,4 +1,13 @@ -ONID;Start;End;Name;Operator +SERVICETYPE;Number;Description +SERVICETYPE;01;SD-TV +SERVICETYPE;02;Radio +SERVICETYPE;12;Data/Test +SERVICETYPE;22;SD-TV +SERVICETYPE;25;HD-TV +SERVICETYPE;31;4K-TV +SERVICETYPE;211;Option + +ONID;Start;End;Name;Operator ONID;0x0000;0x0000;(Reserved);(Reserved) ONID;0x0001;0x0001;Société Européenne des Satellites;Société Européenne des Satellites ONID;0x0002;0x0002;Société Européenne des Satellites;Société Européenne des Satellites @@ -417,11 +426,110 @@ TRANSP;118;12699 TRANSP;119;12722 TRANSP;120;12728 -SERVICETYPE;Number;Description -SERVICETYPE;01;SD-TV -SERVICETYPE;02;Radio -SERVICETYPE;12;Data/Test -SERVICETYPE;22;SD-TV -SERVICETYPE;25;HD-TV -SERVICETYPE;31;4K-TV -SERVICETYPE;211;Option \ No newline at end of file +DVBC;kHz;Channel +DVBC;50500;2 +DVBC;57500;3 +DVBC;64500;4 +DVBC;71500;S 01 +DVBC;78500;S 02 +DVBC;85500;S 03 +DVBC;107500;SE 1 +DVBC;113000;SE 2 +DVBC;114500;SE 2 +DVBC;121000;SE 3 +DVBC;121500;SE 3 +DVBC;128500;SE 4 +DVBC;135500;SE 5 +DVBC;142500;SE 6 +DVBC;149500;SE 7 +DVBC;156500;SE 8 +DVBC;163500;SE 9 +DVBC;170500;SE 10 +DVBC;177500;5 +DVBC;184500;6 +DVBC;191500;7 +DVBC;198500;8 +DVBC;205500;9 +DVBC;212500;10 +DVBC;219500;11 +DVBC;226500;12 +DVBC;233500;SE 11 +DVBC;240500;SE 12 +DVBC;247500;SE 13 +DVBC;254500;SE 14 +DVBC;261500;SE 15 +DVBC;268500;SE 16 +DVBC;275500;SE 17 +DVBC;282500;SE 18 +DVBC;289500;SE 19 +DVBC;296500;SE 20 +DVBC;306000;S 21 +DVBC;314000;S 22 +DVBC;322000;S 23 +DVBC;330000;S 24 +DVBC;338000;S 25 +DVBC;346000;S 26 +DVBC;354000;S 27 +DVBC;362000;S 28 +DVBC;370000;S 29 +DVBC;378000;S 30 +DVBC;386000;S 31 +DVBC;394000;S 32 +DVBC;402000;S 33 +DVBC;410000;S 34 +DVBC;418000;S 35 +DVBC;426000;S 36 +DVBC;434000;S 37 +DVBC;442000;S 38 +DVBC;450000;S 39 +DVBC;458000;S 40 +DVBC;466000;S 41 +DVBC;474000;21 +DVBC;482000;22 +DVBC;490000;23 +DVBC;498000;24 +DVBC;506000;25 +DVBC;514000;26 +DVBC;522000;27 +DVBC;530000;28 +DVBC;538000;29 +DVBC;546000;30 +DVBC;554000;31 +DVBC;562000;32 +DVBC;570000;33 +DVBC;578000;34 +DVBC;586000;35 +DVBC;594000;36 +DVBC;602000;37 +DVBC;610000;38 +DVBC;618000;39 +DVBC;626000;40 +DVBC;634000;41 +DVBC;642000;42 +DVBC;650000;43 +DVBC;658000;44 +DVBC;666000;45 +DVBC;674000;46 +DVBC;682000;47 +DVBC;690000;48 +DVBC;698000;49 +DVBC;706000;50 +DVBC;714000;51 +DVBC;722000;52 +DVBC;730000;53 +DVBC;738000;54 +DVBC;746000;55 +DVBC;754000;56 +DVBC;762000;57 +DVBC;770000;58 +DVBC;778000;59 +DVBC;786000;60 +DVBC;794000;61 +DVBC;802000;62 +DVBC;810000;63 +DVBC;818000;64 +DVBC;826000;65 +DVBC;834000;66 +DVBC;842000;67 +DVBC;850000;68 +DVBC;858000;69 diff --git a/source/ChanSort.Api/Model/LookupData.cs b/source/ChanSort.Api/Model/LookupData.cs index d26de6c..0a2bac0 100644 --- a/source/ChanSort.Api/Model/LookupData.cs +++ b/source/ChanSort.Api/Model/LookupData.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections.Concurrent; +using System.Collections.Generic; using System.IO; using System.Reflection; @@ -8,9 +9,8 @@ namespace ChanSort.Api { private readonly IDictionary networks = new Dictionary(); private readonly IDictionary transponderNrByFreqInMhz = new Dictionary(); - private readonly IDictionary transponderFreqInMhzByNr = new Dictionary(); private readonly IDictionary serviceTypeDescriptions = new Dictionary(); - private readonly IDictionary dvbtFreqInMhzByTransponder = new Dictionary(); + private readonly IDictionary dvbcChannels = new ConcurrentDictionary(); public static readonly LookupData Instance = new LookupData(); @@ -28,8 +28,8 @@ namespace ChanSort.Api } #endregion - #region GetTransponderNumber(), GetTransponderFrequency() - public int GetTransponderNumber(int frequencyInMhz) + #region GetAstraTransponder(), GetAstraFrequency() + public int GetAstraTransponder(int frequencyInMhz) { int number; bool found = this.transponderNrByFreqInMhz.TryGetValue(frequencyInMhz, out number) || @@ -40,7 +40,7 @@ namespace ChanSort.Api return found ? number : 0; } - public int GetTransponderFrequency(int transponderNr) + public int GetAstraFrequency(int transponderNr) { return this.transponderNrByFreqInMhz.TryGet(transponderNr); } @@ -59,12 +59,10 @@ namespace ChanSort.Api public void LoadDataFromCsvFile() { this.networks.Clear(); - this.transponderFreqInMhzByNr.Clear(); this.transponderNrByFreqInMhz.Clear(); this.serviceTypeDescriptions.Clear(); - this.dvbtFreqInMhzByTransponder.Clear(); - string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "lookup.csv"); + string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "", "lookup.csv"); if (!File.Exists(file)) return; using (var reader = new StreamReader(file, System.Text.Encoding.UTF8)) @@ -78,8 +76,8 @@ namespace ChanSort.Api switch (fields[0].ToLower()) { case "onid": this.ParseNetwork(fields); break; - case "dvbt": this.ParseDvbtTransponder(fields); break; case "transp": this.ParseTransponder(fields); break; + case "dvbc": this.ParseDvbcChannel(fields); break; case "servicetype": this.ParseServiceType(fields); break; } } @@ -98,14 +96,6 @@ namespace ChanSort.Api private void AddTransponderMapping(int transponderNr, int frequencyInMhz) { this.transponderNrByFreqInMhz[frequencyInMhz] = transponderNr; - this.transponderFreqInMhzByNr[transponderNr] = frequencyInMhz; - } - #endregion - - #region AddDvbtTransponderMapping() - private void AddDvbtTransponderMapping(int transponderNr, int frequencyInMhz) - { - this.dvbtFreqInMhzByTransponder[transponderNr] = frequencyInMhz; } #endregion @@ -164,17 +154,16 @@ namespace ChanSort.Api } #endregion - #region ParseTransponder() - private void ParseDvbtTransponder(IList fields) + #region ParseDvbcChannel() + private void ParseDvbcChannel(IList fields) { if (fields.Count < 3) return; - int nr, freq; - int.TryParse(fields[1], out nr); - int.TryParse(fields[2], out freq); - if (nr == 0 || freq == 0) + int freq; + int.TryParse(fields[1], out freq); + if (freq == 0) return; - this.AddDvbtTransponderMapping(nr, freq); + this.dvbcChannels[freq] = fields[2]; } #endregion @@ -208,24 +197,27 @@ namespace ChanSort.Api #endregion #region GetDvbtTransponder() - public int GetDvbtTransponder(decimal freq) + public int GetDvbtTransponder(decimal freqInMhz) { - return (int)(freq - 106)/8; + return (int)(freqInMhz - 306)/8; + } + #endregion + + #region GetDvbtFrequency() + public decimal GetDvbtFrequeny(int channelTransponder) + { + return channelTransponder * 8 + 306; } #endregion - #region GetDvbtFrequencyForTransponder() - public decimal GetDvbtFrequenyForTransponder(int transponder) + public int GetDvbcTransponder(decimal freqInMhz) { - return transponder * 8 + 106; + return GetDvbtTransponder(freqInMhz) + 25; // Samsung handles it like this } - #endregion - #region GetDvbtFrequencyForChannel() - public decimal GetDvbtFrequenyForChannel(int channel) + public string GetDvbcChannelName(decimal freqInMhz) { - return channel * 8 + 306; + return dvbcChannels.TryGet((int)(freqInMhz * 1000)) ?? ""; } - #endregion } } diff --git a/source/ChanSort.Loader.LG/DtvChannel.cs b/source/ChanSort.Loader.LG/DtvChannel.cs index de491c1..dae3f05 100644 --- a/source/ChanSort.Loader.LG/DtvChannel.cs +++ b/source/ChanSort.Loader.LG/DtvChannel.cs @@ -26,7 +26,7 @@ namespace ChanSort.Loader.LG this.FreqInMhz = (data.GetDword(_FrequencyLong)+10) / 1000; // ReSharper restore PossibleLossOfFraction if (this.FreqInMhz == 0) - this.FreqInMhz = LookupData.Instance.GetDvbtFrequenyForChannel(channel); + this.FreqInMhz = LookupData.Instance.GetDvbtFrequeny(channel); } } } diff --git a/source/ChanSort.Loader.Panasonic/DbChannel.cs b/source/ChanSort.Loader.Panasonic/DbChannel.cs index d8ec275..acbf3a8 100644 --- a/source/ChanSort.Loader.Panasonic/DbChannel.cs +++ b/source/ChanSort.Loader.Panasonic/DbChannel.cs @@ -106,7 +106,9 @@ namespace ChanSort.Loader.Panasonic { freq /= 1000; this.FreqInMhz = freq; - this.ChannelOrTransponder = LookupData.Instance.GetDvbtTransponder(freq).ToString(); + this.ChannelOrTransponder = (this.SignalSource & SignalSource.Antenna) != 0 ? + LookupData.Instance.GetDvbtTransponder(freq).ToString() : + LookupData.Instance.GetDvbcTransponder(freq).ToString(); this.Satellite = (this.SignalSource & SignalSource.Antenna) != 0 ? "DVB-T" : "DVB-C"; } diff --git a/source/ChanSort.Loader.Samsung/DigitalChannel.cs b/source/ChanSort.Loader.Samsung/DigitalChannel.cs index d196c68..e5b2830 100644 --- a/source/ChanSort.Loader.Samsung/DigitalChannel.cs +++ b/source/ChanSort.Loader.Samsung/DigitalChannel.cs @@ -21,9 +21,9 @@ namespace ChanSort.Loader.Samsung int transp = data.GetByte(_ChannelOrTransponder); decimal freq = transpFreq.TryGet(transp); if (freq == 0) - freq = transp*8 + 106; // (106 = DVB-C; DVB-T=306?) + freq = LookupData.Instance.GetDvbtFrequeny(transp); // transp*8 + 106); // (106 = DVB-C; DVB-T=306?) - this.ChannelOrTransponder = LookupData.Instance.GetDvbtTransponder(freq).ToString(); + this.ChannelOrTransponder = transp.ToString(); this.FreqInMhz = freq; } } diff --git a/source/ChanSort.Loader.SamsungJ/DbChannel.cs b/source/ChanSort.Loader.SamsungJ/DbChannel.cs index 113b885..18affa4 100644 --- a/source/ChanSort.Loader.SamsungJ/DbChannel.cs +++ b/source/ChanSort.Loader.SamsungJ/DbChannel.cs @@ -2,53 +2,61 @@ using System.Data.SQLite; using ChanSort.Api; -namespace ChanSort.Loader.Toshiba +namespace ChanSort.Loader.SamsungJ { internal class DbChannel : ChannelInfo { internal Dictionary OriginalFavIndex = new Dictionary(); #region ctor() - internal DbChannel(SQLiteDataReader r, IDictionary field, DataRoot dataRoot, Dictionary providers) + internal DbChannel(SQLiteDataReader r, IDictionary field, DataRoot dataRoot, Dictionary providers, Satellite sat, Transponder tp) { var chType = r.GetInt32(field["chType"]); - if (chType == 7) - this.SignalSource = SignalSource.DvbS; - else if (chType == 4) - this.SignalSource = SignalSource.DvbC; + this.SignalSource = DbSerializer.ChTypeToSignalSource(chType); this.RecordIndex = r.GetInt64(field["SRV.srvId"]); this.OldProgramNr = r.GetInt32(field["major"]); this.FreqInMhz = (decimal)r.GetInt32(field["freq"]) / 1000; this.ChannelOrTransponder = - (this.SignalSource & SignalSource.Cable) != 0 ? LookupData.Instance.GetDvbtTransponder(this.FreqInMhz).ToString() : - (this.SignalSource & SignalSource.Sat) != 0 ? LookupData.Instance.GetTransponderNumber((int)this.FreqInMhz).ToString() : + (this.SignalSource & SignalSource.DvbT) == SignalSource.DvbT ? LookupData.Instance.GetDvbtTransponder(this.FreqInMhz).ToString() : + (this.SignalSource & SignalSource.DvbC) == SignalSource.DvbC ? LookupData.Instance.GetDvbcTransponder(this.FreqInMhz).ToString() : + (this.SignalSource & SignalSource.Sat) == SignalSource.DvbS ? LookupData.Instance.GetAstraTransponder((int)this.FreqInMhz).ToString() : ""; - this.Name = DbSerializer.ReadUtf16(r, 2); + this.Name = DbSerializer.ReadUtf16(r, 6); this.Hidden = r.GetBoolean(field["hidden"]); this.Encrypted = r.GetBoolean(field["scrambled"]); this.Lock = r.GetBoolean(field["lockMode"]); this.Skip = !r.GetBoolean(field["numSel"]); - - //if (isAnalog) - // this.ReadAnalogData(r, field); - //else + + if (sat != null) + { + this.Satellite = sat.Name; + this.SatPosition = sat.OrbitalPosition; + } + if (tp != null) + { + this.Transponder = tp; + this.SymbolRate = tp.SymbolRate; + } + + if ((this.SignalSource & SignalSource.Digital) != 0) this.ReadDvbData(r, field, dataRoot, providers); + else + this.ReadAnalogData(r, field); } #endregion #region ReadAnalogData() private void ReadAnalogData(SQLiteDataReader r, IDictionary field) { - this.Name = r.GetString(field["channel_label"]); - this.FreqInMhz = (decimal)r.GetInt32(field["frequency"]) / 1000000; + } #endregion #region ReadDvbData() protected void ReadDvbData(SQLiteDataReader r, IDictionary field, DataRoot dataRoot, Dictionary providers) { - this.ShortName = DbSerializer.ReadUtf16(r, 3); + this.ShortName = DbSerializer.ReadUtf16(r, 16); this.RecordOrder = r.GetInt32(field["major"]); int serviceType = r.GetInt32(field["srvType"]); this.ServiceType = serviceType; @@ -61,6 +69,7 @@ namespace ChanSort.Loader.Toshiba this.Provider = providers.TryGet(r.GetInt64(field["provId"])); if ((this.SignalSource & SignalSource.Sat) != 0) { + //int satId = r.GetInt32(field["sat_id"]); //var sat = dataRoot.Satellites.TryGet(satId); //if (sat != null) diff --git a/source/ChanSort.Loader.SamsungJ/DbSerializer.cs b/source/ChanSort.Loader.SamsungJ/DbSerializer.cs index 034e0ad..7cc2927 100644 --- a/source/ChanSort.Loader.SamsungJ/DbSerializer.cs +++ b/source/ChanSort.Loader.SamsungJ/DbSerializer.cs @@ -8,15 +8,16 @@ using System.Windows.Forms; using ChanSort.Api; using ICSharpCode.SharpZipLib.Zip; -namespace ChanSort.Loader.Toshiba +namespace ChanSort.Loader.SamsungJ { class DbSerializer : SerializerBase { private readonly Dictionary channelById = new Dictionary(); private readonly Dictionary dbPathByChannelList = new Dictionary(); private string tempDir; + private Dictionary transponderByFreq; - private enum FileType { Unknown, SatDb, ChannelDb } + private enum FileType { Unknown, SatDb, ChannelDbDvb, ChannelDbAnalog } #region ctor() public DbSerializer(string inputFile) : base(inputFile) @@ -37,6 +38,19 @@ namespace ChanSort.Loader.Toshiba public override void Load() { this.UnzipDataFile(); + if (File.Exists(tempDir + "\\sat")) + { + try + { + using (var conn = new SQLiteConnection("Data Source=" + tempDir + "\\sat")) + { + conn.Open(); + this.ReadSatDatabase(conn); + } + } + catch { } + } + foreach (var filePath in Directory.GetFiles(tempDir, "*.")) { try @@ -53,11 +67,12 @@ namespace ChanSort.Loader.Toshiba switch (type) { - case FileType.SatDb: - //ReadSatDatabase(conn); + case FileType.SatDb: break; + case FileType.ChannelDbAnalog: + ReadChannelDatabase(conn, filePath, false); break; - case FileType.ChannelDb: - ReadChannelDatabase(conn, filePath); + case FileType.ChannelDbDvb: + ReadChannelDatabase(conn, filePath, true); break; } } @@ -131,8 +146,12 @@ namespace ChanSort.Loader.Toshiba return FileType.SatDb; cmd.CommandText = "select count(1) from sqlite_master where type='table' and name in ('CHNL','SRV','SRV_DVB')"; - if ((long) cmd.ExecuteScalar() == 3) - return FileType.ChannelDb; + if ((long)cmd.ExecuteScalar() == 3) + return FileType.ChannelDbDvb; + + cmd.CommandText = "select count(1) from sqlite_master where type='table' and name in ('CHNL','SRV','SRV_ANL')"; + if ((long)cmd.ExecuteScalar() == 3) + return FileType.ChannelDbAnalog; return FileType.Unknown; } @@ -153,7 +172,7 @@ namespace ChanSort.Loader.Toshiba #region ReadSatellites() private void ReadSatellites(SQLiteCommand cmd) { - cmd.CommandText = "select distinct satId, satName, satPos, satDir from SAT"; + cmd.CommandText = "select distinct satId, cast(satName as blob), satPos, satDir from SAT"; using (var r = cmd.ExecuteReader()) { while (r.Read()) @@ -161,7 +180,7 @@ namespace ChanSort.Loader.Toshiba Satellite sat = new Satellite(r.GetInt32(0)); int pos = Math.Abs(r.GetInt32(2)); sat.OrbitalPosition = string.Format("{0}.{1}{2}", pos / 10, pos % 10, r.GetInt32(3) == 1 ? "E" : "W"); - sat.Name = r.GetString(1) + " " + sat.OrbitalPosition; + sat.Name = ReadUtf16(r, 1); this.DataRoot.AddSatellite(sat); } } @@ -186,7 +205,7 @@ namespace ChanSort.Loader.Toshiba tp.Number = r.GetInt32(4); tp.Polarity = r.GetInt32(2) == 0 ? 'H' : 'V'; tp.Satellite = this.DataRoot.Satellites.TryGet(satId); - tp.SymbolRate = r.GetInt32(3) / 1000; + tp.SymbolRate = r.GetInt32(3); this.DataRoot.AddTransponder(tp.Satellite, tp); } } @@ -195,15 +214,14 @@ namespace ChanSort.Loader.Toshiba #region ReadChannelDatabase() - private void ReadChannelDatabase(SQLiteConnection conn, string dbPath) + private void ReadChannelDatabase(SQLiteConnection conn, string dbPath, bool digital) { this.channelById.Clear(); using (var cmd = conn.CreateCommand()) { this.RepairCorruptedDatabaseImage(cmd); - var providers = this.ReadProviders(cmd); - //this.ReadAnalogChannels(cmd); - var channelList = this.ReadDtvChannels(cmd, dbPath, providers); + var providers = digital ? this.ReadProviders(cmd) : null; + var channelList = this.ReadChannels(cmd, dbPath, providers, digital); this.ReadFavorites(cmd); this.dbPathByChannelList.Add(channelList, dbPath); } @@ -230,43 +248,23 @@ namespace ChanSort.Loader.Toshiba } #endregion - #region ReadAnalogChannels() - private void ReadAnalogChannels(SQLiteCommand cmd) + #region ReadChannels() + private ChannelList ReadChannels(SQLiteCommand cmd, string dbPath, Dictionary providers, bool digital) { - //string[] fieldNames = {"channel_handle", "channel_number", "list_bits", "channel_label", "frequency"}; - //var sql = this.GetQuery("EuroATVChanList", fieldNames); - //var fields = this.GetFieldMap(fieldNames); - - //cmd.CommandText = sql; - //using (var r = cmd.ExecuteReader()) - //{ - // while (r.Read()) - // { - // ChannelInfo channel = new DbChannel(SignalSource.Analog, r, fields, this.DataRoot); - // if (!channel.IsDeleted) - // this.DataRoot.AddChannel(this.atvChannels, channel); - // } - //} - } - #endregion + var signalSource = DetectSignalSource(cmd, digital); + var sat = (signalSource & SignalSource.Sat) == 0 ? null : this.DetectSatellite(cmd); - #region ReadDtvChannels() - private ChannelList ReadDtvChannels(SQLiteCommand cmd, string dbPath, Dictionary providers) - { string name = Path.GetFileName(dbPath); - ChannelList channelList = new ChannelList(SignalSource.Digital, name); - this.ReadDigitalChannels(cmd, "SRV_DVB", channelList, providers); - this.DataRoot.AddChannelList(channelList); - return channelList; - } - #endregion + ChannelList channelList = new ChannelList(signalSource, name); + string table = digital ? "SRV_DVB" : "SRV_ANL"; + List fieldNames = new List { + "chType", "chNum", "freq", // CHNL + "SRV.srvId", "major", "progNum", "cast(srvName as blob)", "srvType", "hidden", "scrambled", "lockMode", "numSel", // SRV + }; + if (digital) + fieldNames.AddRange(new[] { "onid", "tsid", "vidPid", "provId", "cast(shrtSrvName as blob)" }); // SRV_DVB - #region ReadDigitalChannels() - private void ReadDigitalChannels(SQLiteCommand cmd, string table, ChannelList channelList, Dictionary providers) - { - string[] fieldNames = { "SRV.srvId", "major", "cast(srvName as blob)", "cast(shrtSrvName as blob)", "chType", "chNum", - "srvType", "onid", "tsid", "vidPid", "progNum", "freq", "hidden", "scrambled", "lockMode", "numSel", "provId" }; - var sql = this.GetQuery(table, fieldNames); + var sql = this.BuildQuery(table, fieldNames); var fields = this.GetFieldMap(fieldNames); cmd.CommandText = sql; @@ -274,7 +272,8 @@ namespace ChanSort.Loader.Toshiba { while (r.Read()) { - var channel = new DbChannel(r, fields, this.DataRoot, providers); + var tp = this.transponderByFreq != null ? this.transponderByFreq.TryGet(r.GetInt32(2)) : null; + var channel = new DbChannel(r, fields, this.DataRoot, providers, sat, tp); if (!channel.IsDeleted) { this.DataRoot.AddChannel(channelList, channel); @@ -282,14 +281,93 @@ namespace ChanSort.Loader.Toshiba } } } + + this.DataRoot.AddChannelList(channelList); + return channelList; } #endregion - #region GetQuery() - private string GetQuery(string table, string[] fieldNames) + #region DetectSignalSource() + private static SignalSource DetectSignalSource(SQLiteCommand cmd, bool digital) + { + var signalSource = digital ? SignalSource.Digital : SignalSource.Analog; + cmd.CommandText = "select distinct chType from CHNL"; + using (var r = cmd.ExecuteReader()) + { + if (r.Read()) + { + var ss = ChTypeToSignalSource(r.GetInt32(0)); + if (ss != 0) + signalSource = ss; + } + } + return signalSource | SignalSource.TvAndRadio; + } + + #endregion + + #region ChTypeToSignalSource() + internal static SignalSource ChTypeToSignalSource(int chType) + { + switch (chType) + { + case 1: return SignalSource.AnalogT; + case 2: return SignalSource.DvbT; + case 3: return SignalSource.AnalogC; + case 4: return SignalSource.DvbC; + case 7: return SignalSource.DvbS; + default: return 0; + } + } + #endregion + + #region DetectSatellite() + + /// + /// I haven't found a direct way to link a dvbs database file or its channels to a satId. + /// This workaround compares the transponder frequencies in the channel list with the transponder frequencies of each satellite to find a match. + /// + private Satellite DetectSatellite(SQLiteCommand cmd) + { + List tpFreq = new List(); + cmd.CommandText = "select freq from CHNL where chType=7"; + using (var r = cmd.ExecuteReader()) + { + while (r.Read()) + tpFreq.Add(r.GetInt32(0)); + } + + this.transponderByFreq = null; + foreach (var sat in DataRoot.Satellites.Values) + { + Dictionary satFreq = new Dictionary(); + foreach (var tp in sat.Transponder.Values) + satFreq.Add((int) (tp.FrequencyInMhz*1000), tp); + + int mismatch = 0; + foreach (int freq in tpFreq) + { + if (satFreq.ContainsKey(freq) || satFreq.ContainsKey(freq - 1000) || satFreq.ContainsKey(freq + 1000)) + continue; + + ++mismatch; + } + + if (mismatch < 10) + { + this.transponderByFreq = satFreq; + return sat; + } + } + return null; + } + #endregion + + #region BuildQuery() + private string BuildQuery(string table, IList fieldNames) { string sql = "select "; - for (int i = 0; i < fieldNames.Length; i++) + for (int i = 0; i < fieldNames.Count; i++) { if (i > 0) sql += ","; @@ -301,10 +379,10 @@ namespace ChanSort.Loader.Toshiba #endregion #region GetFieldMap() - private IDictionary GetFieldMap(string[] fieldNames) + private IDictionary GetFieldMap(IList fieldNames) { Dictionary field = new Dictionary(); - for (int i = 0; i < fieldNames.Length; i++) + for (int i = 0; i < fieldNames.Count; i++) field[fieldNames[i]] = i; return field; } diff --git a/source/ChanSort.Loader.SamsungJ/DbSerializerPlugin.cs b/source/ChanSort.Loader.SamsungJ/DbSerializerPlugin.cs index 60f5534..cdf5175 100644 --- a/source/ChanSort.Loader.SamsungJ/DbSerializerPlugin.cs +++ b/source/ChanSort.Loader.SamsungJ/DbSerializerPlugin.cs @@ -1,6 +1,6 @@ using ChanSort.Api; -namespace ChanSort.Loader.Toshiba +namespace ChanSort.Loader.SamsungJ { public class DbSerializerPlugin : ISerializerPlugin { diff --git a/source/ChanSort/AboutForm.resx b/source/ChanSort/AboutForm.resx index c8e9d7e..f44c0cb 100644 --- a/source/ChanSort/AboutForm.resx +++ b/source/ChanSort/AboutForm.resx @@ -112,23 +112,23 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Vertical - + 12, 92 90, 13 - + 0 @@ -147,12 +147,12 @@ 9 - + Top, Left, Right - http://sourceforge.net/p/chansort/ + http://github.com/PredatH0r/ChanSort 108, 90 @@ -161,7 +161,7 @@ Transparent - 338, 18 + 205, 18 1 @@ -409,7 +409,7 @@ 0 - + True diff --git a/source/ChanSort/MainForm.cs b/source/ChanSort/MainForm.cs index e532cf4..323d0b3 100644 --- a/source/ChanSort/MainForm.cs +++ b/source/ChanSort/MainForm.cs @@ -25,7 +25,7 @@ namespace ChanSort.Ui { public partial class MainForm : XtraForm { - public const string AppVersion = "v2015-04-18"; + public const string AppVersion = "v2015-05-06"; private const int MaxMruEntries = 10; diff --git a/source/ChanSort/Properties/licenses.licx b/source/ChanSort/Properties/licenses.licx index e69de29..0176dd4 100644 --- a/source/ChanSort/Properties/licenses.licx +++ b/source/ChanSort/Properties/licenses.licx @@ -0,0 +1 @@ +DevExpress.XtraGrid.GridControl, DevExpress.XtraGrid.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a diff --git a/source/changelog.md b/source/changelog.md index 287db86..b5ab356 100644 --- a/source/changelog.md +++ b/source/changelog.md @@ -1,6 +1,11 @@ ChanSort Change Log =================== +2015-05-06 +- added support for Samsung J-Series DVB-T and analog channel lists +- fixed reference lists with Samsung J-Series +- web site and source code moved to http://github.com/PredatH0r/ChanSort + 2015-04-18 - added support for Samsung J-Series DVB-C and DVB-S channel lists (analog channels and DVB-T are not supported yet)