Skip to content

Instantly share code, notes, and snippets.

@kizdolf
Last active March 2, 2016 23:55
Show Gist options
  • 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 reg = /Dialogue: [0-9],([0-9]:([0-9]{2}):[0-9]{2}.[0-9]{2}),([0-9]:([0-9]{2}):[0-9]{2}.[0-9]{2}).*,,(.*)/g;
fs.writeFileSync(file_out, 'WEBVTT\n\n');
readline.createInterface({
input: fs.createReadStream(file_in)
}).on('line', (line)=>{
var explode = line.split(reg);
if(explode.length == 7){
var start = '0' + explode[1],
end = '0' + explode[3],
txt = explode[5],
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