OnlineVideos.Sites.georgius.CeskaTelevizeUtil.GetPageVideos C# (CSharp) Méthode

GetPageVideos() private méthode

private GetPageVideos ( String pageUrl, System.Boolean first ) : List
pageUrl String
first System.Boolean
Résultat List
        private List<VideoInfo> GetPageVideos(String pageUrl, Boolean first)
        {
            // in first run we must check site number, if we are really on first site

            List<VideoInfo> pageVideos = new List<VideoInfo>();

            if (!String.IsNullOrEmpty(pageUrl))
            {
                this.nextPageUrl = String.Empty;

                if (this.currentCategory.Name == "Živě")
                {
                    System.Collections.Specialized.NameValueCollection headers = new System.Collections.Specialized.NameValueCollection();

                    headers.Add("Accept", "*/*"); // accept any content type
                    headers.Add("User-Agent", OnlineVideoSettings.Instance.UserAgent); // set the default OnlineVideos UserAgent when none specified
                    headers.Add("X-Requested-With", "XMLHttpRequest");
                    headers.Add("x-addr", "127.0.0.1");

                    String baseWebData = GetWebData("http://www.ceskatelevize.cz/ivysilani/ajax/live-box", null, null, "http://www.ceskatelevize.cz/ivysilani/podle-abecedy", null, true, false, null, null, headers, false);

                    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                    document.LoadHtml(baseWebData);

                    HtmlAgilityPack.HtmlNodeCollection liveChannels = document.DocumentNode.SelectNodes(".//div[contains(@class, 'channel')]");

                    foreach (var liveChannel in liveChannels)
                    {
                        HtmlAgilityPack.HtmlNode titleLink = liveChannel.SelectSingleNode("./p[@class='title']/a");
                        HtmlAgilityPack.HtmlNode thumbLink = liveChannel.SelectSingleNode(".//img");

                        String showUrl = (titleLink != null) ? Utils.FormatAbsoluteUrl(titleLink.Attributes["href"].Value, CeskaTelevizeUtil.baseUrl) : String.Empty;
                        String showThumbUrl = ((thumbLink != null) && thumbLink.Attributes.Contains("src")) ? thumbLink.Attributes["src"].Value : String.Empty;
                        String showTitle = (titleLink != null) ? titleLink.InnerText.Trim() : String.Empty;

                        if (String.IsNullOrEmpty(showTitle) || String.IsNullOrEmpty(showUrl))
                        {
                            continue;
                        }

                        VideoInfo videoInfo = new VideoInfo()
                        {
                            Thumb = showThumbUrl,
                            Title = showTitle,
                            VideoUrl = showUrl
                        };

                        pageVideos.Add(videoInfo);
                    }
                }
                else
                {
                    String baseWebData = GetWebData(pageUrl, forceUTF8: true);

                    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                    document.LoadHtml(baseWebData);

                    if (first)
                    {
                        HtmlAgilityPack.HtmlNode firstPageNode = document.DocumentNode.SelectSingleNode(".//a[@class='first' and @data-page='1']");
                        String firstPageUrl = Utils.FormatAbsoluteUrl(firstPageNode.Attributes["href"].Value, CeskaTelevizeUtil.baseUrl);

                        // reload first page and continue in parsing
                        baseWebData = GetWebData(firstPageUrl, forceUTF8: true);
                        document.LoadHtml(baseWebData);
                    }

                    HtmlAgilityPack.HtmlNodeCollection episodes = document.DocumentNode.SelectNodes(".//ul[@class='clearfix content']/li");

                    foreach (var episode in episodes)
                    {
                        HtmlAgilityPack.HtmlNode link = episode.SelectSingleNode("a[@class='itemImage']");

                        if (link != null)
                        {
                            HtmlAgilityPack.HtmlNode thumbLink = link.SelectSingleNode("img");
                            HtmlAgilityPack.HtmlNode title = episode.SelectSingleNode(".//h3");
                            HtmlAgilityPack.HtmlNodeCollection descriptions = episode.SelectNodes(".//p[not(*)]");

                            String showUrl = Utils.FormatAbsoluteUrl(link.Attributes["href"].Value, CeskaTelevizeUtil.baseUrl);
                            String showThumbUrl = ((thumbLink != null) && thumbLink.Attributes.Contains("src")) ? thumbLink.Attributes["src"].Value : String.Empty;
                            String showTitle = (title != null) ? title.InnerText.Trim() : String.Empty;

                            StringBuilder showDescription = new StringBuilder();

                            if (descriptions != null)
                            {
                                foreach (var descriptionItem in episode.SelectNodes(".//p[not(*)]"))
                                {
                                    showDescription.AppendLine(OnlineVideos.Helpers.StringUtils.PlainTextFromHtml(descriptionItem.InnerText.Replace('\t', ' ').Trim()));
                                }
                            }

                            if (String.IsNullOrEmpty(showTitle) || String.IsNullOrEmpty(showUrl) || String.IsNullOrEmpty(showThumbUrl))
                            {
                                continue;
                            }

                            VideoInfo videoInfo = new VideoInfo()
                            {
                                Thumb = showThumbUrl,
                                Title = showTitle,
                                VideoUrl = showUrl,
                                Description = showDescription.ToString()
                            };

                            pageVideos.Add(videoInfo);
                        }
                    }
                    
                    HtmlAgilityPack.HtmlNode nextPageLink = document.DocumentNode.SelectSingleNode(".//a[@class='next']");
                    this.nextPageUrl = (nextPageLink != null) ? Utils.FormatAbsoluteUrl(nextPageLink.Attributes["href"].Value, CeskaTelevizeUtil.baseUrl) : String.Empty;
                }
            }

            return pageVideos;
        }