public static List <YouTubeVideoQuality> GetYouTubeVideoUrls(string VideoUrl) { var list = new List <YouTubeVideoQuality>(); var id = YouTubeDownloader.GetVideoIDFromUrl(VideoUrl); var infoUrl = string.Format("http://www.youtube.com/get_video_info?&video_id={0}&el=detailpage&ps=default&eurl=&gl=US&hl=en", id); var infoText = new WebClient().DownloadString(infoUrl); var infoValues = HttpUtility.ParseQueryString(infoText); var title = infoValues["title"]; var videoDuration = infoValues["length_seconds"]; var videos = infoValues["url_encoded_fmt_stream_map"].Split(','); foreach (var item in videos) { try { var data = HttpUtility.ParseQueryString(item); var server = Uri.UnescapeDataString(data["fallback_host"]); var signature = data["sig"] ?? data["signature"]; var url = Uri.UnescapeDataString(data["url"]) + "&fallback_host=" + server; if (!string.IsNullOrEmpty(signature)) { url += "&signature=" + signature; } var size = getSize(url); var videoItem = new YouTubeVideoQuality(); videoItem.DownloadUrl = url; videoItem.VideoSize = size; videoItem.VideoTitle = title; var tagInfo = new ITagInfo(Uri.UnescapeDataString(data["itag"])); videoItem.Dimension = tagInfo.VideoDimensions; videoItem.Extention = tagInfo.VideoExtentions; videoItem.Length = long.Parse(videoDuration); list.Add(videoItem); } catch { } } return(list); }
// void bStart_Click(object o, EventArgs e) { wc = new WebClient(); lab.Visible = true; wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged); wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted); tSource.ReadOnly = true; bPaste.Enabled = false; bBrowse.Enabled = false; try { if (yt) //youtube { YouTubeVideoQuality it = calit.SelectedItem as YouTubeVideoQuality; n = tTarget.Text + "\\" + it.VideoTitle.Replace("\\", "").Replace("/", "").Replace(":", "").Replace("*", "").Replace("?", "").Replace("\"", "").Replace("<", "").Replace(">", "").Replace("|", "") + "." + it.Extention; wc.DownloadFileAsync(new Uri(it.DownloadUrl), n); } else //normal { n = tTarget.Text + "\\" + Path.GetFileName(tSource.Text).Replace("\\", "").Replace("/", "").Replace(":", "").Replace("*", "").Replace("?", "").Replace("\"", "").Replace("<", "").Replace(">", "").Replace("|", ""); wc.DownloadFileAsync(new Uri(tSource.Text), n); } // bStart.Enabled = false; bCancel.Enabled = true; } catch (Exception ex) { MessageBox.Show(this, ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); wc.Dispose(); } //memoria Process.GetCurrentProcess().MaxWorkingSet = Process.GetCurrentProcess().MaxWorkingSet; tim.Start(); }