Ejemplo n.º 1
0
        private List <VideoInfo> GetPageVideos(String pageUrl)
        {
            List <VideoInfo> pageVideos = new List <VideoInfo>();

            if (!String.IsNullOrEmpty(pageUrl))
            {
                this.nextPageUrl = String.Empty;
                if (this.currentCategory.Name == "Živě")
                {
                    pageUrl = "http://www.ceskatelevize.cz/ivysilani/ajax/live-box";
                }
                String baseWebData = CeskaTelevizeUtil.GetWebData(pageUrl, null, null, null, true);

                if (this.currentCategory.Name == "Živě")
                {
                    while (true)
                    {
                        int startIndex = baseWebData.IndexOf(CeskaTelevizeUtil.showEpisodeLiveStart);
                        if (startIndex >= 0)
                        {
                            int endIndex = baseWebData.IndexOf(CeskaTelevizeUtil.showEpisodeLiveEnd, startIndex);
                            if (endIndex >= 0)
                            {
                                String episodeData = baseWebData.Substring(startIndex, endIndex - startIndex);
                                baseWebData = baseWebData.Substring(endIndex);

                                String showUrl      = String.Empty;
                                String showTitle    = String.Empty;
                                String showThumbUrl = String.Empty;

                                Match match = Regex.Match(episodeData, CeskaTelevizeUtil.showEpisodeLiveUrlAndTitleRegex);
                                if (match.Success)
                                {
                                    showUrl   = Utils.FormatAbsoluteUrl(match.Groups["showUrl"].Value, CeskaTelevizeUtil.baseUrl);
                                    showTitle = match.Groups["showTitle"].Value.Trim();
                                }

                                match = Regex.Match(episodeData, CeskaTelevizeUtil.showEpisodeLiveThumbUrlRegex);
                                if (match.Success)
                                {
                                    showThumbUrl = match.Groups["showThumbUrl"].Value;
                                }

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

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

                                pageVideos.Add(videoInfo);
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    int startIndex = baseWebData.IndexOf(CeskaTelevizeUtil.showEpisodesStart);
                    if (startIndex >= 0)
                    {
                        int endIndex = baseWebData.IndexOf(CeskaTelevizeUtil.showEpisodesEnd, startIndex);
                        if (endIndex >= 0)
                        {
                            baseWebData = baseWebData.Substring(startIndex, endIndex - startIndex);

                            while (true)
                            {
                                startIndex = baseWebData.IndexOf(CeskaTelevizeUtil.showEpisodeStart);
                                if (startIndex >= 0)
                                {
                                    endIndex = baseWebData.IndexOf(CeskaTelevizeUtil.showEpisodeEnd, startIndex);
                                    if (endIndex >= 0)
                                    {
                                        String episodeData = baseWebData.Substring(startIndex, endIndex - startIndex);
                                        baseWebData = baseWebData.Substring(endIndex + CeskaTelevizeUtil.showEpisodeEnd.Length);

                                        String showTitle       = String.Empty;
                                        String showThumbUrl    = String.Empty;
                                        String showUrl         = String.Empty;
                                        String showDescription = String.Empty;

                                        Match match = Regex.Match(episodeData, CeskaTelevizeUtil.showEpisodeUrlAndTitleRegex);
                                        if (match.Success)
                                        {
                                            showUrl   = Utils.FormatAbsoluteUrl(match.Groups["showUrl"].Value, CeskaTelevizeUtil.baseUrl);
                                            showTitle = match.Groups["showTitle"].Value.Trim();
                                        }

                                        match = Regex.Match(episodeData, CeskaTelevizeUtil.showEpisodeThumbUrlRegex);
                                        if (match.Success)
                                        {
                                            showThumbUrl = match.Groups["showThumbUrl"].Value;
                                        }

                                        startIndex = episodeData.IndexOf(CeskaTelevizeUtil.showEpisodeDescriptionStart);
                                        if (startIndex >= 0)
                                        {
                                            endIndex = episodeData.IndexOf(CeskaTelevizeUtil.showEpisodeDescriptionEnd, startIndex);
                                            if (endIndex >= 0)
                                            {
                                                showDescription = episodeData.Substring(startIndex + CeskaTelevizeUtil.showEpisodeDescriptionStart.Length, endIndex - startIndex - CeskaTelevizeUtil.showEpisodeDescriptionStart.Length).Trim().Replace('\t', ' ').Replace("</p>", "\n").Trim();
                                            }
                                        }

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

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

                                        pageVideos.Add(videoInfo);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }

                            Match nextPageMatch = Regex.Match(baseWebData, CeskaTelevizeUtil.nextPageRegex);
                            this.nextPageUrl = (nextPageMatch.Success) ? String.Format("{0}{1}", CeskaTelevizeUtil.baseUrl, nextPageMatch.Groups["nextPage"].Value) : String.Empty;
                        }
                    }
                }
            }

            return(pageVideos);
        }