An elixir library for fetching Youtube Captions without API key. Uses Req under the hood.
The package can be installed by adding youtube_captions
to your list of dependencies in mix.exs
:
def deps do
[
{:youtube_captions, "~> 0.1.0"}
]
end
And run mix deps.get
.
First find video identifier. You can find it in the YouTube URL ?v=VIDEO_ID
.
Then you can download captions by calling YoutubeCaptions.get_subtitles(video_id, language)
. Language is optional and defaults to en
.
If successfull, you'll get list of subtitles in format %{start: float(), duration: float(), text: String.t()}
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},
#=> ...
#=> ]}
# You can customize Req options by passing third parameter
YoutubeCaptions.get_subtitles("JvBT4XBdoUE", "en", receive_timeout: 10_000)
Heavily inspired by youtube-captions-scraper.
Copyright © 2023-present Jakub Skałecki
This work is free. You can redistribute it and/or modify it under the
terms of the MIT License. See the LICENSE.md file for more details.