A dead simple vtt parser in Elixir.
To install Vttyl, add it to your mix.exs
file.
def deps do
[
{:vttyl, "~> 0.3.0"}
]
end
Then, run $ mix deps.get
.
Vttyl has two basic ways to use it.
iex> vtt = """
WEBVTT
1
00:00:15.450 --> 00:00:17.609
Hello world!
"""
...> Vttyl.parse(vtt) |> Enum.into([])
[%Vttyl.Part{end: 17609, part: 1, start: 15450, text: "Hello world!", voice: nil}]
iex> "same_text.vtt" |> File.stream!([], 2048) |> Vttyl.parse_stream() |> Enum.into([])
[%Vttyl.Part{end: 17609, part: 1, start: 15450, text: "Hello world!", voice: nil}]
(Closing voice spans are currently not supported)
iex> vtt = """
WEBVTT
1
00:00:15.450 --> 00:00:17.609
<v Andy>Hello world!
"""
...> Vttyl.parse(vtt) |> Enum.into([])
[%Vttyl.Part{end: 17609, part: 1, start: 15450, text: "Hello world!", voice: "Andy"}]
Vttyl also supports encoding parts.
iex> parts = [%Vttyl.Part{end: 17609, part: 1, start: 15450, text: "Hello world!"}]
...> Vttyle.encode(parts)
"""
WEBVTT
1
00:00:15.450 --> 00:00:17.609
Hello world!
"""
iex> parts = [%Vttyl.Part{end: 17609, part: 1, start: 15450, text: "Hello world!", voice: "Andy"}]
...> Vttyle.encode(parts)
"""
WEBVTT
1
00:00:15.450 --> 00:00:17.609
<v Andy>Hello world!
"""
Vttyl is Copyright © 2019 Grain Intelligence, Inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
Vttyl is maintained and funded by Grain Intelligence, Inc. The names and logos for Grain are trademarks of Grain Intelligence, Inc.
For more information, see the documentation.