View Source YoutubeCaptions (YoutubeCaptions v0.1.0)

Youtube captions downloader. Exposes a single function get_subtitles/3.

Fetching is done using library Req. You can pass additional options to Req.get/2 as 3rd argument.

Examples

iex> YoutubeCaptions.get_subtitles("JvBT4XBdoUE", "en")
{:ok,
[
  %{start: 0.99, text: "[Music]", duration: 6.87},
  %{start: 14.42, text: "thank you so hello everyone and thank", duration: 3.66},
  %{start: 16.67, text: "you for joining me in this talk where", duration: 3.93},
  %{start: 18.08, text: "we're going to explore the legacy of Joe", duration: 3.99},
  %{start: 20.6, text: "Armstrong the principal inventor of", duration: 4.74},
  %{start: 22.07, text: "Erlang who unfortunately recently passed", duration: 5.82},
  %{start: 25.34, text: "away and so Joe sadly will not be with", duration: 3.18},
  %{start: 27.89, text: "us anymore", duration: 2.88},
  ...
]}

Summary

Functions

Downloads subtitles of YouTube video. You have to specify video_id and optionally language. Defaults to en.

Types

@type caption() :: %{start: float(), duration: float(), text: String.t()}
@type lang() :: String.t()
@type req_options() :: keyword()
@type video_id() :: String.t()

Functions

Link to this function

get_subtitles(video_id, lang \\ "en", req_options \\ [])

View Source
@spec get_subtitles(video_id(), lang(), req_options()) ::
  {:ok, [caption()]} | {:error, String.t()}

Downloads subtitles of YouTube video. You have to specify video_id and optionally language. Defaults to en.

Fetching is done using library Req. If you want, you can pass additional params to Req.get/2 using 3rd argument.

Examples

iex> YoutubeCaptions.get_subtitles("JvBT4XBdoUE", "en")
{:ok,
[
  %{start: 0.99, text: "[Music]", duration: 6.87},
  %{start: 14.42, text: "thank you so hello everyone and thank", duration: 3.66},
  ...
]}

iex> YoutubeCaptions.get_subtitles("JvBT4XBdoUE", "de")
{:error, "Unable to find transcript for language de"}

iex> YoutubeCaptions.get_subtitles("invalid", "en")
{:error, "Could not find captions for video"}