A parser for SRT files.
npm install @badgateway/srt-parser :shrug:
Using the parser is very simple!
Sample code:
import parseSRT from '@badgateway/parse-srt';
const srtString = `1
00:02:16,612 --> 00:02:19,376
Senator, we're making
our final approach into Coruscant.
2
00:02:19,482 --> 00:02:21,609
Very good, Lieutenant.
3
00:03:13,336 --> 00:03:15,167
We made it.
4
00:03:18,608 --> 00:03:20,371
I guess I was wrong.
5
00:03:20,476 --> 00:03:22,671
There was no danger at all.
`
const parsedString = parseSRT(srtString);
console.log(parsedString);
// [
// {
// id: 1,
// start: 2 * 60000 + 16 * 1000 + 612,
// end: 2 * 60000 + 19 * 1000 + 376,
// text: "Senator, we're making\nour final approach into Coruscant.",
// },
// {
// id: 2,
// start: 2 * 60000 + 19 * 1000 + 482,
// end: 2 * 60000 + 21 * 1000 + 609,
// text: 'Very good, Lieutenant.',
// },
// {
// id: 3,
// start: 3 * 60000 + 13 * 1000 + 336,
// end: 3 * 60000 + 15 * 1000 + 167,
// text: 'We made it.',
// },
// {
// id: 4,
// start: 3 * 60000 + 18 * 1000 + 608,
// end: 3 * 60000 + 20 * 1000 + 371,
// text: 'I guess I was wrong.',
// },
// {
// id: 5,
// start: 3 * 60000 + 20 * 1000 + 476,
// end: 3 * 60000 + 22 * 1000 + 671,
// text: 'There was no danger at all.',
// },
// ]type Subtitle = {
id: number;
start: number;
end: number;
text: string;
}
export function parseSubtitleCandidate(subtitleCandidate: string): Subtitle {}