Srt.js

A JavaScript parser for SubRip(.srt) files

Drop srt file(s)

Srt.js is a simple JavaScript parser for SubRip(.srt) files. You can easily parse a .srt subtitle file in the client side or in the server side using Node.js

$ git clone https://github.com/fuermosi777/srtjs.git srtjs

Or you can just


Download from Github

Start

Start based on CommonJS. You can use it in Node.js, Browserify or Webpack.

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

You can get the content of a srt file using FileReader API

Lines

Srt object provides access to the 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 .srt text

You can call getSrtContent() method to get the content as plain text.

console.log(srt.getSrtContent());

You can create a download link using Data URI.

Srt.js is available under the MIT License.

Fork me on GitHub