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
For browser usage, you can copy the script subtitle.browser.js
from the browser folder.
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 stringify your changes:
captions.stringify(); // Returns a valid SRTTests
Subtitle.js uses AVA for running tests and nyc for code coverage.
If you want to run these tests, you need to install all devDependencies:
npm install
Now you can run the tests with the following command:
npm test
Code Coverage
You can check the code coverage by running the following command:
npm run coverage
If you want a pretty HTML report, run the following:
npm run report
Your report will be available in the coverage folder.
Roadmap
- Basic SRT parser
- Basic manipulation
- Stringify
- Time conversion
- Duration property
- Browser support
- Stream interface
- WebVTT support
- Better docs