Skip to content

How to Generate Video Download Links with youtube-dl

youtube-dl is a versatile and reliable tool for downloading streaming videos from various sites and not just YouTube. It not only fetches the download link but also downloads them right from the terminal or command-line. As such, one does not need a download manager to use the tool.

Nevertheless, downloading is not youtube-dl’s strongest point. Compared to dedicated download managers, Youtube-dl is not only comparatively slower but also doesn’t support multiple concurrent downloads.

Likewise, while it’s possible to resume interrupted downloads with it, this is only ideal for single downloads.

There are a couple of ways to get around these limitations. The first one is to use a download manager that supports downloading steaming videos. Of these you’ll find two types: youtube-dl frontends like Persepolis or the numerous commercial / freeware options that exist.

The second option is to use youtube-dl to generate the download links then use your preferred download manager to download the media files. This will be the subject of this tutorial.

One clear advantage of going this route is that it not accelerates your downloads but also gives you control of the video and audio formats to download unlike other video downloaders which only provide a handful of preset formats.

Step 1: Install youtube-dl

Download the latest youtube-dl executable for Windows or install it using a package manager if you’re using a Linux distribution or macOS. You can also use e youtube-dl fork like yt-dlp.

While we won’t be using it in this tutorial you’ll want to install FFmpeg if you intend to carry out some post-processing like merging separate audio and video files or converting the downloaded formats e.g WebM to MP4, Opus or M4A to MP3 etc.

On Windows download the latest FFmpeg executable and place it in the same folder as the youtube-dl executable, while on Linux just install it using your distribution’s package manager.

Step 2: Generate Download Links with youtube-dl

1. Launch the terminal or the command prompt. On Windows you’ll need first to navigate to the directory where the youtube-dl executable is located.

2. To generate the download link only, we need to use the option -g or --get-url. So for instance, to get the download URL for a YouTube URL you’ll need to run the following command:

youtube-dl https://www.youtube.com/watch?v=J38Yq85ZoyY -g

Or

youtube-dl https://www.youtube.com/watch?v=J38Yq85ZoyY --get-url

This will return the download URL for the video which you can then use with your download manager.

Screenshot of youtube-dl in the command prompt with download links generated.
youtube-dl generated download links

TIP: On Windows, make sure the Quick Edit Mode is enabled so that it’s easy to copy and paste links from the command prompt window. To do that, just right-click anywhere on the title bar then select Properties and go to Options > Edit options.

3. In the above command, youtube-dl will by default fetch the link for the best available formats i.e the highest quality. In the case of YouTube you may therefore end up getting two separate download URLs for the video and audio files.

As such you’ll need to merge the files manually with FFmpeg or a join them with a muxer like MKVToolNix. You can however skip the merging if you use a media player like PotPlayer which picks up external audio automatically so long as the two files have the same filename and are in the same folder.

To avoid all this, you can use the best option which tells youtube-dl to gets the best available format in a single container (MP4):

youtube-dl -f best https://www.youtube.com/watch?v=J38Yq85ZoyY -g

4. If you want to download a specific format (e.g 720p MP4), you can do that by first getting a list of all available formats using the option -F as follows:

youtube-dl -F https://www.youtube.com/watch?v=J38Yq85ZoyY

This will return all the available video and audio formats with their IDs. You can then generate the link for the exact format you want by specifying its ID as follows:

youtube-dl -f 18 https://www.youtube.com/watch?v=J38Yq85ZoyY -g
Screenshot of youtube-dl in the command prompt having fetched all available video formats.

5. You can alternatively specify a certain resolution instead of having to get the format ID first. To do this, specify the resolution’s height as follows:

youtube-dl -f "best[height<=720]" https://www.youtube.com/watch?v=J38Yq85ZoyY -g

The above command will fetch the download URL for the best available video format that has a resolution of 720p or less. In case it finds no video with a 720p quality, it will fetch the next best available format in line i.e. 480p > 360p > 240p > 144p.

6. If you only want the download link for the best available audio format use the bestaudio option as follows:

youtube-dl -f bestaudio https://www.youtube.com/watch?v=J38Yq85ZoyY -g

With YouTube, this will usually fetch the Opus (ogg) format which has the best quality. You can however get the more common M4A format using:

youtube-dl -f m4a https://www.youtube.com/watch?v=J38Yq85ZoyY -g

Note: The above commands should work on other video hosting sites that Youtube-dl supports and not just YouTube e.g. Facebook, Dailymotion, Vimeo etc.

Step 3: Batch Generate Download Links using Youtube-dl

You can batch generate multiple download URLs for videos in two ways:

a. Using a playlist URL

Generating links for a YouTube playlist is similar to that of a single video, you only need to use the playlist URL instead:

youtube-dl -f best https://www.youtube.com/playlist?list=PLL5UQuWqy6y-MtCkamPLFxVgELoZgsYHF -g

b. Using a Text file

You can specify a list of video URLs in a text file for youtube-dl to download using the -a option. Each video URL needs to start on a new line in the text file.

Save this text file in the same folder where the youtube-dl executable is located (otherwise you’ll need to specify its path) then run the command:

youtube-dl -f best -a links.txt -g

In both of the commands above, youtube-dl will fetch the best available video format for each of the videos. You can use the commands from the previous section to specify exact formats.

Once all the download links have been generated, just copy them from the command prompt / terminal, then use the option to import downloads from the clipboard or its equivalent in your download manager.

This option is available in downloads managers like Free Download Manager and uGet, the latter as a clipboard batch option.

In other download managers like Persepolis and IDM, you’ll have to save the links first in a text file then import it.

Note: This may not be a very ideal way of downloading huge playlists or very long lists though technically it should work. Nevertheless, be mindful of the fact that most of these download links expire after a specific period. You may therefore want to break the download task into several batches to avoid expired links, especially if your internet speed is not fast or reliable.

Share:

Leave a Reply

Feel free to share your comments or questions with me. I may not be able to respond immediately so please check later once I've approved your comment.

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

Kelvin Kathia

Kelvin Kathia is a writer that's passionate about sharing solutions to everyday tech problems. He's the founder and editor of Journey Bytes, a tech blog and web design agency. Feel free to leave him comments or questions regarding this post, or by leaving him a message on the contact page. If you found his content helpful, a donation is much appreciated.