Created
October 21, 2013 23:48
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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