How to get direct url for youtube videos

后端 未结 3 667
我在风中等你
我在风中等你 2020-11-30 22:35

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 javas

3条回答
  •  借酒劲吻你
    2020-11-30 23:12

    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")
    }
    

提交回复
热议问题