Created
November 18, 2012 04:15
-
-
Save that4chanwolf/4103499 to your computer and use it in GitHub Desktop.
ASS parser script
This file contains 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
#!/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