Inheritance: SiteUtilBase
        public override string GetVideoUrl(VideoInfo video)
        {
            if (video.PlaybackOptions == null)
            {
                video.PlaybackOptions = new Dictionary <string, string>();
            }
            video.PlaybackOptions.Clear();

            System.Net.CookieContainer container = new System.Net.CookieContainer();
            String baseWebData = GetWebData(video.VideoUrl, cookies: container, forceUTF8: true);

            int start = baseWebData.IndexOf(CeskaTelevizeUtil.showEpisodePostStart);

            if (start >= 0)
            {
                int end = baseWebData.IndexOf(CeskaTelevizeUtil.showEpisodePostEnd, start + CeskaTelevizeUtil.showEpisodePostStart.Length);
                if (end >= 0)
                {
                    String postData = baseWebData.Substring(start + CeskaTelevizeUtil.showEpisodePostStart.Length, end - start - CeskaTelevizeUtil.showEpisodePostStart.Length);
                    Newtonsoft.Json.Linq.JContainer playlistData = (Newtonsoft.Json.Linq.JContainer)Newtonsoft.Json.JsonConvert.DeserializeObject(postData);

                    StringBuilder builder = new StringBuilder();
                    foreach (Newtonsoft.Json.Linq.JProperty child in playlistData.Children())
                    {
                        builder.AppendFormat("&playlist[0][{0}]={1}", child.Name, child.Value.ToString());
                    }
                    builder.AppendFormat("&requestUrl={0}&requestSource=iVysilani&addCommercials=1&type=flash", video.VideoUrl.Remove(0, CeskaTelevizeUtil.baseUrl.Length));

                    String serializedDataForPost = HttpUtility.UrlEncode(builder.ToString()).Replace("%3d", "=").Replace("%26", "&");
                    String playlistSerializedUrl = CeskaTelevizeUtil.GetWebDataFromPost("http://www.ceskatelevize.cz/ivysilani/ajax/get-client-playlist", serializedDataForPost, container, video.VideoUrl);
                    Newtonsoft.Json.Linq.JContainer playlistJson = (Newtonsoft.Json.Linq.JContainer)Newtonsoft.Json.JsonConvert.DeserializeObject(playlistSerializedUrl);

                    String videoDataUrl = String.Empty;
                    foreach (Newtonsoft.Json.Linq.JProperty child in playlistJson.Children())
                    {
                        if (child.Name == "url")
                        {
                            videoDataUrl = child.Value.ToString().Replace("%26", "&");
                        }
                    }

                    String videoConfigurationSerialized = GetWebData(videoDataUrl);
                    Newtonsoft.Json.Linq.JContainer videoConfiguration = (Newtonsoft.Json.Linq.JContainer)Newtonsoft.Json.JsonConvert.DeserializeObject(videoConfigurationSerialized);

                    String qualityUrl  = (String)((Newtonsoft.Json.Linq.JValue)((Newtonsoft.Json.Linq.JProperty)((Newtonsoft.Json.Linq.JArray)videoConfiguration["playlist"])[0]["streamUrls"].First).Value).Value;
                    String qualityData = GetWebData(qualityUrl);

                    String[] lines        = qualityData.Split(new Char[] { '\n' });
                    int      lastBadwidth = -1;

                    for (int i = 0; i < lines.Length; i++)
                    {
                        String line = lines[i];

                        if (line == "#EXTM3U")
                        {
                            continue;
                        }
                        else
                        {
                            int bandwidthIndex = line.IndexOf("BANDWIDTH=");

                            if (bandwidthIndex == (-1))
                            {
                                // url line
                                video.PlaybackOptions.Add(String.Format("Bandwidth (quality) {0}", lastBadwidth), line);
                            }
                            else
                            {
                                lastBadwidth = int.Parse(line.Substring(bandwidthIndex + "BANDWIDTH=".Length));
                            }
                        }
                    }
                }
            }

            if (video.PlaybackOptions.Count > 0)
            {
                var enumer = video.PlaybackOptions.GetEnumerator();
                enumer.MoveNext();
                return(enumer.Current.Value);
            }

            return(String.Empty);
        }
        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);
        }