JavaScript Ninja - So You Want To Get A YouTube Video Streams Resource Without Ajax'ing Around? DAAAA!!!

Posted at

Hello Readers! some time ago I've made a nice little Git repository named YouTube Downloader having most of raw resources I've gathered around which may be useful if you are intereseted in in-depth-understanding of the the YouTube JavaScript Player API Reference

(which is a nice mental leap towards making an hybrid (Android) APP or using the more challenging YouTube Android Player API or just making a bookmarklet or even yet another youtube downloader website/extension [please don't!] ;) )

anyway.. is what you are really in for:

sources = (function(sources, tmp){
  return sources.split(',').map(function(source){
    tmp = {};
      part = part.split('=');
      tmp[ part[0] ] = decodeURIComponent( part[1] );
    return tmp;
, []

and now for a pro tip, a zero-effort JSON beautifier formatting trick:

, null, 2));

hey! it's probably even works with most of embedded youtube plugin, since it uses almost no dependencies by the very raw YouTube-Player "API/SDK" (which YouTube itself uses...)

..give it a try on this lovely video:


edit: Tip: ǡre yoǘ ȃ coʍʍʌ-ϝiɍst Nåƶɨ? (*cough* *cough* me?)
this will ease your O.C.D.:
sources = JSON.stringify(sources, null, 2).replace(/,\
 /g, "\


sources = JSON.stringify(sources, null, 2).replace(/,\
 /g, "\
 ,").replace(/ *(,(\\ +))/g,"$2,")

who does not love a little bit of JavaScript RegEx backtrace replacing :)


Oh yeah! comma-first bliss ;)