Skip to content

Instantly share code, notes, and snippets.

@kizdolf
Last active March 2, 2016 23:55
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 kizdolf/920c254d1f2a9c7be9a5 to your computer and use it in GitHub Desktop.
Save kizdolf/920c254d1f2a9c7be9a5 to your computer and use it in GitHub Desktop.
'use strict';
var fs = require('fs'),
readline = require('readline');
var ass_to_vtt = (file_in, file_out, cb)=>{
var order = [],
gotOrder = false;
fs.writeFileSync(file_out, 'WEBVTT\n\n');
readline.createInterface({
input: fs.createReadStream(file_in)
}).on('line', (line)=>{
if(/Format: /.test(line)){
order = line.split('Format: ')[1].split(', ');
if(order.indexOf('Text') !== -1)
gotOrder = true;
}else if(gotOrder && /Dialogue: /.test(line)){
var explode = line.split('Dialogue: ')[1].split(',');
if(explode.length == order.length){
var start = '0' + explode[order.indexOf('Start')],
end = '0' + explode[order.indexOf('End')],
txt = explode[order.indexOf('Text')],
vtt = (start + ' --> ' + end + '\n' + txt + '\n\n');
fs.appendFileSync(file_out, vtt);
}
}
}).on('close', ()=>{
cb(true);
});
};
ass_to_vtt('English.ass', 'English.vtt', ()=>{
console.log('done');
});
@kizdolf
Copy link
Author

kizdolf commented Mar 2, 2016

Node js function

translate a ass subtitles to vtt subs. nice for html5.

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