Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /**
  2. * Gets the dialogue out an ASS subtitle file. You can write the output to a
  3. * text file then open it in the browser so it works with Yomichan or whatever.
  4. *
  5. * To add the ability to convert for a certain anime's subtitle files, write the
  6. * appropriate conversion function and add it to the conversionFunctions object.
  7. *
  8. * If there aren't enough command line arguments, the list of available
  9. * conversion functions is printed instead.
  10. *
  11. * Usage:
  12. * node ass-to-dialogue.js <ANIME NAME> <ASS FILE>
  13. *
  14. * Example:
  15. * node ass-to-dialogue.js umaru '[Kamigami] Himouto! Umaru-chan - 01 [1280x720 x264 AAC Sub(Chs,Cht,Jap)](1)(1).ass'
  16. *
  17. **/
  18.  
  19.  
  20. /* CONVERSION FUNCTIONS */
  21. const conversionFunctions = {
  22. umaru: e => e
  23. .find(f => f.section === 'Events')
  24. .body
  25. .filter(g => g.key === 'Dialogue')
  26. .map(h => h.value.Text.replace(/{.*}/, ''))
  27. }
  28.  
  29.  
  30. // IMPORTS
  31. const fs = require('fs');
  32. const assParser = require('ass-parser');
  33.  
  34. // read conversion function name and filename from command line
  35. const conversion = conversionFunctions[process.argv[2]];
  36. const filename = process.argv[3];
  37.  
  38. if (conversion && filename) {
  39. const file = fs.readFileSync(filename, 'utf8');
  40. // parse, run conversion function, print out
  41. conversion(assParser(file))
  42. .forEach(line => console.log(line));
  43. } else {
  44. // print available conversion functions if not enough command line args
  45. Object.keys(conversionFunctions).forEach(f => console.log(f));
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement