A JavaScript parser for SubRip(.srt) files
Switch branches/tags
Nothing to show
Clone or download
Latest commit 663a8b2 May 31, 2015
Permalink
Failed to load latest commit information.
dist update readme May 18, 2015
src npm module May 30, 2015
test npm module May 30, 2015
.gitignore ud ignore May 30, 2015
Makefile npm module May 30, 2015
README.md up readme May 30, 2015
gulpfile.js update readme May 18, 2015
index.html update readme May 18, 2015
package.json npm module May 30, 2015

README.md

Srt.js

A small parser for SubRip(.srt) subtitle file in JavaScript

Online demo

Installation

npm install srtjs --save

Usage

Node.js

var Srt = require('srtjs'),
	fs = require('fs');
	
var srtText = fs.readFileSync('./test/test.srt', {
    encoding: 'utf-8'
});
	
var srt = new Srt(srtText);

Browserify

var Srt = require('./src/srt.js');
var srt = new Srt(yourSrtText);

Lines:

// get the number of entries
console.log(srt.lines.length); // 723

// get the 5th line
console.log(srt.lines[4].subtitle); // Come on, let's go!

// get the index of the entry
console.log(srt.lines[4].counter); // 5

// get the start time of the 5th entry
console.log(srt.lines[5].start.text); // 00:01:42,500

// each entry also has a start and end date object
console.log(srt.lines[5].start.time);

// you can get hours, minutes, seconds, and milliseconds as well
console.log(srt.lines[5].start.hours);

Shift:

// move all subs 5 seconds later
srt.shift(5, seconds);

// move all subs 2 seconds earlier
srt.shift(-2, seconds);

Get subtitle text:

console.log(srt.getSrtContent());

Tests

npm test

License

Srt.js is available under the MIT License.