Skip to content

Instantly share code, notes, and snippets.

@gabrielmoreira
Last active December 26, 2015 21:39
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 gabrielmoreira/7217529 to your computer and use it in GitHub Desktop.
Save gabrielmoreira/7217529 to your computer and use it in GitHub Desktop.
Criar legenda .srt para os vídeos do TED
$.getScript("http://momentjs.com/downloads/moment.min.js", function() {
$.getScript("https://raw.github.com/eligrey/FileSaver.js/master/FileSaver.js", function() {
var SUBTITLE_DELAY = parseInt(prompt("Subtitle delay", "10800"), 10);
var zero = moment();
zero.hour(0).minute(0).second(0).milliseconds(0);
var legendas = [];
$('[class="transcriptLink"]').each(function() {
var elapsedMs = parseInt(this.href.split("#")[1], 10);
legendas.push({
inicio: zero.clone().millisecond(elapsedMs + SUBTITLE_DELAY)
, texto: $(this).text()
});
} );
var srt = "";
var formato = 'HH:mm:ss,SSS';
$.each(legendas, function(i, legenda) {
var proximaLegenda = legendas[i+1] || {inicio: legenda.inicio.clone().add('seconds', 5)};
srt += (i + 1) + "\r\n";
srt += legenda.inicio.format(formato) + " --> " + proximaLegenda.inicio.format(formato) + "\r\n";
srt += legenda.texto + "\r\n\r\n";
});
if (console && console.log)
console.log(srt);
if (Blob) {
var file = new Blob([srt], {type: "text/plain;charset=utf-8"});
saveAs(file, $('#altHeadline').text() + ".srt");
}
});
});
@gabrielmoreira
Copy link
Author

Criar o seguinte atalho no navegador:

Nome:

Salvar legendas do TED

URL:

javascript:$.getScript("https://gist.github.com/gabrielmoreira/7217529/raw/gistfile1.js");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment