Parse and manipulate SRT (SubRip) format.
npm install subtitle --save
var Subtitle = require('subtitle');
var captions = new Subtitle();
captions.parse('your srt here');
console.log(captions.getSubtitles());
It's gonna return an array like this:
[
{
index: 1,
start: '00:00:20,000',
end: '00:00:24,400',
text: 'Bla Bla Bla Bla'
},
{
index: 2,
start: '00:00:24,600',
end: '00:00:27,800',
text: 'Bla Bla Bla Bla'
}
]
You can also pass options to the getSubtitles()
method.
captions.getSubtitles({
duration: true, // Include the `duration` property
timeFormat: 'ms' // Set time format to milliseconds
});
Here's the result:
[
{
index: 1,
start: 20000,
end: 24400,
duration: 4400,
text: 'Bla Bla Bla Bla'
},
{
index: 2,
start: 24600,
end: 27800,
duration: 3200,
text: 'Bla Bla Bla Bla'
}
]
You can also add new captions.
var captions = new Subtitle();
captions.add({
start: '00:00:20,000',
end: '00:00:21,900',
text: 'Text here'
});
// You can use time in MS if you prefer
captions.add({
start: 22000,
end: 22580,
text: 'Another text here...'
});
And what about resync your captions?
// Advance 1s
captions.resync(1000);
// Delay 500ms
captions.resync(-500);
Then, you can stringfy your changes:
captions.stringfy(); // Returns a valid SRT
npm test
- Basic SRT parser
- Basic manipulation
- Stringfy
- Time conversion
- Duration property
- WebVTT support
- Browser support (including for Browserify)
- Better docs