Skip to content

Instantly share code, notes, and snippets.

@jamesu
Created January 31, 2011 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jamesu/804277 to your computer and use it in GitHub Desktop.
Save jamesu/804277 to your computer and use it in GitHub Desktop.
Fixed that Youtube bookmarklet that puts download links for YT videos
// Convert to bookmarklet, run script. You should get download links for your video!
(function() {
if (document.getElementById('download-youtube-video')) return;
var args = null,
video_title = null,
video_id = null,
video_hash = null;
var download_code = new Array();
var fmt_labels = {
'18': 'standard MP4',
'22': 'HD 720p',
'37': 'HD 1080p'
};
try {
args = yt.getConfig('PLAYER_CONFIG').args;
video_title = escape(document.querySelector('meta[name=title]').content);
} catch(e) {}
if (args) {
var fmt_url_map = args['fmt_url_map'];
if (fmt_url_map == '') return;
video_id = args['video_id'];
video_hash = args['t'];
var fmt = new Array();
var formats = fmt_url_map.split(',');
var format;
for (var i = 0; i < formats.length; i++) {
var format_elems = formats[i].split('|');
fmt[format_elems[0]] = unescape(format_elems[1])
}
for (format in fmt_labels) {
if (fmt[format] != null) {
download_code.push('<a href=\''+(fmt[format]+'&title='+video_title)+'\'>'+fmt_labels[format]+'</a>')
} else if (format == '18') {
download_code.push('<a href=\'http://www.youtube.com/get_video?fmt=18&video_id='+video_id+ '&t='+video_hash+'\'>'+fmt_labels[format]+'</a>')
}
}
}
if (video_id == null || video_hash == null) return;
var div_embed = document.getElementById('watch-info');
if (div_embed) {
var div_download = document.createElement('div');
div_download.innerHTML = '<br /><span id=\'download-youtube-video\'>Download: '+download_code.join(' | ')+'</span>';
div_embed.appendChild(div_download)
}
})();
void(0)
// Bookmarklet below
javascript:(function()%20{if%20(document.getElementById(%27download-youtube-video%27))%20return;var%20args%20=%20null,video_title%20=%20null,video_id%20=%20null,video_hash%20=%20null;var%20download_code%20=%20new%20Array();var%20fmt_labels%20=%20{%2718%27:%20%27standard%20MP4%27,%2722%27:%20%27HD%20720p%27,%2737%27:%20%27HD%201080p%27};try%20{args%20=%20yt.getConfig(%27SWF_CONFIG%27).args;video_title%20=%20escape(document.querySelector(%27meta[name=title]%27).content);}%20catch(e)%20{}if%20(args)%20{var%20fmt_url_map%20=%20args[%27fmt_url_map%27];if%20(fmt_url_map%20==%20%27%27)%20return;video_id%20=%20args[%27video_id%27];video_hash%20=%20args[%27t%27];var%20fmt%20=%20new%20Array();var%20formats%20=%20fmt_url_map.split(%27,%27);var%20format;for%20(var%20i%20=%200;%20i%20<%20formats.length;%20i++)%20{var%20format_elems%20=%20formats[i].split(%27|%27);fmt[format_elems[0]]%20=%20unescape(format_elems[1])}for%20(format%20in%20fmt_labels)%20{if%20(fmt[format]%20!=%20null)%20{download_code.push(%27<a%20href=\%27%27+(fmt[format]+%27&title=%27+video_title)+%27\%27>%27+fmt_labels[format]+%27</a>%27)}%20else%20if%20(format%20==%20%2718%27)%20{download_code.push(%27<a%20href=\%27http://www.youtube.com/get_video?fmt=18&video_id=%27+video_id+%20%27&t=%27+video_hash+%27\%27>%27+fmt_labels[format]+%27</a>%27)}}}if%20(video_id%20==%20null%20||%20video_hash%20==%20null)%20return;var%20div_embed%20=%20document.getElementById(%27watch-info%27);if%20(div_embed)%20{var%20div_download%20=%20document.createElement(%27div%27);div_download.innerHTML%20=%20%27<br%20/><span%20id=\%27download-youtube-video\%27>Download:%20%27+download_code.join(%27%20|%20%27)+%27</span>%27;div_embed.appendChild(div_download)}})();void(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment