Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Gets the dialogue out an ASS subtitle file. You can write the output to a
- * text file then open it in the browser so it works with Yomichan or whatever.
- *
- * To add the ability to convert for a certain anime's subtitle files, write the
- * appropriate conversion function and add it to the conversionFunctions object.
- *
- * If there aren't enough command line arguments, the list of available
- * conversion functions is printed instead.
- *
- * Usage:
- * node ass-to-dialogue.js <ANIME NAME> <ASS FILE>
- *
- * Example:
- * node ass-to-dialogue.js umaru '[Kamigami] Himouto! Umaru-chan - 01 [1280x720 x264 AAC Sub(Chs,Cht,Jap)](1)(1).ass'
- *
- **/
- /* CONVERSION FUNCTIONS */
- const conversionFunctions = {
- umaru: e => e
- .find(f => f.section === 'Events')
- .body
- .filter(g => g.key === 'Dialogue')
- .map(h => h.value.Text.replace(/{.*}/, ''))
- }
- // IMPORTS
- const fs = require('fs');
- const assParser = require('ass-parser');
- // read conversion function name and filename from command line
- const conversion = conversionFunctions[process.argv[2]];
- const filename = process.argv[3];
- if (conversion && filename) {
- const file = fs.readFileSync(filename, 'utf8');
- // parse, run conversion function, print out
- conversion(assParser(file))
- .forEach(line => console.log(line));
- } else {
- // print available conversion functions if not enough command line args
- Object.keys(conversionFunctions).forEach(f => console.log(f));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement