1- # WebVTT compiler parser and segmenter
1+ # Subrip (.srt) compiler parser and segmenter
22
3- Compiles, parses WebVTT files, segments and generates HLS playlists for them.
3+ Compiles, parses Subrip files, segments and generates HLS playlists for them.
44
5- [ ![ CircleCI] ( https://circleci.com/gh/osk/node-webvtt.svg?style=svg )] ( https://circleci.com/gh/osk/node-webvtt )
5+ [ ![ CircleCI] ( https://circleci.com/gh/goatandsheep/node-srt.svg?style=svg )] ( https://circleci.com/gh/goatandsheep/node-srt )
6+
7+ This is a sister package to [ osk/node-webvtt] ( https://github.com/osk/node-webvtt ) .
68
79## Usage
810
9- For a WebVTT file:
11+ For a Subrip file:
1012
1113``` text
12- WEBVTT
13-
141400:00:00.000 --> 00:00:01.000
1515Hello world!
1616
2424Bar
2525```
2626
27- We can parse, segment and create HLS playlists, and compile back to WebVTT format:
27+ We can parse, segment and create HLS playlists, and compile back to Subrip format:
2828
2929``` javascript
30- const webvtt = require (' node-webvtt ' );
30+ const subrip = require (' node-srt ' );
3131
3232const segmentDuration = 10 ; // default to 10
3333const startOffset = 0 ; // Starting MPEG TS offset to be used in timestamp map, default 900000
3434
35- const parsed = webvtt .parse (input);
36- const compile = webvtt .compile (input);
37- const segmented = webvtt .parse (input, segmentDuration);
38- const playlist = webvtt .hls .hlsSegmentPlaylist (input, segmentDuration);
39- const segments = webvtt .hls .hlsSegment (input, segmentDuration, startOffset);
35+ const parsed = subrip .parse (input);
36+ const compile = subrip .compile (input);
37+ const segmented = subrip .parse (input, segmentDuration);
38+ const playlist = subrip .hls .hlsSegmentPlaylist (input, segmentDuration);
39+ const segments = subrip .hls .hlsSegment (input, segmentDuration, startOffset);
4040```
4141
4242### Parsing
4343
44- Parses the WebVTT file and returns an object with ` valid === true ` if parsed correctly and an array of cues parsed.
44+ Parses the Subrip file and returns an object with ` valid === true ` if parsed correctly and an array of cues parsed.
4545
4646Each cue can have:
4747
@@ -51,7 +51,7 @@ Each cue can have:
5151* ` text ` - Text of the subtitle
5252* ` styles ` - If any of the cue
5353
54- If the WebVTT file is invalid, the parser will throw a ` ParserError ` exception. So for safety, calls to ` parse ` should be in ` try catch ` .
54+ If the Subrip file is invalid, the parser will throw a ` ParserError ` exception. So for safety, calls to ` parse ` should be in ` try catch ` .
5555
5656For the above example we'd get:
5757
@@ -124,21 +124,17 @@ result = {
124124
125125### Metadata
126126
127- Some WebVTT strings may also contain lines of metadata after the initial ` WEBVTT ` line, for example:
127+ Some Subrip strings may also contain lines of metadata after the initial ` WEBVTT ` line, for example:
128128
129129``` text
130- WEBVTT
131- Kind: captions
132- Language: en
133-
13413000:00:00.000 --> 00:00:01.000
135131Hello world!
136132```
137133
138134By passing ` { meta: true } ` to the ` parse ` method, these metadata will be returned as an object called ` meta ` . For example, parsing the above example:
139135
140136``` javascript
141- parse (webvtt , { meta: true });
137+ parse (subrip , { meta: true });
142138```
143139
144140would return the following:
@@ -166,7 +162,7 @@ If no metadata is available, `meta` will be set to `null` in the result if the o
166162
167163### Compiling
168164
169- Compiles JSON from the above format back into a WebVTT string. If a ` meta ` key is in the input,
165+ Compiles JSON from the above format back into a Subrip string. If a ` meta ` key is in the input,
170166it will be compiled as well. The ` meta ` value must be an object and each key and value must be a string.
171167
172168If the object is missing any attributes, the compiler will throw a ` CompilerError ` exception. So
@@ -191,10 +187,6 @@ const input = {
191187const result = compile (input);
192188
193189/*
194- WEBVTT
195- Kind: captions
196- Language: en
197-
1981901
19919100:02:15.001 --> 00:02:20.000
200192Hello world
@@ -267,16 +259,16 @@ Creates a list of HLS segments for the subtitles, returning an array of them wit
267259
268260## CLI
269261
270- For segmenting a WebVTT file quickly, you can use the included CLI tool:
262+ For segmenting a Subrip file quickly, you can use the included CLI tool:
271263
272264``` bash
273- ./webvtt -segment.js -v --target-duration 10 -o ./subs subs.vtt
265+ ./subrip -segment.js -v --target-duration 10 -o ./subs subs.vtt
274266```
275267
276268``` bash
277- $ ./webvtt -segment.js --help
269+ $ ./subrip -segment.js --help
278270
279- Usage: webvtt -segment [options] < webvtt file>
271+ Usage: subrip -segment [options] < subrip file>
280272
281273 Options:
282274
0 commit comments