Making configurations for youtube-dl

What is youtube-dl?

Youtube-dl is a command-line tool that can download videos from multiple websites including Youtube. It can also download audio, subtitles, thumbnails, metadata, and a lot more. It requires the Python 2.6, 2.7, or 3.2+, and it is not platform-specific.

In some cases you might only want to download the audio of a video. In other cases you might need to login to the site (with cookies or password) and download a non-public video.

youtube-dl documentation is able to get settings in a couple of ways.

You can configure youtube-dl by placing any supported command-line option to a configuration file“.

youtube-dl documentation

So how do we do that exactly? Well, we have some options.

Alternative 1: Single config file… 🥱

The thing about config files is that they are universal, and will always be applied when you are trying to download something.

If you want to ignore it you will have to add --ignore-config and add your options manually.

If you think that is OK and really don’t care, here is how to make a config file.

This example will be for Windows computers, but the gist is the same for all operating systems, except for the location of the config file

For Windows you need to make a file like for example:

%APPDATA%\youtube-dl\config.txt

Then, in the configuration file you can include something like:

# Extract audio from video files
--extract-audio
--audio-format mp3
--audio-quality 0
--embed-thumbnail
--add-metadata

Now, all your new downloads will adhere to this configuration.

But what if you need different config files for different tasks? Unfortunately, that feature is not yet available, but there are workarounds.

Alternative 2: Multiple config files 😒

You can make multiple config files and then use --config-location to specify a specific config file each time.

For example:

youtube-dl --config-location %APPDATA%\youtube-dl\audio.txt https://www.youtube.com/watch?v=Ix6nFKMWU3Y

The obvious disadvantage is that you will have remember the name of the config file every time.

Alternative 3: Script files 🤩

Instead of manually making config files, which you will have to enter the path for every time, why not just make a script file instead?

Its really easy and you can make cool additions, like for example update youtube-dl for each run, post processing and so forth.

I am using batch, but you are free to use any weapon of choice here. Py, bash, or whatever floats your boat.

Here are two examples:

Example: Download MP3.bat

:: This script will download video with youtube-dl and convert it to audio
:: Requires Windows, youtube-dl and a link to download

set /p link="Enter the link of the video or audio you want to download: "

pushd %~dp0
cd /d %~dp0

start /w python.exe -m pip install --upgrade pip
start /w python.exe -m pip install --upgrade youtube-dl

youtube-dl ^
--ignore-config ^
--extract-audio ^
--audio-format mp3 ^
--audio-quality 0 ^
--embed-thumbnail ^
--add-metadata ^
--console-title ^
--output "%userprofile%/desktop/%%(title)s.%%(ext)s" ^
"%link%"

This script will download a video to MP3 in the best available quality.

Example: Download video.bat

set /p link="Enter the link of the video or audio you want to download: "
set location=%userprofile%/desktop/

pushd %~dp0
cd /d %~dp0

start /w python.exe -m pip install --upgrade pip
start /w python.exe -m pip install --upgrade youtube-dl

youtube-dl ^
--ignore-config ^
--write-description ^
--write-info-json ^
--add-metadata ^
--write-annotations ^
--write-thumbnail ^
--write-all-thumbnails ^
--write-sub ^
--all-subs ^
--no-overwrites ^
--embed-thumbnail ^
--console-title ^
--output "%location%/%%(title)s/%%(title)s.%%(ext)s" ^
"%link%"

echo Download location:
echo %location%
pause

This script will try to update pip and youtube-dl, so you should run it with an administrator account.

If you know any other cool ways to make configurations, please share it with us. 😊

Leave a Reply

Your email address will not be published. Required fields are marked *