Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // Run from the dev tools console of any Youtube video
  2. // Accurate as of October 28, 2016. Uses quality + video type for naming now,
  3. // prevents video urls being overwritten.
  4.  
  5. // ES6 version
  6. const videoUrls = ytplayer.config.args.url_encoded_fmt_stream_map
  7. .split(',')
  8. .map(item => item
  9. .split('&')
  10. .reduce((prev, curr) => (curr = curr.split('='),
  11. Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])})
  12. ), {})
  13. )
  14. .reduce((prev, curr) => Object.assign(prev, {
  15. [curr.quality + ':' + curr.type.split(';')[0]]: curr
  16. }), {});
  17.  
  18. console.log(videoUrls);
  19.  
  20. // ES5 version
  21. var videoUrls = ytplayer.config.args.url_encoded_fmt_stream_map
  22. .split(',')
  23. .map(function (item) {
  24. return item
  25. .split('&')
  26. .reduce(function (prev, curr) {
  27. curr = curr.split('=');
  28. return Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])})
  29. }, {});
  30. })
  31. .reduce(function (prev, curr) {
  32. return Object.assign(prev, {
  33. [curr.quality + ':' + curr.type.split(';')[0]]: curr
  34. });
  35. }, {});
  36.  
  37. console.log(videoUrls);
  38.  
  39. // Prior June 2016 buggy version
  40. // var videoUrls = {};
  41. // ytplayer.config.args.url_encoded_fmt_stream_map.split(',').forEach(function (item) {
  42. // var obj = {};
  43. //
  44. // item.split('&').forEach(function (param) {
  45. // param = param.split('=');
  46. // obj[param[0]] = decodeURIComponent(param[1]);
  47. // });
  48. //
  49. // videoUrls[obj.quality] = obj;
  50. // });
  51. //
  52. // console.log(videoUrls);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement