Skip to content

Instantly share code, notes, and snippets.

@miracle2k
Created July 18, 2014 08:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save miracle2k/0a445bd62cec11409d9c to your computer and use it in GitHub Desktop.
Old code, trying to parse ASS files.
// https://github.com/Arnavion/libjass
// https://github.com/spiegeleixxl/html5-ass-subtitles/blob/master/assparser.js
Subtitles = {};
Subtitles.ASS = function(content) {
var linesOfDialog = [];
function parse(content) {
var lines = content.split('\n');
var inEventsSection = false;
for (var i=0; i<lines.length; i++) {
if (lines[i].startsWith('[Events]'))
inEventsSection = true;
else if (!inEventsSection)
continue;
else {
if (lines[i].startsWith('Dialogue:')) {
var parts = lines[i].split(',');
var st = lineparts[1].trim().split(':');
var et = lineparts[2].trim().split(':');
var startTime = st[0]*60*60 + st[1]*60 + parseFloat(st[2]);
var endTime = et[0]*60*60 + et[1]*60 + parseFloat(et[2]);
linesOfDialog.push({
pre: linesPre + partsPre,
post: partsPost,
startTime: startTime,
endTime: endTime
});
}
}
}
}
this.serialize = function() {
linesOfDialog.forEach(function(line) {
out(line.pre);
out(line.startTime);
out(',');
out(line.endTime);
out(line.post);
});
out(postamble)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment