From abb2c904467e5f5eae85d03b13247e789f589876 Mon Sep 17 00:00:00 2001 From: Horst Beham Date: Fri, 20 Mar 2020 01:25:27 +0100 Subject: [PATCH] - another attempt to get Samsung 1352.0 format working It seems that when a user changes a program number through the TVs menu, it creates a cloned record and sets the SRV_EXT_APP.recState=1 So when there are 2 channels with the same program number, the one with recState=NULL should be ignored --- source/ChanSort.Loader.SamsungJ/DbChannel.cs | 4 +- .../ChanSort.Loader.SamsungJ/DbSerializer.cs | 63 ++++++++++++------- source/changelog.md | 3 + 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/source/ChanSort.Loader.SamsungJ/DbChannel.cs b/source/ChanSort.Loader.SamsungJ/DbChannel.cs index d5281ef0..34eb90a9 100644 --- a/source/ChanSort.Loader.SamsungJ/DbChannel.cs +++ b/source/ChanSort.Loader.SamsungJ/DbChannel.cs @@ -20,7 +20,7 @@ internal DbChannel(SQLiteDataReader r, IDictionary field, DataRoot (this.SignalSource & SignalSource.DvbC) == SignalSource.DvbC ? LookupData.Instance.GetDvbcTransponder(this.FreqInMhz).ToString() : (this.SignalSource & SignalSource.DvbS) == SignalSource.DvbS ? LookupData.Instance.GetAstraTransponder((int)this.FreqInMhz).ToString() : ""; - this.Name = DbSerializer.ReadUtf16(r, 6); + this.Name = DbSerializer.ReadUtf16(r, field["srvName"]); this.Hidden = r.GetBoolean(field["hidden"]); this.Encrypted = r.GetBoolean(field["scrambled"]); this.Lock = r.GetBoolean(field["lockMode"]); @@ -58,7 +58,7 @@ private void ReadAnalogData(SQLiteDataReader r, IDictionary field) #region ReadDvbData() protected void ReadDvbData(SQLiteDataReader r, IDictionary field, DataRoot dataRoot, Dictionary providers) { - this.ShortName = DbSerializer.ReadUtf16(r, 16); + this.ShortName = DbSerializer.ReadUtf16(r, field["srvName"]); this.RecordOrder = r.GetInt32(field["major"]); int serviceType = r.GetInt32(field["srvType"]); this.ServiceType = serviceType; diff --git a/source/ChanSort.Loader.SamsungJ/DbSerializer.cs b/source/ChanSort.Loader.SamsungJ/DbSerializer.cs index e8bb25ef..406f36f3 100644 --- a/source/ChanSort.Loader.SamsungJ/DbSerializer.cs +++ b/source/ChanSort.Loader.SamsungJ/DbSerializer.cs @@ -18,7 +18,7 @@ class DbSerializer : SerializerBase private readonly Dictionary dbPathByChannelList = new Dictionary(); private readonly List tableNames = new List(); - private enum FileType { Unknown, SatDb, ChannelDbDvb, ChannelDbAnalog } + private enum FileType { Unknown, SatDb, ChannelDbDvb, ChannelDbAnalog, ChannelDbIp } #region ctor() public DbSerializer(string inputFile) : base(inputFile) @@ -32,7 +32,7 @@ public DbSerializer(string inputFile) : base(inputFile) this.Features.CanHideChannels = true; this.Features.SupportedFavorites = Favorites.A | Favorites.B | Favorites.C | Favorites.D | Favorites.E; this.Features.SortedFavorites = true; - this.Features.AllowGapsInFavNumbers = false; + this.Features.AllowGapsInFavNumbers = true; } #endregion @@ -81,12 +81,12 @@ public override void Load() switch (type) { - case FileType.SatDb: break; - case FileType.ChannelDbAnalog: - ReadChannelDatabase(conn, filePath, false); + case FileType.SatDb: break; + case FileType.ChannelDbAnalog: case FileType.ChannelDbDvb: - ReadChannelDatabase(conn, filePath, true); + case FileType.ChannelDbIp: + ReadChannelDatabase(conn, filePath, type); break; } } @@ -132,6 +132,9 @@ private FileType DetectFileType(SQLiteCommand cmd) if (tableNames.Contains("CHNL") && tableNames.Contains("SRV") && tableNames.Contains("SRV_ANL")) return FileType.ChannelDbAnalog; + //if (tableNames.Contains("CHNL") && tableNames.Contains("SRV") && tableNames.Contains("SRV_IP")) + // return FileType.ChannelDbIp; + return FileType.Unknown; } #endregion @@ -194,13 +197,13 @@ private void ReadTransponders(SQLiteCommand cmd) #region ReadChannelDatabase() - private void ReadChannelDatabase(SQLiteConnection conn, string dbPath, bool digital) + private void ReadChannelDatabase(SQLiteConnection conn, string dbPath, FileType fileType) { this.channelById.Clear(); using (var cmd = conn.CreateCommand()) { - var providers = digital ? this.ReadProviders(cmd) : null; - var channelList = this.ReadChannels(cmd, dbPath, providers, digital); + var providers = fileType == FileType.ChannelDbDvb ? this.ReadProviders(cmd) : null; + var channelList = this.ReadChannels(cmd, dbPath, providers, fileType); this.ReadFavorites(cmd); this.dbPathByChannelList.Add(channelList, dbPath); } @@ -228,19 +231,19 @@ private Dictionary ReadProviders(SQLiteCommand cmd) #endregion #region ReadChannels() - private ChannelList ReadChannels(SQLiteCommand cmd, string dbPath, Dictionary providers, bool digital) + private ChannelList ReadChannels(SQLiteCommand cmd, string dbPath, Dictionary providers, FileType fileType) { - var signalSource = DetectSignalSource(cmd, digital); + var signalSource = DetectSignalSource(cmd, fileType); string name = Path.GetFileName(dbPath); ChannelList channelList = new ChannelList(signalSource, name); - string table = digital ? "SRV_DVB" : "SRV_ANL"; + string table = fileType == FileType.ChannelDbDvb ? "SRV_DVB" : fileType == FileType.ChannelDbAnalog ? "SRV_ANL" : "SRV_IP"; List fieldNames = new List { "chType", "chNum", "freq", // CHNL - "SRV.srvId", "major", "progNum", "cast(srvName as blob)", "srvType", "hidden", "scrambled", "lockMode", "numSel", // SRV + "SRV.srvId", "major", "progNum", "cast(srvName as blob) srvName", "srvType", "hidden", "scrambled", "lockMode", "numSel", "elim" // SRV }; - if (digital) - fieldNames.AddRange(new[] {"onid", "tsid", "vidPid", "provId", "cast(shrtSrvName as blob)", "lcn"}); // SRV_DVB + if (fileType == FileType.ChannelDbDvb) + fieldNames.AddRange(new[] {"onid", "tsid", "vidPid", "provId", "cast(shrtSrvName as blob) shrtSrvName", "lcn"}); // SRV_DVB var sql = this.BuildQuery(table, fieldNames); var fields = this.GetFieldMap(fieldNames); @@ -248,16 +251,25 @@ private ChannelList ReadChannels(SQLiteCommand cmd, string dbPath, Dictionary fieldNames) } sql += " from " + table + " inner join SRV on SRV.srvId="+table+".srvId inner join CHNL on CHNL.chId=SRV.chId"; - if (this.tableNames.Contains("SRV_EXT_APP")) // in format 1352.0 there are duplicate "major" values in SRV and this recState seems to be the only indicator for "deleted" channels - sql += " inner join SRV_EXT_APP on SRV_EXT_APP.srvId=SRV.srvId and SRV_EXT_APP.recState is null"; + if (this.tableNames.Contains("SRV_EXT_APP")) // in format 1352.0 there are duplicate "major" values in SRV and this recState seems to be the only difference + sql += " inner join SRV_EXT_APP on SRV_EXT_APP.srvId=SRV.srvId order by SRV.major, ifnull(SRV_EXT_APP.recState,0) desc"; return sql; } @@ -324,7 +338,11 @@ private IDictionary GetFieldMap(IList fieldNames) { Dictionary field = new Dictionary(); for (int i = 0; i < fieldNames.Count; i++) - field[fieldNames[i]] = i; + { + var idx = fieldNames[i].LastIndexOf(' ') + 1; + field[fieldNames[i].Substring(idx)] = i; + } + return field; } #endregion @@ -334,17 +352,18 @@ private void ReadFavorites(SQLiteCommand cmd) { cmd.CommandText = "select srvId, fav, pos from SRV_FAV"; var r = cmd.ExecuteReader(); + int favPosAdjust = tableNames.Contains("SRV_EXT_APP") ? 0 : 1; while (r.Read()) { var channel = this.channelById.TryGet(r.GetInt64(0)); if (channel == null) continue; int fav = r.GetInt32(1) - 1; // fav values start with 1 in the table - int pos = r.GetInt32(2); // pos values start with 0 + int pos = r.GetInt32(2) + favPosAdjust; // pos values start with 0 or 1 if (pos >= 0) { channel.Favorites |= (Favorites) (1 << fav); - channel.OldFavIndex[fav] = pos + 1; + channel.OldFavIndex[fav] = pos; } } } diff --git a/source/changelog.md b/source/changelog.md index a4710bb4..920c4862 100644 --- a/source/changelog.md +++ b/source/changelog.md @@ -1,6 +1,9 @@ ChanSort Change Log =================== +2020-03-20 +- another attempt to get Samsung 1352.0 format working + 2020-03-15 - repackaged to include Polish translation files