Methods
(static) parseVTT(text) → {object}
Parses a WebVTT file into caption lines.
A WebVTT file is blocks separated by blank lines, and only a cue's text is shown: the lines after its timing line, up to the next blank line. Everything else (the WEBVTT header, NOTE / STYLE / REGION blocks, and a cue identifier, the optional line BEFORE a timing line) is skipped, because none of it follows a timing line within its block.
A cue whose timing cannot be read is dropped whole, and its text with it: attaching that text to the previous cue's timing would show it at the wrong moment.
- start / end in milliseconds; one entry per text line
- skippedCues counts cues dropped for an unreadable timing line, firstSkipped quotes the first of them
| Name | Type | Description |
|---|---|---|
text | string | the file contents |
- Source
{ entries: [{ start, end, text }], skippedCues: integer, firstSkipped: string }
- Type:
- object
(static) vttTimestampPattern() → {object}
The timestamp grammar vttTimestampToMs() accepts: [H:]MM:SS.mmm. The hour field is optional in WebVTT. A comma before the milliseconds is not valid WebVTT, but it has reached the app in production (#584), and rejecting it would drop every cue in such a file rather than show them.
- Source
- Type:
- object
(static) vttTimestampToMs(text, patternopt) → {integer}
Milliseconds for one WebVTT timestamp, or -1 when it is not one.
converting many stamps, so the regex is compiled once per file rather than per stamp
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
text | string | the bare stamp: no | ||
pattern | dynamic | <optional> | invalid | a vttTimestampPattern(); pass one in when |
- Source
milliseconds, or -1
- Type:
- integer
(static) vttTimingField(text) → {string}
The timestamp at the start of one side of a timing line: the end side can carry cue settings after it (00:28.876 align:start position:10%), and a CRLF file leaves a trailing carriage return.
| Name | Type | Description |
|---|---|---|
text | string |
- Source
- Type:
- string