Skip to content

Instantly share code, notes, and snippets.

@that4chanwolf
Created November 18, 2012 04:15
Show Gist options
  • Save that4chanwolf/4103499 to your computer and use it in GitHub Desktop.
Save that4chanwolf/4103499 to your computer and use it in GitHub Desktop.
ASS parser script
#!/usr/bin/env node
/*
* Simple script for turning ASS files into regular scripts
* NOTE: Not 100% tested, will probably fail.
* Please fix me ;_;
*/
var ap = require('argparser').
files("in", "out").
parse(),
fs = require('fs');
var dialog = /^Dialogue: [0-9],[0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9],[0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9],(.+),,[0-9],[0-9],[0-9],,/,
effect = /\{.*?\}/gi;
var final = '';
(function() {
console.log(ap.opt("in"), ap.opt("out"));
if( ap.opt("in") === false || ap.opt("out") === false) {
return console.error(new Error("both --in and --out must be specified, and they need to be already made files"));
}
fs.readFile(ap.opt("in"), 'utf8', function(err, data) {
if(err) throw err;
data = data.split("\n");
data.forEach(function(line) {
if(dialog.test(line)) {
line = line.replace(dialog, '');
line = line.replace(effect, '');
final += line + '\n';
}
});
fs.writeFile(ap.opt('out'), final, function(err, saved) {
if(err) throw err;
console.log("`%s` saved!", ap.opt('out'));
});
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment