How to install and use youtube-dl

How to install and use youtube-dl

Introduction

A few days ago youtube-dl repository was blocked on GitHub. The takedown request was made by DMCA.

If you don't know, youtube-dl is a Python script to download video and audio files from YouTube and other websites. I had this post in the backlog for a few months. But after the news above came out, I want to summarize how to install and use youtube-dl with the necessary packages.

Installation

To install youtube-dl on Ubuntu run the:

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

If you get the following error after running youtube-dl in a command line:

/usr/bin/env: ‘python’: No such file or directory

Run:

sudo apt install python3
whereis python3
sudo ln -s /usr/bin/python3 /usr/bin/python

You need a ffmpeg package. It is used to convert video and audio files after the download is done.

sudo apt-get install ffmpeg

You also need to install AtomicParsley if you want to embed thumbnails in audio files.

sudo apt install atomicparsley

Usage

To download a video:

youtube-dl $YOUTUBE_LINK

To download an mp3 file with a thumbnail:

youtube-dl -x -embed-thumbnail --format mp3 $YOUTUBE_LINK

Note: format can be only mp3 or m4a at the moment. If one of the formats is unavailable, try another. The error will look similar to:

ERROR: requested format not available

To download a playlist:

youtube-dl -x --format m4a --embed-thumbnail --yes-playlist $YOUTUBE_PLAYLIST_URL