Last active
December 26, 2015 21:39
-
-
Save gabrielmoreira/7217529 to your computer and use it in GitHub Desktop.
Criar legenda .srt para os vídeos do TED
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
$.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"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Criar o seguinte atalho no navegador:
Nome:
URL: