Youtube-dl Howto for Mac & linux users

Where to Get youtube-dl

https://github.com/ytdl-org/youtube-dl

This how-to will show you how to set up your configuration files for quick, easy use of the youtube-dl command line application. It will show how to extract FLAC audio from the downloaded video and store it in a directory of your selection for use in your musical library.

I am not the author of this application. The information is placed here from the author’s website.

Installing youtube-dl

To install it right away for all UNIX users (Linux, macOS, etc.), type:

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 do not have curl, you can alternatively use a recent wget:

sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

Windows users can download an .exe file and place it in any location on their PATH except for %SYSTEMROOT%\System32 (e.g. do not put in C:\Windows\System32).

You can also use pip:

sudo -H pip install --upgrade youtube-dl

Setting up the youtube-dl config file

Create your youtube-dl.conf file and store it in your .config directory. If you don’t have one, simply create it.

mkdir ~/.config

Then, create your youtube-dl.conf file like so:

# place this file in ~/.config/youtube-dl.conf
#--write-thumbnail
--geo-bypass
--geo-bypass-country US
--no-check-certificate
--yes-playlist
--playlist-start 1
--ignore-errors
--no-mtime
--prefer-ffmpeg
--extract-audio
--add-metadata
--audio-format=flac
--metadata-from-title "(?P<artist>.+?)-(?P<title>.+)"
--audio-quality=0
-o "/path/to/your_audio_files/%(playlist)s/%(title)s.%(ext)s"

–yes-playlist tells youtube-dl to treat the url as a playlist, and will extract each video of the playlist as a separate file. This is particularly useful when extracting a “Greatest Hits” playlist of videos from YouTube.

For more details on configuration options look here

-o tells youtube-dl where to save the extracted audio file in the format set by the –audio-format configuration line above, with the title and extension of the format.

Update .bashrc

In your ~/.bashrc if you don’t have one, create one:

# Youtube-dl commands 
alias ytdl='youtube-dl'

By default, when you run youtube-dl, it will look to your .config/ directory for a youtube-dl.conf file. If you want to rename it or store it somewhere else, use the following command:

youtube-dl --config-location /path-to-config/your_config.conf 

To see what version is installed:

~$ youtube-dl -v 

[debug] Custom config: []
[debug] Command-line args: ['-v']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] youtube-dl version 2021.12.17
[debug] Python version 3.8.10 (CPython) - Linux-5.4.0-137-generic-x86_64-with-glibc2.29
[debug] exe versions: ffmpeg 4.2.7, ffprobe 4.2.7

If you want to update to the latest version:

youtube-dl --update

Executing youtube-dl

First, get the URL of your Youtube video, then from the command line simply run:

youtube-dl url-of-youtube-video

You will see something that looks like this:

[youtube] Extracting URL: https://www.youtube.com/watch?v=JnC88xBPkkc
[youtube] JnC88xBPkkc: Downloading webpage
[youtube] JnC88xBPkkc: Downloading android player API JSON
[MetadataParser] Parsed artist from '%(title)s': 'Rush '
[MetadataParser] Parsed title from '%(title)s': ' The Trees'
[info] JnC88xBPkkc: Downloading 1 format(s): 251
[download] Destination: /path-to-your-dl-directory/The_Trees.webm
[download] 100% of 3.84MiB in 00:00:00 at 7.98MiB/s
[ExtractAudio] Destination: /path-to-your-dl-directory/The_Trees.flac
Deleting original file /path-to-your-dl-directory/The_Trees.webm (pass -k to keep)
[Metadata] Adding metadata to "/path-to-your-dl-directory/The_Trees.flac"

Have fun with this fun an easy way to find your music!