本文介绍了asp.net中的youtube下载程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

i想要一个下载youtube的方法(全高清1080p)

i有这个鳕鱼但是质量是720p

hello
i want a method for download of youtube (full hd 1080p)
i have this cod but quality is 720p

try
{
   Uri videoUri = new Uri(txtYouTubeURL.Text);
   string videoID = HttpUtility.ParseQueryString(videoUri.Query).Get("v");
   string videoInfoUrl = "http://www.youtube.com/get_video_info?video_id=" + videoID;

   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(videoInfoUrl);
   HttpWebResponse response = (HttpWebResponse)request.GetResponse();

   Stream responseStream = response.GetResponseStream();
   StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));

   string videoInfo = HttpUtility.HtmlDecode(reader.ReadToEnd());

   NameValueCollection videoParams = HttpUtility.ParseQueryString(videoInfo);

   if (videoParams["reason"] != null)
   {
      lblMessage.Text = videoParams["reason"];
      return;
   }

   string[] videoURLs = videoParams["url_encoded_fmt_stream_map"].Split(',');

   foreach (string vURL in videoURLs)
   {
      string sURL = HttpUtility.HtmlDecode(vURL);

      NameValueCollection urlParams = HttpUtility.ParseQueryString(sURL);
      string videoFormat = HttpUtility.HtmlDecode(urlParams["type"]);

      sURL = HttpUtility.HtmlDecode(urlParams["url"]);
      sURL += "&signature=" + HttpUtility.HtmlDecode(urlParams["sig"]);
      sURL += "&type=" + videoFormat;
      sURL += "&title=" + HttpUtility.HtmlDecode(videoParams["title"]);

      videoFormat = urlParams["quality"] + videoFormat.Split(';')[0].Split('/')[1];

      ddlVideoFormats.Items.Add(new ListItem(videoFormat, sURL));
   }

   btnProcess.Enabled = false;
   ddlVideoFormats.Visible = true;
   btnDownload.Visible = true;
   lblMessage.Text = string.Empty;
   }
   catch (Exception ex)
   {
      lblMessage.Text = ex.Message;
      lblMessage.ForeColor = Color.Red;
      return;
   }
}

推荐答案

这篇关于asp.net中的youtube下载程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 15:31