Packages

WebVTT subtitle parser. Tested. Defines a generic Cue struct.

Current section

Files

Jump to
kim_subtitle lib subtitle helpers.ex
Raw

lib/subtitle/helpers.ex

defmodule Subtitle.Helpers do
def parse_integers(strings) do
maybe_ints =
strings
|> Enum.map(&Integer.parse/1)
|> Enum.map(fn
{int, ""} ->
int
_other ->
:error
end)
if Enum.member?(maybe_ints, :error) do
:error
else
{:ok, maybe_ints}
end
end
def to_ms(mm, ss, ttt) do
to_ms(0, mm, ss, ttt)
end
def to_ms(hh, mm, ss, ttt) do
ttt + ss * 1_000 + mm * 60 * 1000 + hh * 60 * 60 * 1000
end
def split_ms(ms) do
hours = div(ms, 60 * 60 * 1000)
mm = div(ms, 60 * 1000) - hours * 60
ss = div(ms, 1000) - mm * 60 - hours * 60 * 60
ttt = ms - ss * 1000 - mm * 60 * 1000 - hours * 60 * 60 * 1000
[hours, mm, ss, ttt]
end
end