Skip to content

Instantly share code, notes, and snippets.

@netj
Created July 25, 2013 17:43
Show Gist options
  • Save netj/6082062 to your computer and use it in GitHub Desktop.
Save netj/6082062 to your computer and use it in GitHub Desktop.
Download YouTube Subtitle — Run this bookmarklet on a YouTube video page to download its subtitle.
/* Created with YouScript Bookmarklet Editor
* http://netj.github.com/youscript/
*/
var m = location.href.match(/youtube.com\/watch\?(.+[&])?v=([^&]+)/);
if (m != null) {
var videoId = m[2];
function askLanguageAndDownload() {
var lang = "en";
// figure out the first available language for subtitle
var langSelector = document.getElementById("watch-transcript-track-selector");
if (langSelector != null)
lang = langSelector.value.substring(0,2);
lang = prompt("Download subtitle for which language?", lang);
if (lang)
open("http://video.google.com/timedtext?lang="+lang+"&v="+videoId);
}
if (document.getElementById("watch-transcript-track-selector") != null)
askLanguageAndDownload();
else { // we need to click the Transcript button to get the language selector
var btn = null;
{
var btns = document.getElementsByClassName("action-panel-trigger");
for (var i=0; i<btns.length; i++)
if (btns[i].title == "Transcript") {
btn = btns[i];
btns[i].click();
}
}
if (btn != null)
setTimeout(askLanguageAndDownload, 2000);
else
askLanguageAndDownload();
}
} else {
alert("Cannot recognize which YouTube video you are watching.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment