Chapters v1.0.1 Chapters.Parsers.Normalplaytime.Parser View Source

Parses Normal Play Time strings.

See https://www.w3.org/TR/media-frags/#npttimedef.

Examples

iex> {:ok, r, "", _, _, _} = parse("1")
iex> r
[{:seconds, 1}]

iex> {:ok, r, "", _, _, _} = parse("1.843")
iex> r
[{:seconds, 1}, {:milliseconds, 843}]

iex> {:ok, r, "", _, _, _} = parse("12:34")
iex> r
[{:minutes, 12}, {:seconds, 34}]

iex> {:ok, r, "", _, _, _} = parse("12:34.56")
iex> r
[{:minutes, 12}, {:seconds, 34}, {:milliseconds, 560}]

iex> {:ok, r, "", _, _, _} = parse("12:34.5")
iex> r
[{:minutes, 12}, {:seconds, 34}, {:milliseconds, 500}]

iex> {:ok, r, "", _, _, _} = parse("1:2")
iex> r
[{:minutes, 1}, {:seconds, 2}]

iex> {:ok, r, "", _, _, _} = parse("1:2:3.4")
iex> r
[{:hours, 1}, {:minutes, 2}, {:seconds, 3}, {:milliseconds, 400}]

iex> {:ok, r, "", _, _, _} = parse("01:02:03")
iex> r
[{:hours, 1}, {:minutes, 2}, {:seconds, 3}]

iex> {:ok, r, "", _, _, _} = parse("00:00:00.123")
iex> r
[{:hours, 0}, {:minutes, 0}, {:seconds, 0}, {:milliseconds, 123}]

Link to this section Summary

Functions

Parses the given binary as parse.

Get total milliseconds from a Normal Play Time string.

Get total milliseconds from parse result.

Link to this section Functions

Link to this function

parse(binary, opts \\ []) View Source
parse(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: pos_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses the given binary as parse.

Returns {:ok, [token], rest, context, position, byte_offset} or {:error, reason, rest, context, line, byte_offset} where position describes the location of the parse (start position) as {line, column_on_line}.

Options

  • :line - the initial line, defaults to 1
  • :byte_offset - the initial byte offset, defaults to 0
  • :context - the initial context value. It will be converted to a map
Link to this function

parse_total_ms(playtime) View Source

Get total milliseconds from a Normal Play Time string.

See https://www.w3.org/TR/media-frags/#npttimedef.

Examples

iex> parse_total_ms("00:01:30.00") 90000

iex> parse_total_ms("something") nil

Get total milliseconds from parse result.

Examples

iex> total_ms [{:hours, 1}, {:minutes, 2}, {:seconds, 3}, {:milliseconds, 400}] 3723400