Javascript - How to get the url for Youtube videos programmatically? (self-answer) -
an extremely common question "how url youtube video?". answers involve scraping , regexing html of video page or resort 'use 3rd party tool or website'.
its extremely easy dev tools console in browser on youtube video page.
see answer below.
example here:
https://gist.github.com/geuis/8b1b2ea57d7f9a9ae22f80d4fbf5b97f
// run dev tools console of youtube video // accurate of june 12, 2016 var videourls = {}; ytplayer.config.args.url_encoded_fmt_stream_map.split(',').foreach(function (item) { var obj = {}; item.split('&').foreach(function (param) { param = param.split('='); obj[param[0]] = decodeuricomponent(param[1]); }); videourls[obj.quality] = obj; }); console.log(videourls);
sample output https://www.youtube.com/watch?v=9bzkp7q19f0
{ "hd720": { "url": "https://r3---sn-n4v7sn76.googlevideo.com/videoplayback?ms=au&mv=m&mt=146577…za3kgkxmjcumc4wlje&ip=108.233.85.171&key=yt6&requiressl=yes&itag=22&cnr=14", "quality": "hd720", "s": "1bef82c7d9487809555e4b5124ca244fd93857c62.7869eb3fe7e8be955b85e19f769dd80c49f3a87cb", "itag": "22", "type": "video/mp4;+codecs=\"avc1.64001f,+mp4a.40.2\"" }, "medium": { "url": "https://r3---sn-n4v7sn76.googlevideo.com/videoplayback?ms=au&mv=m&mt=146577…axlnnqyza3kgkxmjcumc4wlje&ip=108.233.85.171&key=yt6&requiressl=yes&itag=18", "quality": "medium", "s": "35addcf2f151540b9ae72455ed9cd079b3a166669.f168091b130653fcaca72506c01625b74e46c1a7d", "itag": "18", "type": "video/mp4;+codecs=\"avc1.42001e,+mp4a.40.2\"" }, "small": { "url": "https://r3---sn-n4v7sn76.googlevideo.com/videoplayback?ms=au&mv=m&mt=146577…axlnnqyza3kgkxmjcumc4wlje&ip=108.233.85.171&key=yt6&requiressl=yes&itag=17", "quality": "small", "s": "0c397549d581241f0f39d3eb8bf6e9b9067f65afd.76b46a360178c4b001e96166c46aeae5cf0d6a35f", "itag": "17", "type": "video/3gpp;+codecs=\"mp4v.20.3,+mp4a.40.2\"" } }
Comments
Post a Comment