public SatChannel(int slot, SignalSource presetList, DataMapping data, DataRoot dataRoot, FavoritesIndexMode sortedFavorites, IDictionary<int,string> providerNames) : base(data, sortedFavorites) { this.InitCommonData(slot, SignalSource.DvbS | presetList, data); if (!this.InUse) return; this.InitDvbData(data, providerNames); int transponderIndex = data.GetWord(_TransponderIndex); Transponder transponder = dataRoot.Transponder.TryGet(transponderIndex); if (transponder == null) { var list = dataRoot.GetChannelList(this.SignalSource|SignalSource.Tv); dataRoot.Warnings.AppendFormat("{0} channel record #{1} (Pr# {2} \"{3}\") contains invalid transponder index {4}\r\n", list.ShortCaption, slot, this.OldProgramNr, this.Name, transponderIndex); return; } Satellite sat = transponder.Satellite; this.Satellite = sat.Name; this.SatPosition = sat.OrbitalPosition; this.Polarity = transponder.Polarity; this.SymbolRate = transponder.SymbolRate; this.FreqInMhz = transponder.FrequencyInMhz; this.ChannelOrTransponder = ""; }
public void ApplyReferenceList(DataRoot refDataRoot) { foreach (var channelList in DataRoot.ChannelLists) { foreach (var channel in channelList.Channels) { channel.SetPosition(0, -1); } } StringBuilder log = new StringBuilder(); foreach (var refList in refDataRoot.ChannelLists) { var tvList = DataRoot.GetChannelList(refList.SignalSource); if (tvList == null || tvList.SignalSource != refList.SignalSource) { log.AppendFormat("Skipped reference list {0}\r\n", refList.ShortCaption); continue; } ApplyReferenceList(refDataRoot, refList, tvList); } }
public static void Save(string tvDataFile, DataRoot dataRoot) { using (var stream = new StreamWriter(tvDataFile)) { Save(stream, dataRoot); } }
public static void Save(TextWriter stream, DataRoot dataRoot) { foreach (var channelList in dataRoot.ChannelLists) { if (channelList.IsMixedSourceFavoritesList) // these pseudo-lists would create dupes for all channels { continue; } foreach (var channel in channelList.GetChannelsByNewOrder()) { if (channel.NewProgramNr == -1) { continue; } var line = string.Format("{0},{1},{2},{3},\"{4}\",{5},{6}", "", // past: channel.RecordIndex, channel.NewProgramNr, "", // past: channel.TransportStreamId, channel.Uid, channel.Name, EncodeSignalSource(channel.SignalSource), EncodeFavoritesAndFlags(channel)); stream.WriteLine(line); } } }
private void ApplyFavorites(DataRoot refDataRoot, ChannelInfo refChannel, ChannelInfo tvChannel) { if (this.DataRoot.SortedFavorites) { if (!this.DataRoot.MixedSourceFavorites || refDataRoot.MixedSourceFavorites) { tvChannel.Favorites = refChannel.Favorites & DataRoot.SupportedFavorites; if (refDataRoot.SortedFavorites) { var c = Math.Min(refChannel.FavIndex.Count, tvChannel.FavIndex.Count); for (int i = 0; i < c; i++) { tvChannel.FavIndex[i] = refChannel.FavIndex[i]; } } else { this.ApplyPrNrToFavLists(tvChannel); } } } else { tvChannel.Favorites = refChannel.Favorites & DataRoot.SupportedFavorites; } }
private void ApplyFavorites(DataRoot refDataRoot, ChannelInfo refChannel, ChannelInfo tvChannel) { if (this.DataRoot.SortedFavorites) { if (!this.DataRoot.MixedSourceFavorites || refDataRoot.MixedSourceFavorites) { tvChannel.Favorites = refChannel.Favorites & DataRoot.SupportedFavorites; if (refDataRoot.SortedFavorites) { var c = Math.Min(refDataRoot.FavListCount, this.DataRoot.FavListCount); for (int i = 0; i < c; i++) { tvChannel.SetPosition(i + 1, refChannel.GetOldPosition(i + 1)); } } else { this.ApplyPrNrToFavLists(tvChannel); } } } else { tvChannel.Favorites = refChannel.Favorites & DataRoot.SupportedFavorites; this.ApplyPrNrToFavLists(tvChannel); } }
internal DbChannel(SignalSource source, SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, IDictionary<string,bool> encryptionInfo) { this.SignalSource = source; this.RecordIndex = r.GetInt32(field["channel_handle"]); this.Bits = r.GetInt32(field["list_bits"]); bool isTv = (Bits & BITS_Tv) != 0; bool isRadio = (Bits & BITS_Radio) != 0; bool isAnalog = (source & SignalSource.Analog) != 0; if (isAnalog && !isTv) { this.IsDeleted = true; return; } if (isTv) this.SignalSource |= SignalSource.Tv; if (isRadio) this.SignalSource |= SignalSource.Radio; this.Lock = (Bits & BITS_Locked) != 0; this.OldProgramNr = r.GetInt32(field["channel_number"]); this.Favorites = this.ParseFavorites(Bits); if (isAnalog) this.ReadAnalogData(r, field); else this.ReadDvbData(r, field, dataRoot, encryptionInfo); }
protected void ReadDvbData(SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, IDictionary<string, bool> encryptionInfo) { string longName, shortName; this.GetChannelNames(r.GetString(field["channel_label"]), out longName, out shortName); this.Name = longName; this.ShortName = shortName; this.RecordOrder = r.GetInt32(field["channel_order"]); this.FreqInMhz = (decimal)r.GetInt32(field["frequency"]) / 1000; int serviceType = r.GetInt32(field["dvb_service_type"]); this.ServiceType = serviceType; this.OriginalNetworkId = r.GetInt32(field["onid"]); this.TransportStreamId = r.GetInt32(field["tsid"]); this.ServiceId = r.GetInt32(field["sid"]); int bits = r.GetInt32(field["list_bits"]); this.Favorites = this.ParseFavorites(bits); if ((this.SignalSource & SignalSource.Sat) != 0) { int satId = r.GetInt32(field["sat_id"]); var sat = dataRoot.Satellites.TryGet(satId); if (sat != null) { this.Satellite = sat.Name; this.SatPosition = sat.OrbitalPosition; int tpId = satId * 1000000 + (int)this.FreqInMhz; var tp = dataRoot.Transponder.TryGet(tpId); if (tp != null) { this.SymbolRate = tp.SymbolRate; } } } this.Encrypted = encryptionInfo.TryGet(this.Uid); }
public LnbConfig(DataMapping mapping, DataRoot dataRoot) { this.Id = mapping.GetByte("SettingId"); if (this.Id == 0) return; int satIndex = mapping.GetByte("SatIndex"); this.Satellite = dataRoot.Satellites[satIndex]; }
public void ApplyReferenceList(DataRoot refDataRoot) { foreach (var channelList in this.DataRoot.ChannelLists) { foreach (var channel in channelList.Channels) channel.SetPosition(this.SubListIndex, -1); } StringBuilder log = new StringBuilder(); foreach (var refList in refDataRoot.ChannelLists) { var tvList = this.DataRoot.GetChannelList(refList.SignalSource); if (tvList == null) { log.AppendFormat("Skipped reference list {0}\r\n", refList.ShortCaption); continue; } foreach (var refChannel in refList.Channels) { var tvChannels = tvList.GetChannelByUid(refChannel.Uid); ChannelInfo tvChannel = tvChannels.FirstOrDefault(c => c.GetPosition(this.SubListIndex) == -1); if (tvChannel != null) { tvChannel.SetPosition(this.SubListIndex, refChannel.OldProgramNr); tvChannel.Favorites = refChannel.Favorites & DataRoot.SupportedFavorites; tvChannel.Skip = refChannel.Skip; tvChannel.Lock = refChannel.Lock; tvChannel.Hidden = refChannel.Hidden; tvChannel.IsDeleted = refChannel.IsDeleted; if ((tvChannel.SignalSource & SignalSource.Analog) != 0) { tvChannel.Name = refChannel.Name; tvChannel.IsNameModified = true; } if (this.DataRoot.SortedFavorites) { if (refDataRoot.SortedFavorites) { var c = Math.Min(refChannel.FavIndex.Count, tvChannel.FavIndex.Count); for (int i = 0; i < c; i++) tvChannel.FavIndex[i] = refChannel.FavIndex[i]; } else { this.ApplyPrNrToFavLists(tvChannel); } } } else { tvChannel = new ChannelInfo(refChannel.SignalSource, refChannel.Uid, refChannel.OldProgramNr, refChannel.Name); tvList.AddChannel(tvChannel); } } } }
protected void ReadDvbData(SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, Dictionary<long, string> providers) { this.ShortName = DbSerializer.ReadUtf16(r, 16); this.RecordOrder = r.GetInt32(field["major"]); int serviceType = r.GetInt32(field["srvType"]); this.ServiceType = serviceType; this.SignalSource |= LookupData.Instance.IsRadioOrTv(serviceType); this.OriginalNetworkId = r.GetInt32(field["onid"]); this.TransportStreamId = r.GetInt32(field["tsid"]); this.ServiceId = r.GetInt32(field["progNum"]); this.VideoPid = r.GetInt32(field["vidPid"]); if (!r.IsDBNull(field["provId"])) this.Provider = providers.TryGet(r.GetInt64(field["provId"])); }
private ChannelList GetChannelList(SignalSource signalSource) { var channelList = DataRoot.GetChannelList(signalSource); if (channelList == null) { channelList = new ChannelList(signalSource, CreateCaption(signalSource)) { VisibleColumnFieldNames = Columns }; DataRoot.AddChannelList(channelList); } return(channelList); }
private void AssertRefListContent(DataRoot dataRoot, string refListFile) { CsvFileSerializer csv = new CsvFileSerializer(null, dataRoot, false); MemoryStream mem = new MemoryStream(); var writer = new StreamWriter(mem); csv.Save(writer); writer.Flush(); mem.Seek(0, SeekOrigin.Begin); var actual = new StreamReader(mem).ReadToEnd(); var expected = File.ReadAllText(refListFile); // satellite orbital position is no longer part of the UID (Samsung J series doesn't provide this information) var regex = new Regex(@",S\d+.\d+[EW](-\d+-\d+-\d+,)"); expected = regex.Replace(expected, @",S$1"); Assert.AreEqual(expected, actual); }
internal static SatChannel CreateFromProxy(ChannelInfo proxy, DataRoot dataRoot, DataMapping mapping, int rawSize) { if (proxy.Transponder == null || proxy.Transponder.Satellite == null || proxy.Transponder.Satellite.LnbConfig == null) return null; byte[] rawData = mapping.Settings.GetBytes("newRecordTemplate"); if (rawData == null) return null; mapping.SetDataPtr(rawData, 0); mapping.SetWord(_SatConfigIndex, proxy.Transponder.Satellite.LnbConfig.Id); mapping.SetWord(_TransponderIndex, proxy.Transponder.Id); mapping.SetWord(_ServiceId, proxy.ServiceId); var channel = new SatChannel(0, proxy.NewProgramNr, mapping, dataRoot); channel.Name = proxy.Name; return channel; }
public string Load(string fileName, DataRoot root, ChannelList list) { if (list.ReadOnly) return "The current channel list is read-only"; this.lineNumber = 0; this.dataRoot = root; this.channelList = list; this.warnings.Remove(0, this.warnings.Length); foreach (var channel in this.channelList.Channels) channel.NewProgramNr = -1; using (var stream = new StreamReader(fileName, Encoding.Default)) { ReadChannelsFromStream(stream); } return this.warnings.ToString(); }
public SatTransponder(int index, DataMapping mapping, DataRoot dataRoot, int satIndexFactor) : base(index) { this.mapping = mapping; this.data = mapping.Data; this.offset = mapping.BaseOffset; this.firstChannelIndex = mapping.GetWord(_FirstChannelIndex); this.lastChannelIndex = mapping.GetWord(_LastChannelIndex); this.FrequencyInMhz = mapping.GetWord(_Frequency); this.OriginalNetworkId = mapping.GetWord(_OriginalNetworkId); this.TransportStreamId = mapping.GetWord(_TransportStreamId); this.symbolRate = mapping.GetWord(_SymbolRate); if (this.symbolRate%100 >= 95) this.symbolRate = (this.symbolRate/100 + 1)*100; // note: a correction factor is applied later after all transponders were loaded (*0.5, *1, *2) this.Satellite = dataRoot.Satellites.TryGet(mapping.GetByte(_SatIndex)/satIndexFactor); }
public static void Save(TextWriter stream, DataRoot dataRoot, bool includeDeletedChannels = true) { foreach (var channelList in dataRoot.ChannelLists) { if (channelList.IsMixedSourceFavoritesList) // these pseudo-lists would create dupes for all channels { continue; } foreach (var channel in channelList.GetChannelsByNewOrder()) { if (channel.NewProgramNr == -1 && !includeDeletedChannels) { continue; } var line = $",{channel.NewProgramNr},,{channel.Uid},\"{channel.Name}\",{EncodeSignalSource(channel.SignalSource)},{EncodeFavoritesAndFlags(channel)}"; stream.WriteLine(line); } } }
protected void ReadDvbData(SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, byte[] delivery) { int stype = r.GetInt32(field["stype"]); this.SignalSource |= LookupData.Instance.IsRadioOrTv(stype); this.ServiceType = stype; int freq = r.GetInt32(field["freq"]); if ((this.SignalSource & SignalSource.Sat) != 0) { // ReSharper disable PossibleLossOfFraction this.FreqInMhz = freq/10; // ReSharper restore PossibleLossOfFraction int satId = r.GetInt32(field["physical_ch"]) >> 12; var sat = dataRoot.Satellites.TryGet(satId); if (sat != null) { this.Satellite = sat.Name; this.SatPosition = sat.OrbitalPosition; } if (delivery.Length >= 7) { this.SymbolRate = (delivery[5] >> 4)*10000 + (delivery[5] & 0x0F)*1000 + (delivery[6] >> 4)*100 + (delivery[6] & 0x0F)*10; } } else { freq /= 1000; this.FreqInMhz = freq; 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"; } this.OriginalNetworkId = r.GetInt32(field["onid"]); this.TransportStreamId = r.GetInt32(field["tsid"]); this.ServiceId = r.GetInt32(field["sid"]); }
internal DbChannel(SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, Encoding encoding) { this.RecordIndex = r.GetInt32(field["rowid"]); this.RecordOrder = r.GetInt32(field["major_channel"]); this.OldProgramNr = r.GetInt32(field["major_channel"]); int ntype = r.GetInt32(field["ntype"]); if (ntype == 1) { this.SignalSource |= SignalSource.DvbS; if (r.GetInt32(field["ya_svcid"]) >= 0) this.SignalSource |= SignalSource.Freesat; } else if (ntype == 2) this.SignalSource |= SignalSource.DvbT; else if (ntype == 3) this.SignalSource |= SignalSource.DvbC; else if (ntype == 10) this.SignalSource |= SignalSource.AnalogT | SignalSource.Tv; else if (ntype == 14) this.SignalSource |= SignalSource.AnalogC | SignalSource.Tv; else if (ntype == 15) this.SignalSource |= SignalSource.SatIP; byte[] buffer = new byte[1000]; var len = r.GetBytes(field["delivery"], 0, buffer, 0, 1000); this.AddDebug(buffer, 0, (int) len); this.Skip = r.GetInt32(field["skip"]) != 0; this.Encrypted = r.GetInt32(field["free_CA_mode"]) != 0; this.Lock = r.GetInt32(field["child_lock"]) != 0; this.ParseFavorites(r, field); this.ReadNamesWithEncodingDetection(r, field, encoding); if (ntype == 10 || ntype == 14) this.ReadAnalogData(r, field); else this.ReadDvbData(r, field, dataRoot, buffer); }
public string Load(string fileName, DataRoot root, ChannelList list) { if (list.ReadOnly) { return("The current channel list is read-only"); } this.lineNumber = 0; this.dataRoot = root; this.channelList = list; this.warnings.Remove(0, this.warnings.Length); foreach (var channel in this.channelList.Channels) { channel.NewProgramNr = -1; } using (var stream = new StreamReader(fileName, Encoding.Default)) { ReadChannelsFromStream(stream); } return(this.warnings.ToString()); }
public SatChannel(int order, int slot, DataMapping data, DataRoot dataRoot) : base(data) { this.InUse = data.GetWord(_SatConfigIndex) != 0xFFFF; if (!InUse) return; this.InitCommonData(slot, SignalSource.DvbS, data); this.InitDvbData(data); int transponderIndex = data.GetWord(_TransponderIndex); Transponder transponder = dataRoot.Transponder.TryGet(transponderIndex); Satellite sat = transponder.Satellite; this.Transponder = transponder; this.Satellite = sat.Name; this.SatPosition = sat.OrbitalPosition; this.RecordOrder = order; this.TransportStreamId = transponder.TransportStreamId; this.OriginalNetworkId = transponder.OriginalNetworkId; this.SymbolRate = transponder.SymbolRate; this.Polarity = transponder.Polarity; this.FreqInMhz = transponder.FrequencyInMhz; }
internal DbChannel(SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, Dictionary<long, string> providers, Satellite sat, Transponder tp) { var chType = r.GetInt32(field["chType"]); 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.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, 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 (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); base.IsDeleted = this.OldProgramNr == -1; }
private void AssertRefListContent(DataRoot dataRoot, string refListFile) { CsvFileSerializer csv = new CsvFileSerializer(null, dataRoot, false); MemoryStream mem = new MemoryStream(); var writer = new StreamWriter(mem); csv.Save(writer); writer.Flush(); mem.Seek(0, SeekOrigin.Begin); var actual = new StreamReader(mem).ReadToEnd(); var expected = File.ReadAllText(refListFile); Assert.AreEqual(expected, actual); }
private void ReadChannel(string line, int lineNr) { var parts = CsvFile.Parse(line, ','); if (parts.Count < 5) { return; } if (!int.TryParse(parts[1], out var programNr)) { return; } var uid = parts[3]; if (uid.StartsWith("S")) // remove satellite orbital position from UID ... not all TV models provide this information { uid = "S" + uid.Substring(uid.IndexOf('-')); } var signalSource = GetSignalSource(ref programNr, uid, parts); if (signalSource == 0) { return; } var channelList = GetChannelList(signalSource); if (channelList == null) { return; } var name = parts[4]; var channel = new ChannelInfo(signalSource, lineNr, programNr, name); var uidParts = uid.Split('-'); if (uidParts.Length >= 4) { if (int.TryParse(uidParts[1], out var val)) { channel.OriginalNetworkId = val; } if (int.TryParse(uidParts[2], out val)) { channel.TransportStreamId = val; } if (int.TryParse(uidParts[3], out val)) { channel.ServiceId = val; } } if (parts.Count >= 7) { ApplyFlags(channel, parts[6]); } DataRoot.AddChannel(channelList, channel); }
private bool LoadTvDataFile(ISerializerPlugin plugin, string tvDataFile) { if (!File.Exists(tvDataFile)) { XtraMessageBox.Show(this, Resources.MainForm_LoadTvDataFile_FileNotFound_Caption, string.Format(Resources.MainForm_LoadTvDataFile_FileNotFound_Message, tvDataFile), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } if (plugin == null) plugin = this.GetPluginForFile(tvDataFile); // abort action if there is no currentTvSerializer for the input file var serializer = plugin == null ? null : plugin.CreateSerializer(tvDataFile); if (serializer == null) return false; if (!this.PromptSaveAndContinue()) return false; serializer.DefaultEncoding = this.defaultEncoding; serializer.Load(); this.SetFileName(tvDataFile); this.currentPlugin = plugin; this.currentTvSerializer = serializer; this.dataRoot = this.currentTvSerializer.DataRoot; this.AddFileToMruList(this.currentTvFile); this.UpdateMruMenu(); return true; }
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); } }
/// <summary> /// Applies the ordering of a reference list to the TV list /// </summary> /// <param name="refDataRoot">object representing the whole reference list file</param> /// <param name="refList">the particular ChannelList to take the order from</param> /// <param name="refListPosIndex">the sublist index in the reference list that should be applied (0=main channel number, 1=fav1, ...)</param> /// <param name="tvList">the particular ChannelList to apply the order to</param> /// <param name="tvListPosIndex">the sublist index in the target list that should be changed (-1=main and all favs, 0=main channel number, 1=fav1, ...)</param> /// <param name="addProxyChannels">if true, a placeholder channel will be created in the tvList if there is no matching TV channel for a reference channel</param> /// <param name="positionOffset">can be used to shift the Pr# of the reference list so avoid conflicts with already assigned Pr# in the TV list</param> /// <param name="chanFilter">a function which is called for each channel in the reference list (with 2nd parameter=true) and TV list (2nd parameter=false) to determine if the channel is part of the reordering /// This is used to filter for analog/digital, radio/TV, antenna/cable/sat/ip /// </param> /// <param name="overwrite">controls whether Pr# will be reassigned to the reference channel when they are already in-use in the TV list</param> /// <param name="consecutive">when true, consecutive numbers will be used instead of the Pr# in the reference list when applying the order</param> public void ApplyReferenceList(DataRoot refDataRoot, ChannelList refList, int refListPosIndex, ChannelList tvList, int tvListPosIndex, bool addProxyChannels = true, int positionOffset = 0, Func <ChannelInfo, bool, bool> chanFilter = null, bool overwrite = true, bool consecutive = false) { // create Hashtable for exact channel lookup // the UID of a TV channel list contains a source-indicator (Analog, Cable, Sat), which may be undefined in the reference list) var onidTsidSid = new Dictionary <long, List <ChannelInfo> >(); var chansByNewNr = new Dictionary <int, List <ChannelInfo> >(); foreach (var channel in tvList.Channels) { var key = DvbKey(channel.OriginalNetworkId, channel.TransportStreamId, channel.ServiceId); if (key == 0) { continue; } var list = onidTsidSid.TryGet(key); if (list == null) { list = new List <ChannelInfo>(); onidTsidSid.Add(key, list); } list.Add(channel); } var incNr = 1 + positionOffset; var refPos = refListPosIndex < 0 || !refDataRoot.SortedFavorites ? 0 : refListPosIndex; var refChannels = refList.Channels.OrderBy(ch => ch.GetOldPosition(refPos)).ToList(); var newPos = Math.Max(0, tvListPosIndex); foreach (var refChannel in refChannels) { if (!(chanFilter?.Invoke(refChannel, true) ?? true)) { continue; } var tvChannel = FindChannel(tvList, newPos, refChannel, onidTsidSid); if (tvChannel != null) { if (!(chanFilter?.Invoke(tvChannel, false) ?? true)) { continue; } var newNr = consecutive ? incNr++ : refChannel.GetOldPosition(refPos) + positionOffset; // handle conflicts when the number is already in-use if (chansByNewNr.TryGetValue(newNr, out var curChans)) { if (!overwrite) { continue; } foreach (var chan in curChans) { chan.SetPosition(newPos, -1); } } else { curChans = new List <ChannelInfo>(); chansByNewNr[newNr] = curChans; } curChans.Add(tvChannel); tvChannel.SetPosition(newPos, newNr); if (refDataRoot.CanSkip && this.DataRoot.CanSkip) { tvChannel.Skip = refChannel.Skip; } if (refDataRoot.CanLock && this.DataRoot.CanLock) { tvChannel.Lock = refChannel.Lock; } if (refDataRoot.CanHide && this.DataRoot.CanHide) { tvChannel.Hidden = refChannel.Hidden; } //tvChannel.IsDeleted = refChannel.IsDeleted; if ((tvChannel.SignalSource & SignalSource.Analog) != 0 && !string.IsNullOrEmpty(refChannel.Name)) { tvChannel.Name = refChannel.Name; tvChannel.IsNameModified = true; } if (tvListPosIndex == -1) { ApplyFavorites(refDataRoot, refChannel, tvChannel); } } else if (addProxyChannels) { tvChannel = new ChannelInfo(refChannel.SignalSource, refChannel.Uid, refChannel.OldProgramNr, refChannel.Name); tvList.AddChannel(tvChannel); } } }
/// <summary> /// Applies the ordering of a reference list to the TV list /// </summary> /// <param name="refDataRoot">object representing the whole reference list file</param> /// <param name="refList">the particular ChannelList to take the order from</param> /// <param name="tvList">the particular ChannelList to apply the order to</param> /// <param name="addProxyChannels">if true, a placeholder channel will be created in the tvList if there is no matching TV channel for a reference channel</param> /// <param name="positionOffset">can be used to shift the Pr# of the reference list so avoid conflicts with already assigned Pr# in the TV list</param> /// <param name="chanFilter">a function which is called for each channel in the reference list (with 2nd parameter=true) and TV list (2nd parameter=false) to determine if the channel is part of the reordering /// This is used to filter for analog/digital, radio/TV, antenna/cable/sat/ip /// </param> /// <param name="overwrite">controls whether Pr# will be reassigned to the reference channel when they are already in-use in the TV list</param> /// <param name="consecutive">when true, consecutive numbers will be used instead of the Pr# in the reference list when applying the order</param> public void ApplyReferenceList(DataRoot refDataRoot, ChannelList refList, ChannelList tvList, bool addProxyChannels = true, int positionOffset = 0, Func <ChannelInfo, bool, bool> chanFilter = null, bool overwrite = true, bool consecutive = false) { // create Hashtable for exact channel lookup // the UID of a TV channel list contains a source-indicator (Analog, Cable, Sat), which may be undefined in the reference list) var onidTsidSid = new Dictionary <long, List <ChannelInfo> >(); foreach (var channel in tvList.Channels) { var key = DvbKey(channel.OriginalNetworkId, channel.TransportStreamId, channel.ServiceId); var list = onidTsidSid.TryGet(key); if (list == null) { list = new List <ChannelInfo>(); onidTsidSid.Add(key, list); } list.Add(channel); } var incNr = 1 + positionOffset; foreach (var refChannel in refList.Channels.OrderBy(ch => ch.OldProgramNr)) { if (!(chanFilter?.Invoke(refChannel, true) ?? true)) { continue; } var tvChannels = tvList.GetChannelByUid(refChannel.Uid); // try to find matching channels based on ONID+TSID+SID if (tvChannels.Count == 0) { var key = DvbKey(refChannel.OriginalNetworkId, refChannel.TransportStreamId, refChannel.ServiceId); List <ChannelInfo> candidates; if (key != 0 && onidTsidSid.TryGetValue(key, out candidates)) { tvChannels = candidates; // narrow the list down further when a transponder is also provided (i.e. the same TV channel can be received on multiple DVB-T frequencies) if (tvChannels.Count > 1 && !string.IsNullOrEmpty(refChannel.ChannelOrTransponder)) { candidates = tvChannels.Where(ch => ch.ChannelOrTransponder == refChannel.ChannelOrTransponder).ToList(); if (candidates.Count > 0) { tvChannels = candidates; } } } } // try to find matching channels by name if (tvChannels.Count == 0 && !string.IsNullOrWhiteSpace(refChannel.Name)) { tvChannels = tvList.GetChannelByName(refChannel.Name).ToList(); } // get the first unassigned channel from the candidates (e.g. when matching by non-unique names), or fall back to the first matching channel (e.g. by unique ID) ChannelInfo tvChannel = tvChannels.FirstOrDefault(c => c.GetPosition(0) == -1); if (tvChannel == null && tvChannels.Count > 0) { tvChannel = tvChannels[0]; } if (tvChannel != null) { if (!(chanFilter?.Invoke(tvChannel, false) ?? true)) { continue; } var newNr = consecutive ? incNr++ : refChannel.OldProgramNr + positionOffset; // handle conflicts when the number is already in-use var curChans = tvList.GetChannelByNewProgNr(newNr); if (!overwrite && curChans.Any()) { continue; } foreach (var chan in curChans) { chan.NewProgramNr = -1; } tvChannel.SetPosition(0, newNr); tvChannel.Skip = refChannel.Skip; tvChannel.Lock = refChannel.Lock; tvChannel.Hidden = refChannel.Hidden; tvChannel.IsDeleted = refChannel.IsDeleted; if ((tvChannel.SignalSource & SignalSource.Analog) != 0 && !string.IsNullOrEmpty(refChannel.Name)) { tvChannel.Name = refChannel.Name; tvChannel.IsNameModified = true; } ApplyFavorites(refDataRoot, refChannel, tvChannel); } else if (addProxyChannels) { tvChannel = new ChannelInfo(refChannel.SignalSource, refChannel.Uid, refChannel.OldProgramNr, refChannel.Name); tvList.AddChannel(tvChannel); } } }
public void ApplyReferenceList(DataRoot refDataRoot) { foreach (var channelList in this.DataRoot.ChannelLists) { foreach (var channel in channelList.Channels) { channel.SetPosition(this.SubListIndex, -1); } } StringBuilder log = new StringBuilder(); foreach (var refList in refDataRoot.ChannelLists) { var tvList = this.DataRoot.GetChannelList(refList.SignalSource); if (tvList == null) { log.AppendFormat("Skipped reference list {0}\r\n", refList.ShortCaption); continue; } foreach (var refChannel in refList.Channels) { var tvChannels = tvList.GetChannelByUid(refChannel.Uid); ChannelInfo tvChannel = tvChannels.FirstOrDefault(c => c.GetPosition(this.SubListIndex) == -1); if (tvChannel != null) { tvChannel.SetPosition(this.SubListIndex, refChannel.OldProgramNr); tvChannel.Favorites = refChannel.Favorites & DataRoot.SupportedFavorites; tvChannel.Skip = refChannel.Skip; tvChannel.Lock = refChannel.Lock; tvChannel.Hidden = refChannel.Hidden; tvChannel.IsDeleted = refChannel.IsDeleted; if ((tvChannel.SignalSource & SignalSource.Analog) != 0) { tvChannel.Name = refChannel.Name; tvChannel.IsNameModified = true; } if (this.DataRoot.SortedFavorites) { if (refDataRoot.SortedFavorites) { var c = Math.Min(refChannel.FavIndex.Count, tvChannel.FavIndex.Count); for (int i = 0; i < c; i++) { tvChannel.FavIndex[i] = refChannel.FavIndex[i]; } } else { this.ApplyPrNrToFavLists(tvChannel); } } } else { tvChannel = new ChannelInfo(refChannel.SignalSource, refChannel.Uid, refChannel.OldProgramNr, refChannel.Name); tvList.AddChannel(tvChannel); } } } }
public CsvFileSerializer(string fileName, DataRoot dataRoot, bool addChannels) { this.fileName = fileName; this.dataRoot = dataRoot; this.addChannels = addChannels; }