Ejemplo n.º 1
0
        private async Task GetVideoUrl(DownloadViewModel model)
        {
            string url = "http://www.flvcd.com/parse.php?format=&kw={0}";

            if (string.IsNullOrEmpty(model.UrlSource))
            {
                return;
            }
            url = string.Format(url, model.UrlSource);
            var response = await HttpWebResponseUtility.CreateGetHttpResponseAsync(url, null, "", null);

            using (Stream stream = response.GetResponseStream()) {
                using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("gb2312"))) {
                    string responseStr = reader.ReadToEnd();
                    Regex  rx          = _RegexDic[VideoSourceType.Youku][4];
                    model.UrlDownloadList = new List <string>();
                    if (rx.IsMatch(responseStr))
                    {
                        MatchCollection mc = rx.Matches(responseStr);
                        foreach (var item in mc)
                        {
                            string downloadurl = item.ToString().Replace(@"href=""", "");
                            model.UrlDownloadList.Add(downloadurl);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private async void BtnGetVideoUrl_Click(object sender, EventArgs e)
        {
            string url = "http://www.flvcd.com/parse.php?format=&kw={0}";

            if (string.IsNullOrEmpty(TxtVideoUrl.Text.Trim()))
            {
                MessageBox.Show("请输入视频地址");
                return;
            }
            url = string.Format(url, TxtVideoUrl.Text.Trim());
            var response = await HttpWebResponseUtility.CreateGetHttpResponseAsync(url, null, "", null);

            using (Stream stream = response.GetResponseStream()) {
                using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("gb2312"))) {
                    string responseStr = reader.ReadToEnd();
                    string subStr      = "下载地址:<a href=\"";
                    int    startIndex  = responseStr.IndexOf(subStr) + 14;
                    int    endIndex    = responseStr.IndexOf("\" target=\"_blank\"", startIndex);
                    //string videoUrl = responseStr.Substring(startIndex, endIndex - startIndex);
                    //TxtResult.Text = videoUrl;

                    //获取视频名称
                    startIndex = responseStr.IndexOf("<title>") + 7;
                    endIndex   = responseStr.IndexOf("FLVCD硕鼠官网|FLV下载", startIndex);
                    string title = responseStr.Substring(startIndex, endIndex - startIndex);
                    txtVideoTitle.Text = title;

                    Regex rx = _RegexDic[VideoSourceType.Youku][1];
                    _ListUrl.Clear();
                    TxtResult.Text = "";
                    if (rx.IsMatch(responseStr))
                    {
                        MatchCollection mc = rx.Matches(responseStr);
                        foreach (var item in mc)
                        {
                            string downloadurl = item.ToString().Replace(@"href=""", "");
                            _ListUrl.Add(downloadurl);
                            TxtResult.Text += downloadurl + ";";
                        }
                    }
                }
            }
        }