Documentation
¶
Overview ¶
Package subtitle reads SubRip (.srt) and WebVTT (.vtt) text, decoded to UTF-8, into cues and the other blocks of the file, with their offsets in that text. Nothing is fetched or run.
Index ¶
Constants ¶
const MaxHeader = blocks.MaxMeta
MaxHeader bounds the text of the WebVTT header: past it the rest is left out, the text kept longer than the bound so that its user, which cuts it there, sees that it was. It is the bound of a metadata value.
const MaxText = 8 << 20
MaxText bounds the text of one cue or block: past it the text is cut, and the item says so (Cut).
const MaxVoices = 4 << 10
MaxVoices bounds the voices of a cue, joined by ", ": once they are longer, the cue's later voices are not collected (its user cuts the joined list at this bound).
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Field ¶
type Field struct{ Key, Value string }
Field is a WebVTT header line of the form "Key: value".
type Header ¶
type Header struct {
// Signature says that the file begins with the WebVTT signature.
Signature bool
// Text is what follows WEBVTT on the first line, trimmed, and the
// header lines that are not "Key: value", one per line; once longer
// than MaxHeader, the later lines are left out.
Text string
// Fields are the header lines "Key: value", in order.
Fields []Field
// Regions are the REGION definitions, as written.
Regions []string
// Controls counts the control characters dropped from the header.
Controls int
}
Header is what a WebVTT file says before its first cue.
type Item ¶
type Item struct {
Kind Kind
// Start and End are the offsets in the text of the first byte of the
// item's first line (a cue's identifier or number line, else its
// timing line) and of the end of its last line with text, its line
// end not included.
Start, End int
// ID is a WebVTT cue's identifier, a SubRip cue's number, as written.
ID string
// Begin and Finish are the cue's timings, HH:MM:SS.mmm when TimingOK,
// else as written.
Begin, Finish string
TimingOK bool
// Settings are WebVTT cue settings, or SubRip coordinates, as written.
Settings string
// Text is the text as a viewer sees it, markup removed, trimmed; empty
// for a cue with no text.
Text string
Spans []gofastcore.Span
// Voices are the names of the WebVTT voices of the cue, in order, each
// once.
Voices []string
// Controls counts the control characters dropped from the text.
Controls int
// Replaced counts the character references to no character (�, a
// surrogate, a number past U+10FFFF) read as U+FFFD, in the text and
// the voices.
Replaced int
// Cut says that the text was longer than MaxText and was cut there.
Cut bool
// Deep says that WebVTT tags nested deeper than the bound given VTT;
// the deeper tags were ignored.
Deep bool
}
Item is one block of the file.
type Kind ¶
type Kind uint8
Kind says what an item is.
const ( // Cue is a cue: its timings, settings, identifier and text. Cue Kind = iota // Note is a WebVTT NOTE block, a comment no player shows. Note // Style is a WebVTT STYLE block: its text is a style sheet. Style // Stray is text that is in no cue: before the first cue of a SubRip // file, or a WebVTT block that is not a cue, NOTE, STYLE or REGION. Stray )