glubs/webvtt

Types

Item represents an individual item in a WebVTT file, which can be either a Note or a Cue.

pub type Item {
  Note(String)
  Style(String)
  Cue(
    id: Option(String),
    start_time: Int,
    end_time: Int,
    payload: String,
    settings: List(#(String, String)),
  )
}

Constructors

  • Note(String)
  • Style(String)
  • Cue(
      id: Option(String),
      start_time: Int,
      end_time: Int,
      payload: String,
      settings: List(#(String, String)),
    )

Token represents individual tokens that can be generated during the tokenization of WebVTT cue payload.

pub type Token {
  StartTag(
    tag: String,
    classes: List(String),
    annotation: Option(String),
  )
  Text(content: String)
  Timestamp(ms: Int)
  EndTag(tag: String)
}

Constructors

  • StartTag(
      tag: String,
      classes: List(String),
      annotation: Option(String),
    )
  • Text(content: String)
  • Timestamp(ms: Int)
  • EndTag(tag: String)

TokenizationError represents errors that may occur during the tokenization process.

pub type TokenizationError {
  InvalidStartToken
  InvalidEndToken
}

Constructors

  • InvalidStartToken
  • InvalidEndToken

Represents a WebVTT file with an optional comment and a list of items.

pub type WebVTT {
  WebVTT(
    metadata: List(#(String, String)),
    comment: Option(String),
    items: List(Item),
  )
}

Constructors

  • WebVTT(
      metadata: List(#(String, String)),
      comment: Option(String),
      items: List(Item),
    )

Functions

pub fn parse(webvtt: String) -> Result(WebVTT, String)

Parses a WebVTT string and returns a Result containing the parsed WebVTT structure or a parsing error.

pub fn to_string(webvtt: WebVTT) -> String

Converts a WebVTT type to a string.

pub fn tokenize(
  payload: String,
) -> Result(List(Token), TokenizationError)

Tokenizes the given cue payload and returns a Result containing the list of generated tokens or a tokenization error.

Search Document