/// <summary>
        /// Acquire and process OpenTV data.
        /// </summary>
        /// <param name="dataProvider">A sampe data provider.</param>
        /// <param name="worker">The background worker that is running this collection.</param>
        /// <returns>A CollectorReply code.</returns>
        public override CollectorReply Process(ISampleDataProvider dataProvider, BackgroundWorker worker)
        {
            OpenTVProgramCategory.LoadFromCode(RunParameters.Instance.CountryCode.Trim());
            CustomProgramCategory.Load();
            ParentalRating.Load();

            bool referenceTablesLoaded = SingleTreeDictionaryEntry.Load(Path.Combine(RunParameters.ConfigDirectory, "Huffman Dictionary " + RunParameters.Instance.CountryCode.Trim() + ".cfg"));

            if (!referenceTablesLoaded)
            {
                return(CollectorReply.ReferenceDataError);
            }

            GetStationData(dataProvider, worker);
            if (worker.CancellationPending)
            {
                return(CollectorReply.Cancelled);
            }

            GetBouquetSections(dataProvider, worker);
            if (worker.CancellationPending)
            {
                return(CollectorReply.Cancelled);
            }

            getTitleSections(dataProvider, worker);
            if (worker.CancellationPending)
            {
                return(CollectorReply.Cancelled);
            }

            getSummarySections(dataProvider, worker);

            return(CollectorReply.OK);
        }
        /// <summary>
        /// Parse the descriptor.
        /// </summary>
        /// <param name="byteData">The MPEG2 section containing the descriptor.</param>
        /// <param name="index">Index of the byte in the MPEG2 section following the descriptor length.</param>
        internal override void Process(byte[] byteData, int index)
        {
            lastIndex = index;

            startBytes = Utils.GetBytes(byteData, lastIndex, 2);

            int startIndex;

            if ((byteData[lastIndex + 1] & 0xf8) == 0x80)
            {
                compressedLength = Length;

                if ((byteData[lastIndex] & 0x40) != 0)
                {
                    decompressedLength = (byteData[lastIndex] & 0x3f) | ((byteData[lastIndex + 1] << 6) & 0xff);
                }
                else
                {
                    decompressedLength = byteData[lastIndex] & 0x3f;
                }

                startIndex       = lastIndex + 2;
                loggedStartIndex = 2;
            }
            else
            {
                compressedLength   = Length - 1;
                decompressedLength = byteData[lastIndex] & 0x7f;
                startIndex         = lastIndex + 1;
                loggedStartIndex   = 1;
            }

            if (compressedLength <= 0)
            {
                lastIndex = index + Length;
                return;
            }

            eventNameBytes = Utils.GetBytes(byteData, startIndex, compressedLength);

            if (Table <= 0x80)
            {
                huffmanTable = 1;
            }
            else
            {
                huffmanTable = 2;
            }

            eventName = SingleTreeDictionaryEntry.DecodeData(huffmanTable, eventNameBytes);

            lastIndex = index + Length;

            Validate();
        }
        /// <summary>
        /// Acquire and process Dish Network data.
        /// </summary>
        /// <param name="dataProvider">A sample data provider.</param>
        /// <param name="worker">The background worker that is running this collection.</param>
        /// <returns>A CollectorReply code.</returns>
        public override CollectorReply Process(ISampleDataProvider dataProvider, BackgroundWorker worker)
        {
            DishNetworkProgramCategory.Load();
            CustomProgramCategory.Load();
            ParentalRating.Load();

            SingleTreeDictionaryEntry.Load(Path.Combine(RunParameters.ConfigDirectory, "Huffman Dictionary Dish Network 128.cfg"), 1);
            SingleTreeDictionaryEntry.Load(Path.Combine(RunParameters.ConfigDirectory, "Huffman Dictionary Dish Network 255.cfg"), 2);
            SingleTreeDictionaryEntry.OffsetStart = false;

            GetStationData(dataProvider, worker);
            if (worker.CancellationPending)
            {
                return(CollectorReply.Cancelled);
            }

            getDishNetworkData(dataProvider, worker);

            return(CollectorReply.OK);
        }
        /// <summary>
        /// Parse the descriptor.
        /// </summary>
        /// <param name="byteData">The MPEG2 section containing the descriptor.</param>
        /// <param name="index">Index of the byte in the MPEG2 section following the descriptor length.</param>
        internal override void Process(byte[] byteData, int index)
        {
            lastIndex = index;

            startBytes = Utils.GetBytes(byteData, lastIndex, 2);

            int startIndex;

            compressedLength   = Length - 2;
            decompressedLength = byteData[lastIndex] & 0x7f;
            startIndex         = lastIndex + 2;
            loggedStartIndex   = 2;

            if (compressedLength <= 0)
            {
                lastIndex = index + Length;
                return;
            }

            supplementaryInformationBytes = Utils.GetBytes(byteData, startIndex, Length - (startIndex - index));

            if (Table <= 0x80)
            {
                huffmanTable = 1;
            }
            else
            {
                huffmanTable = 2;
            }

            supplementaryInformation = SingleTreeDictionaryEntry.DecodeData(huffmanTable, supplementaryInformationBytes);

            lastIndex = index + Length;

            Validate();
        }
