DEV Community

antonio vasconcellos
antonio vasconcellos

Posted on • Edited on

Downloading YouTube Videos with Elixir

We recently had to develop some features that involved downloading videos from YouTube.

After some research, we found YT-DLP([https://github.com/yt-dlp/yt-dlp])

yt-dlp is a fork of youtube-dl based on the now inactive youtube-dlc. The main focus of this project is to add new features and patches while staying up to date with the original project.

From this came the idea of writing a simple wrapper around Elixir to facilitate integration with our stack.

exyt-dlp

[https://codeberg.org/v0i4/exyt-dlp]

setup

[https://github.com/yt-dlp/yt-dlp/wiki/Installation]
[https://hex.pm/packages/exyt_dlp]

add to your mix.exs file:
{:exyt_dlp, "~> 0.1.5"}

run mix deps.get at project root folder

check installation

iex> Exyt.check_setup()
"Installed yt-dlp version: 2023.07.06\n"
Enter fullscreen mode Exit fullscreen mode

usage

#sync
options = ["extract-audio", "audio-format": "mp3"]
iex> Exyt.download("https://www.youtube.com/watch?v=bWXazVhlyxQ", options)
{:ok, filename}

#async
options = ["extract-audio", "audio-format": "mp3"]
iex> Exyt.download("https://www.youtube.com/watch?v=bWXazVhlyxQ", options, :async)
{:ok, PID}
Enter fullscreen mode Exit fullscreen mode

docs for more details

https://hexdocs.pm/exyt_dlp/Exyt.html#content

accepting PRs :)

Top comments (1)

Collapse
 
randellbrianknight profile image
Randell Brian Knight

Hello Antonio and welcome to the Dev community 👋