Srt (srt v0.1.0)
Decode SRT subtitles.
Summary
Functions
Decode SRT subtitles and optionally strip HTML tags. Invalid html tags are preserved always stripped.
Types
@type opts() :: {:strip_tags, boolean()}
Functions
@spec decode(String.t(), [opts()]) :: [Srt.Subtitle.t() | {:error, String.t()}]
Decode SRT subtitles and optionally strip HTML tags. Invalid html tags are preserved always stripped.
{\an1} caption position is parsed and returned in text_positions
field as a list of integers (default is 0).
This coord format is not supported: 00:00:33,920 --> 00:00:37,360 X1:100 Y1:100 X2:200 Y2:200
Any parsing errors are returned as {:error, String.t()} for all invalid subtitle entries.
If you want to raise an error for invalid subtitles, use decode!/1
.
Options
:strip_tags
- When true, strip HTML tags from the text. Original tags are preserved and stripped text is returned intext_stripped
field.
Examples
Decode SRT subtitles and parse errors.
iex> """
...> 1
...> 00:00:33,920 --> 00:00:37,360
...> <i>Long ago,
...> the plains of East Africa</i>
...>
...> 2
...> 00:00:37,440 --> 00:00:40,440
...> <i>were home to our distant ancestors.</i>
...>
...> 3
...> 00.00.40,440 --> 00:00:43,440
...> """
...> |> Srt.decode()
[
ok: %Srt.Subtitle{
index: 1,
start: ~T[00:00:33.920],
end: ~T[00:00:37.360],
text: ["<i>Long ago,", "the plains of East Africa</i>"],
text_positions: [0, 0]
},
ok: %Srt.Subtitle{
index: 2,
start: ~T[00:00:37.440],
end: ~T[00:00:40.440],
text: ["<i>were home to our distant ancestors.</i>"],
text_positions: [0]
},
error: "cannot parse \"00.00.40.440Z\" as time, reason: :invalid_format"
]
@spec decode!(String.t(), [opts()]) :: [Srt.Subtitle.t()]
See decode/2
.