Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created October 21, 2013 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakenickels/7092835 to your computer and use it in GitHub Desktop.
Save fakenickels/7092835 to your computer and use it in GitHub Desktop.
Just put this script to execute on a YouTube video page, and download it!
!function( ytplayer ){
var url = ytplayer.config.args["url_encoded_fmt_stream_map"],
videoFormats = url.split(','),
videos = [],
props = ['quality', 'type'];
setFormats();
askToUser();
function setFormats(){
for( var i in videoFormats ){
videoFormats[i] = unescape( videoFormats[i] );
var video = { number: i };
for( var p in props ){
video[ props[p] ] = setProp( videoFormats[i], props[p] );
}
video.downloadURL = videoFormats[i].split('&url=')[1].replace(/;.+\&/g, '&');
if( !(/sig=/g).test(videoFormats[i]) )
video.downloadURL = video.downloadURL.replace('sig=', 'signature=');
else
video.downloadURL += videoFormats[i].match(/sig=[^&]+/g)[0].replace('sig=', '&signature=');
videos.push( video );
}
}
function setProp( videoFormat, prop ){
// Unfortunely...
var regexp = new RegExp(prop +'=[^&]+', 'gi'),
val = videoFormat.match(regexp)[0].replace('&'+ prop +'=', '');
return val;
}
function askToUser(){
var pVal = 'Digite o número do formato que você quer', userChoosen;
for( var i in videos ){
pVal += '\n'+ 'N#'+ i +'. Tipo ' + videos[i].type + ' \n\t Qualidade ' + videos[i].quality;
}
userChoosen = prompt(pVal, '1');
window.open( videos[userChoosen].downloadURL );
}
}( ytplayer )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment