예제 #1
0
 public virtual void AddChannel(ChannelList list, ChannelInfo channel)
 {
     if (list == null)
       {
     warnings.AppendFormat("No list found to add channel '{0}'\r\n", channel);
     return;
       }
       string warning = list.AddChannel(channel);
       if (warning != null)
     this.Warnings.AppendLine(warning);
 }
예제 #2
0
        public virtual void AddChannel(ChannelList list, ChannelInfo channel)
        {
            if (list == null)
            {
                this.Warnings.AppendFormat("No list found to add channel '{0}'\r\n", channel);
                return;
            }
            string warning = list.AddChannel(channel);

            if (warning != null)
            {
                this.Warnings.AppendLine(warning);
            }
        }
예제 #3
0
        /// <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);
                }
            }
        }
예제 #4
0
        private void ReadChannel(string line)
        {
            var parts = CsvFile.Parse(line, ',');

            if (parts.Count < 5)
            {
                return;
            }
            int programNr;

            if (!int.TryParse(parts[1], out programNr))
            {
                return;
            }
            string 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('-'));
            }
            SignalSource signalSource = GetSignalSource(ref programNr, uid, parts);

            if (signalSource == 0)
            {
                return;
            }

            string      name        = parts[4];
            ChannelList channelList = this.GetInitiallyClearedChannelList(signalSource);

            if (channelList == null)
            {
                return;
            }

            IEnumerable <ChannelInfo> channels = FindChannels(channelList, name, uid);
            var channel = channels == null ? null : channels.FirstOrDefault(c => c.NewProgramNr == -1);

            if (channel != null)
            {
                if (!this.addChannels)
                {
                    channel.NewProgramNr = programNr;
                    if ((channel.SignalSource & SignalSource.Analog) != 0)
                    {
                        channel.Name           = name;
                        channel.IsNameModified = true;
                    }
                    if (parts.Count >= 7)
                    {
                        ApplyFlags(channel, parts[6]);
                    }
                }
            }
            else if (parts.Count >= 6) // create proxy channel when using the new ref-list format
            {
                channel = new ChannelInfo(signalSource, uid, programNr, name);
                if (addChannels)
                {
                    channel.NewProgramNr = -1;
                    channel.OldProgramNr = programNr;
                }
                channelList.AddChannel(channel);
            }
        }
예제 #5
0
        /// <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);
                }
            }
        }