Downloading videos with youtube-dl

Youtube-dl is a handy program that helps you download video content from not just Youtube, but a broad range of websites. It can download virtually any video and extract the audio too.


Follow the installation instructions for your operating system. For Macs it’s probably best to first install Homebrew and then use brew install youtube-dl.


Just open a Terminal window and enter

If you want to download the video to a specific folder, first navigate to that folder:
cd /path/to/my_folder
On a Mac, you can type cd and drag and drop the target folder from Finder into the Terminal window.

Extract Audio

To automatically extract the audio after the download enter
youtube-dl -k -x
The -k tells the program to keep the video after extracting the audio, otherwise it would be deleted. -x extracts the audio.

Advanced Options

Just like the -k -x above you can add more parameters to get exactly the results you want.

  • --audio-format wav
    Defines what format the extracted audio will be converted into. Can be best, aac, flac, mp3, m4a, opus, vorbis, wav. If you don’t define a format, it defaults to best.
  • --audio-quality 0
    Sets the audio quality: 0 is best, 9 is worse for VBR. For a constant bitrate enter it like this: 128K. Defaults to 5.
  • -f bestaudio/best
    Makes sure you download the best available quality: bestaudio downloads the best available audio-only format. If no audio-only format is available, best downloads the best available combined video and audio format. If you want to download both, the best audio-only and the best video, use a comma instead of the forward slash.
    If you’re picky, try -f "bestaudio[abr>=128]/best" to download the best audio only if its bitrate is at least 128 kBit/s, otherwise download the best video.
    You can also exclude formats, for example, if you’d rather not download MP3s: -f "bestaudio[abr>=128][acodec!=mp3]/best" or -f "bestaudio[abr>=128][ext!=mp3]/best"

For other options check the documentation.

Save configuration

Once you’ve found your ideal configuration and want to set it as default, you can save it to a configuration file that youtube-dl will reference every time it runs (except when you override this with the parameter --ignore-config).

This is a simple text file, here’s a sample:

# Lines starting with # are comments

# Download best audio if available and download best video
-f bestaudio,best

# Always extract audio and keep downloaded files
-x -k

# Convert to wav
--audio-format wav

# Bonus: Save all videos under Downloads directory in your home directory. Add original format to filename.
-o ~/Downloads/%(title)s_%(format)s.%(ext)s

youtube-dl.conf (361 Bytes)

  • On a Mac, download the file above. In the Finder app’s menu, select Go > Go to Folder... and enter /etc. Move the downloaded file to that location. Edit it by right-clicking it, then select Open With > TextEdit.
    Note: This affects all user accounts on your Mac. To save the configuration for your user account only, the file needs to be renamed config (no file extension! not config.conf, just config!). Via the Finder menu go to the folder ~/.config, create a new folder called youtube-dl and move the config file into it.
  • On Windows, download the file above and save it in your user directory: C:\Users\<user name>\youtube-dl.conf. Or, rename it and save it as %APPDATA%\youtube-dl\config.txt
    Edit it to adjust it to your preferences.

With this file in place, you can revert back to the simple syntax of
but the audio will still be extracted and put into the right directory.