【发布时间】:2011-11-30 18:04:02
【问题描述】:
我想从 YouTube 下载视频。我想得到
http://www.youtube.com/watch?v=Fwa_GvIBH38&feature=feedrec_grec_index
到
http://o-o.preferred.btcl-dac1.v6.lscache4.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Csource%2Calgorithm%2Cburst%2Cfactor%2Ccp&fexp=914016%2C904443&algorithm=throttle-factor&itag=34&ip=58.0.0.0&burst=40&sver=3&signature=82D07EBDBED8BC79D08AEE3F90B1473E44D4065E.88AB21BBB9E2D252B65FE6C419CD7867CDE8815C&source=youtube&expire=1322694000&key=yt1&ipbits=8&factor=1.25&cp=U0hRR1ZUUl9FSkNOMV9OTlZBOmRXLUt2VHYwWVY2&id=1706bf1af2011f7f&ptchn=collegehumor&ptk=collegehumor
我从 IDM 获得了上述链接。
我从一个网站获得了两种方法来获取上述链接。
//this methods get's the download link for youtube videos in mp4 format.
public string url(string url)
{
string html = getYoutubeHtml(url);
HtmlAgilityPack.HtmlDocument hDoc = new HtmlDocument();
hDoc.LoadHtml(html);
HtmlNode node = hDoc.GetElementbyId("movie_player");
string flashvars = node.Attributes[5].Value;
string _url = Uri.UnescapeDataString(flashvars);
string[] w = _url.Split('&');
string link = "";
bool foundUrlMap = false;
for (int i = 0; i < w.Length; i++)
{
if (w[i].Contains("fmt_url_map="))
{
foundUrlMap = true;
link += w[i].Split('|')[1];
}
if (foundUrlMap)
{
//add the parameters to the url
link += "&" + w[i];
if (w[i].Contains("id="))
{
link = link.Split(',')[0];
//change the array index for different formats
break;
}
}
}
link = link.Split('|')[1] + "&title=out";
System.Windows.MessageBox.Show(link);
return link;
}
//this method downloads the html code from the youtube page.
private string getYoutubeHtml(string url)
{
string html = "";
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
TextReader reader = new StreamReader(response.GetResponseStream());
string line = "";
while ((line = reader.ReadLine()) != null)
{
html += line;
}
return html;
}
这行不通。
在w的内部找不到fmt_url_map=inside
那么现在我该怎么办?
【问题讨论】:
-
尝试将this question's answer转换为C#
-
我不是 PHP 专家,但我的朋友是。他告诉我这不起作用,因为谷歌继续更改他们的服务器或 IP。谢谢