Esempio n. 1
0
        public string GetChannelURI(Channel channel)
        {
            string streamURL        = string.Empty;
            string scriptXpath      = "/html/body/script[3]";
            string today            = DateTime.Now.ToString("yyyyMMdd");
            string pathToCachedFile = Path.Combine(Path.GetTempPath(), "MagyarTV-StreamURL-" + channel.Name + "-" + DateTime.Now.ToString("yyyy-dd-M-HH") + ".html"); // Web page is fetched at the very least on top of each hour

            HtmlAgilityPack.HtmlDocument htmlDocument = HtmlAgilityPackEx.LoadFromCachedHtmlFile(pathToCachedFile);

            if (htmlDocument == null) // If there is no cached file, load it from the given URL
            {
                HtmlWeb browser = new HtmlWeb();
                htmlDocument = browser.Load(channel.IndexFeed);
                FileStream sw = new FileStream(pathToCachedFile, FileMode.Create);
                htmlDocument.Save(sw);
                sw.Close();
            }

            HtmlAgilityPack.HtmlNodeCollection script = htmlDocument.DocumentNode.SelectNodes(scriptXpath);

            try
            {
                string   currentline = String.Empty;
                var      x           = script.ToList();
                string[] lines       = x[0].InnerText.Split(new string[] { "\n" }, System.StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < lines.Length; i++)
                {
                    currentline = lines[i].Trim();
                    if (currentline.Contains("index.m3u8"))
                    {
                        break;
                    }
                }
                string[] url_parts = currentline.Split('"');
                streamURL = string.Format("https:{0}", url_parts[3].Replace("\\", ""));
            }
            catch (Exception ex)
            {
                throw;
            }

            return(streamURL);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a list of TV Guide schedule for a given channel
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        private List <ShowEntry> GetShowScheduleList(Channel channel)
        {
            string today            = DateTime.Now.ToString("yyyyMMdd");
            string pathToCachedFile = Path.Combine(Path.GetTempPath(), "MagyarTV-TVGuide-" + channel.Name + "-" + DateTime.Now.ToString("yyyy-dd-M-HH") + ".html"); // Web page is fetched at the very least on top of each hour

            HtmlAgilityPack.HtmlDocument htmlDocument = HtmlAgilityPackEx.LoadFromCachedHtmlFile(pathToCachedFile);

            if (htmlDocument == null) // If there is no cached file, load it from the given URL
            {
                string  url     = String.Format(urlFormat, channel.TVGuideEntry, today);
                HtmlWeb browser = new HtmlWeb();
                htmlDocument = browser.Load(url);
                FileStream sw = new FileStream(pathToCachedFile, FileMode.Create);
                htmlDocument.Save(sw);
                sw.Close();
            }

            List <string>    dateSeparatorList = GetdateSeparatorList(htmlDocument);
            List <ShowEntry> showScheduleList  = GetShowList(channel, htmlDocument, dateSeparatorList);

            return(showScheduleList);
        }