Exemplo n.º 1
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            YutubFileFormat fmt = (YutubFileFormat)cbFormat.SelectedItem;

            dm.DownloadFileName = string.Format("{0}.{1}", yutub.VideoTitle, fmt.VideoExt);
            dm.DownloadPath     = txtDownloadPath.Text;
            dm.DownloadURL      = fmt.DownloadURL;
            dm.onDownloading   += new dlgDownlading(dm_onDownloading);
            dm.Start();
        }
Exemplo n.º 2
0
        void GetVideoInfo()
        {
            if (string.IsNullOrEmpty(_videoURL))
            {
                return;
            }
            string         videoId = HttpUtility.ParseQueryString(this._videoURL)[0];
            HttpWebRequest req     = (HttpWebRequest)WebRequest.Create(string.Format("http://www.youtube.com/get_video_info?&video_id={0}{1}&ps=default&eurl=&gl=US&hl=en", videoId, "&el=vevo"));

            req.Method = "GET";
            HttpWebResponse res       = (HttpWebResponse)req.GetResponse();
            string          videoinfo = "";

            using (StreamReader sr = new StreamReader(res.GetResponseStream()))
            {
                videoinfo = sr.ReadToEnd();
                sr.Close();
            }
            res.Close();
            NameValueCollection list = HttpUtility.ParseQueryString(videoinfo);

            this._videoTitle = list["title"];
            this.ThumbUrl    = list["thumbnail_url"];
            int seconds = int.Parse(list["length_seconds"]);

            this._length = string.Format("{0}:{1}", (int)(seconds / 60), seconds % 60);
            string[] fmt_map = list["url_encoded_fmt_stream_map"].Split(',');
            list.Clear();
            foreach (string item in fmt_map)
            {
                list = HttpUtility.ParseQueryString(item);
                YutubFileFormat fmt = new YutubFileFormat();
                fmt.VideoCode   = int.Parse(list["itag"]);
                fmt.DownloadURL = string.Format("{0}&signature={1}", list["url"], list["sig"]);
                fmt.VideoQu     = list["quality"];
                FormatList.Add(fmt);
            }
        }
Exemplo n.º 3
0
 void GetVideoInfo()
 {
     if (string.IsNullOrEmpty(_videoURL)) return;
     string videoId = HttpUtility.ParseQueryString(this._videoURL)[0];
     HttpWebRequest req = (HttpWebRequest)WebRequest.Create(string.Format("http://www.youtube.com/get_video_info?&video_id={0}{1}&ps=default&eurl=&gl=US&hl=en", videoId, "&el=vevo"));
     req.Method = "GET";
     HttpWebResponse res = (HttpWebResponse)req.GetResponse();
     string videoinfo = "";
     using (StreamReader sr = new StreamReader(res.GetResponseStream()))
     {
         videoinfo = sr.ReadToEnd();
         sr.Close();
     }
     res.Close();
     NameValueCollection list = HttpUtility.ParseQueryString(videoinfo);
     this._videoTitle = list["title"];
     this.ThumbUrl = list["thumbnail_url"];
     int seconds = int.Parse(list["length_seconds"]);
     this._length = string.Format("{0}:{1}", (int)(seconds / 60), seconds % 60);
     string[] fmt_map = list["url_encoded_fmt_stream_map"].Split(',');
     list.Clear();
     foreach (string item in fmt_map)
     {
         list = HttpUtility.ParseQueryString(item);
         YutubFileFormat fmt = new YutubFileFormat();
         fmt.VideoCode = int.Parse(list["itag"]);
         fmt.DownloadURL = string.Format("{0}&signature={1}", list["url"], list["sig"]);
         fmt.VideoQu = list["quality"];
         FormatList.Add(fmt);
     }
 }