private void ReadChannelList(XmlNode node, bool analog) { int i = -1; foreach (XmlNode itemNode in node.ChildNodes) { if (itemNode.LocalName != "ITEM") { continue; } ++i; GcChannel ch = new GcChannel(analog ? SignalSource.AnalogAntennaCable | SignalSource.TV : SignalSource.Digital, i, itemNode); this.ParseChannelInfoNodes(itemNode, ch); var list = this.DataRoot.GetChannelList(ch.SignalSource); this.DataRoot.AddChannel(list, ch); } }
private void LoadChannels() { if (this.doc["channelList"] == null) { throw new FileLoadException("JSON does not contain a channelList node"); } var dec = new DvbStringDecoder(this.DefaultEncoding); int i = 0; foreach (var node in this.doc["channelList"]) { var ch = new GcChannel <JToken>(0, i, node); ch.PcrPid = (int)node["pcrPid"]; ch.IsDisabled = (bool)node["disabled"]; ch.FreqInMhz = (int)node["frequency"]; if (ch.FreqInMhz >= 100000 && ch.FreqInMhz < 1000000) // DVBS is given in MHz, DVBC/T in kHz { ch.FreqInMhz /= 1000; } ch.AudioPid = (int)node["audioPid"]; ch.Source = (string)node["sourceIndex"]; if (ch.Source == "SATELLITE DIGITAL") { ch.SignalSource |= SignalSource.DvbS; } else if (ch.Source == "CABLE DIGITAL") { ch.SignalSource |= SignalSource.DvbC; } else if (ch.Source.Contains("DIGITAL")) // not seen yet. maybe DIGITAL ANTENNA? { ch.SignalSource |= SignalSource.DvbT; } ch.Skip = (bool)node["skipped"]; ch.Hidden = (bool)node["Invisible"]; ch.IsDeleted = (bool)node["deleted"]; //if (int.TryParse((string) node["satelliteId"], out var satId)) ch.Satellite = (string)node["satelliteId"]; //this.DataRoot.Satellites.TryGet(satId); ch.Encrypted = (bool)node["scrambled"]; var nameBytes = Convert.FromBase64String((string)node["chNameBase64"]); dec.GetChannelNames(nameBytes, 0, nameBytes.Length, out var name, out var shortName); ch.Name = name; ch.ShortName = shortName; ch.VideoPid = (int)node["videoPid"]; var transSystem = (string)node["transSystem"]; var tpId = (string)node["tpId"]; if (tpId != null && tpId.Length == 10) { ch.Transponder = this.DataRoot.Transponder.TryGet((int.Parse(tpId.Substring(0, 4)) << 16) + int.Parse(tpId.Substring(4))); // satId + freq, e.g. 0192126041 } ch.TransportStreamId = (int)node["TSID"]; ch.OldProgramNr = ch.IsDeleted ? -1 : (int)node["majorNumber"]; ch.ServiceType = (int)node["serviceType"]; ch.Lock = (bool)node["locked"]; if (string.IsNullOrWhiteSpace(ch.Name)) { ch.Name = (string)node["channelName"]; } ch.ServiceId = (int)node["SVCID"]; if (ch.ServiceId == 0) { ch.ServiceId = (int)node["programNum"]; } ch.OriginalNetworkId = (int)node["ONID"]; ch.SignalSource |= LookupData.Instance.IsRadioTvOrData(ch.ServiceType); if ((ch.OldProgramNr & 0x4000) != 0) { ch.OldProgramNr &= 0x3FFF; ch.SignalSource |= SignalSource.Radio; } var list = this.DataRoot.GetChannelList(ch.SignalSource); this.DataRoot.AddChannel(list, ch); } }
private void ReadChannelList(XmlNode node, bool analog) { int i = -1; foreach (XmlNode itemNode in node.ChildNodes) { if (itemNode.LocalName != "ITEM") continue; ++i; GcChannel ch = new GcChannel(analog ? SignalSource.AnalogCT | SignalSource.Tv : SignalSource.Digital, i, itemNode); this.ParseChannelInfoNodes(itemNode, ch); var list = this.DataRoot.GetChannelList(ch.SignalSource); this.DataRoot.AddChannel(list, ch); } }
private void ParseChannelInfoNodes(XmlNode itemNode, GcChannel ch, bool onlyNames = false) { bool hasHexName = false; int mapType = 0; foreach (XmlNode info in itemNode.ChildNodes) { if (onlyNames && info.LocalName != "vchName" && info.LocalName != "hexVchName") { continue; } switch (info.LocalName) { // common to ATV and DTV case "prNum": ch.OldProgramNr = int.Parse(info.InnerText); if (ch.OldProgramNr != -1) // older versions of ChanSort accidentally saved -1 instead of IsDeleted=1 { ch.OldProgramNr &= 0x3FFF; } break; case "vchName": // In old file format versions, this field contains binary data stuffed into UTF8 envelopes. that data is correct // In newer file formats, this field contains plain text but fails to hold localized characters. The hexVchName field, if present, contains the correct data then. if (!hasHexName) { ch.Name = ParseName(info.InnerText); } break; case "sourceIndex": var source = int.Parse(info.InnerText); if (source == 2) { ch.SignalSource |= SignalSource.Cable; } else if (source == 7) { ch.SignalSource |= SignalSource.Sat; } else { ch.SignalSource |= SignalSource.Antenna; } break; case "mapType": mapType = int.Parse(info.InnerText); break; case "mapAttr": if (mapType == 1) { ch.Favorites = (Favorites)int.Parse(info.InnerText); } break; case "isBlocked": ch.Lock = int.Parse(info.InnerText) == 1; break; case "isSkipped": ch.Skip = int.Parse(info.InnerText) == 1; break; // ATV case "pllData": ch.FreqInMhz = (decimal)int.Parse(info.InnerText) / 20; break; // DTV case "original_network_id": ch.OriginalNetworkId = int.Parse(info.InnerText); break; case "transport_id": ch.TransportStreamId = int.Parse(info.InnerText); break; case "service_id": // also same value in "programNo" ch.ServiceId = int.Parse(info.InnerText); break; case "serviceType": ch.ServiceType = int.Parse(info.InnerText); ch.SignalSource |= LookupData.Instance.IsRadioTvOrData(ch.ServiceType); break; case "frequency": ch.FreqInMhz = int.Parse(info.InnerText); if ((ch.SignalSource & SignalSource.Sat) == 0) { ch.FreqInMhz /= 1000; } break; case "isInvisable": // that spelling error is part of the XML ch.Hidden = int.Parse(info.InnerText) == 1; break; case "isNumUnSel": // ? break; case "isDisabled": ch.IsDisabled = int.Parse(info.InnerText) != 0; break; case "isDeleted": ch.IsDeleted = int.Parse(info.InnerText) != 0; break; case "usSatelliteHandle": int satIndex = int.Parse(info.InnerText); string satPos = this.satPositionByIndex.TryGet(satIndex); ch.SatPosition = satPos ?? satIndex.ToString(); // fallback to ensure unique UIDs ch.Satellite = satPos; break; // not present in all XML files. if present, the <vchName> might be empty or corrupted case "hexVchName": var bytes = Tools.HexDecode(info.InnerText); string longName, shortName; dvbStringDecoder.GetChannelNames(bytes, 0, bytes.Length, out longName, out shortName); ch.Name = longName; ch.ShortName = shortName; hasHexName = true; break; default: if (info.LocalName.StartsWith("favoriteIdx")) { int n = info.LocalName[11] - 'A'; var mask = 1 << n; this.Features.SupportedFavorites |= (Favorites)mask; this.Features.SortedFavorites = true; if (((int)ch.Favorites & mask) != 0) // xml element holds bad index data (250) when fav is not set { ch.SetOldPosition(n + 1, int.Parse(info.InnerText)); } } break; } } }