Logo

dev-resources.site

for different kinds of informations.

Downloading YouTube Videos with Elixir

Published at
9/14/2023
Categories
elixir
youtube
ytdlp
exyt
Author
v0i4
Categories
4 categories in total
elixir
open
youtube
open
ytdlp
open
exyt
open
Author
4 person written this
v0i4
open
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 :)

Featured ones: