Last active
March 2, 2016 23:55
-
-
Save kizdolf/920c254d1f2a9c7be9a5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'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'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
translate a ass subtitles to vtt subs. nice for html5.