要从 youtube 下载视频,您必须找到实际的视频位置。不是您用来观看视频的页面。http://www.youtube.com/watch?v=...
url,是一个 html 页面(很像这个),它将从它的源位置加载视频并显示它。通常,您必须解析 html 并从 html 中提取视频位置。
在您的情况下,您已经找到了执行此操作的代码 - 幸运的是,因为从 youtube 下载视频一点也不简单。查看您在问题中提供的链接,疯狂背后的魔力可在YoutubeService.cs / GetDownloadUrl()
:
http://youtubefisher.codeplex.com/SourceControl/changeset/view/68461#1113202
该方法正在解析 youtube 观看 url 返回的 html 页面,并找到实际的视频内容。增加的复杂性是 youtube 视频也可以是各种不同的格式。
如果下载后需要转换视频类型,我推荐FFMPEG
EDIT: In response to your comment - You didnt look at the source code of YoutubeFisher at all, did you.. I'd recommend analysing the file I mentioned (YoutubeService.cs
). Although after taking a quick look myself, you'll have to parse the yt.playerConfig
variable within the html page.
Use that source to help you.
EDIT: In response to your second comment: "Actually I am trying to develop an application that can download video from any video site." You say that like its easy - fyi, its not. Since every video website is different, you cant just write something that will work for everything out of the box. If I had to do it though, heres how i would: I would write custom parsers for the major video sharing websites (Metacafe, Youtube, Whatever else) so that those ones are guarenteed to work. After that, I would write a "fallover" if you will. Basically, if you're requesting a video from an unknown website, it would scour the html looking for known video extentions (flv, wmv, mp4, etc) and then extract the url from that.
You could use a regex for extracting the url in the latter case, or a combination of something like indexof, substring, and lastindexof.