Ejemplo n.º 1
0
        /**
         * Download the provider EPG data and build the local EPG.
         */
        public async Task UpdateEPG(ProviderChannels channels)
        {
            // Log the start of this long running update process.
            config.WriteLog(false, "Beginning provider EPG update for {0}.", config.EPGURL);

            // Build a skeleton EPG using the channels in the lineup.
            EPGBuilder epg = new EPGBuilder(config, lineup);

            epg.CreateChannels(channels);

            // Fetch and merge the EPG from the provider.
            using (HttpClient client = new HttpClient())
            {
                var res = await client.GetStreamAsync(config.EPGURL);

                var streamReader = new StreamReader(res);
                epg.MergeXMLTV(streamReader);
            }

            // Serialize the EPG items to epg.xml on disk.
            var outputPath = Path.Combine(config.DataPath, "epg.xml");

            epg.WriteToDisk(outputPath);

            // Log the end of this long running update process.
            config.WriteLog(false, "Wrote updated local EPG to {0}.", outputPath);
        }
Ejemplo n.º 2
0
        /**
         * Create a channel element in the EPG for each local channel.
         */
        public void CreateChannels(ProviderChannels channels)
        {
            channels.ForEach(channel =>
            {
                // Find the local channel number associated with the channel ID.
                var channelNumber = lineup.Channels.Find(c => c.ID.Equals(channel.ID)).ChannelNumber;

                // Ignore channels with duplicate IDs.
                if (!epgChannels.ContainsKey(channel.ID))
                {
                    var channelNode = new XElement("channel", new XAttribute("id", channel.ID),
                                                   new XElement("display-name", channel.Name),
                                                   new XElement("lcn", channelNumber));

                    // Add a logo if one is available.
                    if (!String.IsNullOrEmpty(channel.Logo))
                    {
                        channelNode.Add(new XElement("icon", new XAttribute("src", channel.Logo)));
                    }

                    // Remember that we've seen this channel ID.
                    epgChannels.Add(channel.ID, channelNode);

                    // Add this channel to the guide.
                    doc.Root.Add(channelNode);
                }
            });
        }
Ejemplo n.º 3
0
        /**
         * Parse an M3U stream with a filter to remove unwanted entries.
         */
        public async Task <ProviderChannels> Parse(StreamReader stream)
        {
            var currentEntry = new ProviderChannel();
            var m3u          = new ProviderChannels();

            using (stream)
            {
                string line;
                while ((line = await stream.ReadLineAsync()) != null)
                {
                    if (line.StartsWith("#EXTM3U"))
                    {
                        // Ignore the header.
                    }
                    else
                    if (line.StartsWith("#EXTINF"))
                    {
                        // Populate the entry ID.
                        currentEntry.ID = extractAttribute(idRegex, line);

                        // Populate the entry name.
                        currentEntry.Name = extractAttribute(nameRegex, line);

                        if (logoRegex != null)
                        {
                            // Populate the entry logo.
                            currentEntry.Logo = extractAttribute(logoRegex, line);
                        }

                        if (groupRegex != null)
                        {
                            // Populate the entry group.
                            currentEntry.Group = extractAttribute(groupRegex, line);
                        }
                    }
                    else
                    if (line.StartsWith("#"))
                    {
                        // Ignore comments.
                    }
                    else
                    {
                        // Populate the entry URL.
                        currentEntry.URL = line;

                        // Filter entries from the list.
                        if ((Filter == null) || Filter.Invoke(currentEntry))
                        {
                            // Add the entry to the list.
                            m3u.Add(currentEntry);
                        }

                        // Moving to the next entry.
                        currentEntry = new ProviderChannel();
                    }
                }
            }

            return(m3u);
        }