Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amitkhare/892ba2bbc7ce7d88d507cec8c4d7d82a to your computer and use it in GitHub Desktop.
Save amitkhare/892ba2bbc7ce7d88d507cec8c4d7d82a to your computer and use it in GitHub Desktop.
Get Youtube video urls
// Run from the dev tools console of any Youtube video
// Accurate as of June 23, 2017.
// ES6 version
const videoUrls = ytplayer.config.args.adaptive_fmts
.split(',')
.map(item => item
.split('&')
.reduce((prev, curr) => (curr = curr.split('='),
Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])})
), {})
)
.reduce((prev, curr) => Object.assign(prev, {
[curr.quality_label || curr.type]: curr
}), {});
console.log(videoUrls);
// ES5 version
var videoUrls = ytplayer.config.args.adaptive_fmts
.split(',')
.map(function (item) {
return item
.split('&')
.reduce(function (prev, curr) {
curr = curr.split('=');
return Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])})
}, {});
})
.reduce(function (prev, curr) {
return Object.assign(prev, {
[curr.quality_label || curr.type]: curr
});
}, {});
console.log(videoUrls);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment