Last active
April 2, 2018 06:22
-
-
Save nicholastay/b355cc66c8920a45ff48080bd6b3f41f to your computer and use it in GitHub Desktop.
Quick js script to convert vtt format data to srt
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
function vtt2srt(raw) { | |
if (raw.substr(0,6) !== 'WEBVTT') | |
throw new TypeError('data does not look like webvtt'); | |
var vtt = raw.replace('\r', '').trim(); | |
var data = '1\n' + vtt.substr(vtt.indexOf('\n\n')+2); // get past the blank line and get the 1 started | |
var i = 1; // iterate the sub numbers | |
return data.replace(/\n\n/g, str => '\n\n' + (++i) + '\n'); // add the numbers at new lines | |
} | |
module.exports = vtt2srt; | |
// fs.writeFileSync('./out.en.srt', vtt2srt(fs.readFileSync('./lw.en.vtt', 'utf8'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment