如何获取YouTube影片的直接网址 [英] How to get direct url for youtube videos

查看:420
本文介绍了如何获取YouTube影片的直接网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有关于制作您自己的YouTube视频下载器的教程都已经过时了。从视频信息中插入的整个令牌不起作用,也不使用JavaScript方法。有没有人知道这样做的方式,而不只是下载别人的程序?我只想知道这个方法,所以我可以自己编程(为了乐趣:D)

All the current tutorials on making your own youtube video downloader are outdated. The whole token insertion from video info does not work, and neither does using the javascript method. Does anyone know of a way to do this currently without just downloading someone else's programs? I just want to know the method to go about so I can program my own (for fun :D)

提前感谢!

推荐答案

截至今天15/06/2012非常简单;但是你必须注意未来的变化。
这是(在Javascript中)

As of today 15/06/2012 is really simple; but you have to be watch for future changes. Here it is (in Javascript)

try{
    var urls = document.body.innerHTML.match(/"url_encoded_fmt_stream_map": "url=([^"]+)/)[1]
    urls = decodeURIComponent(urls).replace(/\\u0026/g,'&')
    urls = urls.replace(/&quality.+?(?=,url)/g,'');;
    urls = urls.split(',url=')
    // urls is an array of all the possible qualities
    // To download one you could use something like:
    // document.location = urls[0]
    // The first one is usually in the highest quality available
} catch(e){
    console.error("Youtube may have changed its API")
}

这篇关于如何获取YouTube影片的直接网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