Package Exports
- subtitle
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (subtitle) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
subtitle.js
Parse and manipulate SRT (SubRip) format.
Installation
npm install subtitle --save
Usage
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 SRTTests
npm test
Roadmap
- Basic SRT parser
- Basic manipulation
- Stringfy
- Time conversion
- Duration property
- WebVTT support
- Browser support (including for Browserify)
- Better docs