Example #5
0
        /// <summary>
        /// Parse the descriptor.
        /// </summary>
        /// <param name="byteData">The MPEG2 section containing the descriptor.</param>
        /// <param name="index">Index of the byte in the MPEG2 section following the descriptor length.</param>
        internal override void Process(byte[] byteData, int index)
        {
            lastIndex = index;

            startBytes = Utils.GetBytes(byteData, lastIndex, 2);

            int startIndex;

            if ((byteData[lastIndex + 1] & 0xf8) == 0x80)
            {
                compressedLength = Length;

                if ((byteData[lastIndex] & 0x40) != 0)
                {
                    decompressedLength = (byteData[lastIndex] & 0x3f) | ((byteData[lastIndex + 1] << 6) & 0xff);
                }
                else
                {
                    decompressedLength = byteData[lastIndex] & 0x3f;
                }

                startIndex       = lastIndex + 2;
                loggedStartIndex = 2;
            }
            else
            {
                compressedLength   = Length - 1;
                decompressedLength = byteData[lastIndex] & 0x7f;
                startIndex         = lastIndex + 1;
                loggedStartIndex   = 1;
            }

            if (compressedLength <= 0)
            {
                lastIndex = index + Length;
                return;
            }

            eventDescriptionBytes = Utils.GetBytes(byteData, startIndex, compressedLength);

            if (Table <= 0x80)
            {
                huffmanTable = 1;
            }
            else
            {
                huffmanTable = 2;
            }

            originalDescription = SingleTreeDictionaryEntry.DecodeData(huffmanTable, eventDescriptionBytes);

            int splitter = originalDescription.IndexOf("<0D>");

            if (splitter != -1)
            {
                subTitle         = originalDescription.Substring(0, splitter);
                eventDescription = originalDescription.Substring(splitter + 5, decompressedLength - subTitle.Length - 2);
            }
            else
            {
                eventDescription = originalDescription.Substring(0, decompressedLength);
            }

            int closedCaptionsIndex = eventDescription.IndexOf(" (CC)");

            closedCaptions = closedCaptionsIndex != -1;
            if (closedCaptions)
            {
                eventDescription = eventDescription = eventDescription.Remove(closedCaptionsIndex, 5);
            }

            int highDefinitionIndex = eventDescription.IndexOf(" (HD)");

            highDefinition = highDefinitionIndex != -1;
            if (highDefinition)
            {
                eventDescription = eventDescription.Remove(highDefinitionIndex, 5);
            }

            int stereoIndex = eventDescription.IndexOf(" (Stereo)");

            stereo = stereoIndex != -1;
            if (stereo)
            {
                eventDescription = eventDescription.Remove(stereoIndex, 9);
            }

            int dateIndex = eventDescription.IndexOf(" (19");

            if (dateIndex == -1)
            {
                dateIndex = eventDescription.IndexOf(" (20");
            }
            if (dateIndex != -1)
            {
                date             = eventDescription.Substring(dateIndex + 2, 4);
                eventDescription = eventDescription.Remove(dateIndex, 7);
            }

            if (eventDescription.StartsWith("Movie."))
            {
                eventDescription = eventDescription.Remove(0, 6);
            }
            else
            {
                if (eventDescription.StartsWith("Sports."))
                {
                    eventDescription = eventDescription.Remove(0, 7);
                }
                else
                {
                    if (eventDescription.StartsWith("News/Business."))
                    {
                        eventDescription = eventDescription.Remove(0, 14);
                    }
                    else
                    {
                        if (eventDescription.StartsWith("Family/Children."))
                        {
                            eventDescription = eventDescription.Remove(0, 16);
                        }
                        else
                        {
                            if (eventDescription.StartsWith("Education."))
                            {
                                eventDescription = eventDescription.Remove(0, 10);
                            }
                            else
                            {
                                if (eventDescription.StartsWith("Series/Special."))
                                {
                                    eventDescription = eventDescription.Remove(0, 15);
                                }
                                else
                                {
                                    if (eventDescription.StartsWith("Music/Art."))
                                    {
                                        eventDescription = eventDescription.Remove(0, 10);
                                    }
                                    else
                                    {
                                        if (eventDescription.StartsWith("Religious."))
                                        {
                                            eventDescription = eventDescription.Remove(0, 10);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            int newIndex = eventDescription.IndexOf(" New.");

            if (newIndex != -1)
            {
                eventDescription = eventDescription.Remove(newIndex, 5);
            }

            eventDescription = eventDescription.Trim();

            string[] castParts = eventDescription.Split(new char[] { '.' });
            if (castParts.Length > 2)
            {
                if (!castParts[0].Trim().StartsWith("Scheduled: "))
                {
                    cast = getCast(castParts[0]);
                    if (cast != null)
                    {
                        eventDescription = eventDescription.Remove(0, castParts[0].Length + 1).Trim();
                    }
                }
            }

            lastIndex = index + Length;

            Validate();
        }