无法从 youtube 下载
我有一个从 youtube 下载 mp4 文件的脚本。它的作用是生成 http://youtube.com/get_video?video_id= 形式的链接*VIDEO_ID*&t=*THE_TOKEN*=&fmt=18&asv=2,但它不再起作用了(今天注意到它)。你怎么认为?
I have a script that downloads mp4 files from youtube. What it does is to generate link of the form http://youtube.com/get_video?video_id=*VIDEO_ID*&&t=*THE_TOKEN*=&fmt=18&asv=2, but it doesn't work anymore (noticed it today). What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看来他们已经删除了 fmt 选项。请参阅 http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs。
Well it seems like they have removed the fmt option. See http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs.
我创建了一个 node.js 服务器,可以将 YouTube 视频直接流式传输到客户端,并且它可以工作。有关详情,请参阅 https://github.com/licson0729/node-YouTubeStreamer。
I've created a node.js server that can stream YouTube videos directly to the client and it works. See https://github.com/licson0729/node-YouTubeStreamer for details.
不要尝试使用 get_video 来获取视频,而是尝试解析 fmt_url_map (格式 URL 映射)。
您应该能够在找到令牌的同一位置找到 fmt_url_map(例如在 YouTube flash 视频播放器的 flashvars 中或在 YouTube 页面内的某处)。如果找不到,请将请求发送至 http://www.youtube.com/get_video_info ?video_id=VIDEO_ID 并且您应该得到一个非常长的结果,格式为
name=value&name=value&...
查找“fmt_url_map ”在此结果中(在结果中搜索以“&fmt_url_map=”开头并以“&”结尾的字符串)。获得此值后(您可能需要对它进行 url 解码),它将类似于(没有换行符):
其中每个逗号分隔的条目以 fmt 值(示例中的 22 或 35)开头,然后是管道字符,后面跟着 URL,您可以使用该 URL 下载该格式的视频。 (此 URL 是特定于客户端的,因此由于 YouTube 检查 IP,某个客户端的 URL 很可能无法与另一个客户端一起使用。此外,这些 URL 会在一段时间后过期。)
对于不同 fmt 值的列表,请参阅:http://en.wikipedia.org/wiki/YouTube#Quality_and_formats 和显示“YouTube 媒体编码选项的比较”。注意:并非所有格式都适用于所有视频。
已弃用:不再起作用!
Instead of trying to use get_video to get the video, try parsing fmt_url_map (format-url map) instead.
You should be able to find the fmt_url_map in the same place you found the token (like in the flashvars of the YouTube flash video player or inside the YouTube page somewhere). If you can't find it, send a request to http://www.youtube.com/get_video_info?video_id=VIDEO_ID and you should get a really long result that is in the format of
name=value&name=value&...
Find "fmt_url_map" inside this result (search through the result for a string that starts with "&fmt_url_map=" and ends with "&").After you get this value (you may have to url-decode it), it will be something like (without the line breaks):
where each comma-separated entry starts with the fmt value (22 or 35 in the example), followed by a pipe character, which is then followed by the URL where you can use to download the video in that format. (This URL is client-specific, so a URL for a certain client most likely won't work with another client due to YouTube checking IPs. Also, the URLs do expire after a while.)
For a list of the different fmt values, see: http://en.wikipedia.org/wiki/YouTube#Quality_and_formats and show the "Comarison of YouTube media encoding options". NOTE: not all formats may be available for all videos.
Deprecated: won't work anymore!
如果您想下载到服务器,可以使用仍然有效的 youtube-dl。
If you want to download to a server you can use youtube-dl which still works.