Youtube-dl get playlist URLs

In this comprehensive Youtube-dl tutorial, we are going to learn what is Youtube-dl and the list of most commonly used Youtube-dl commands with examples to download audio and video streams from Internet in Linux operating systems.

What is Youtube-dl?

Youtube-dl is a most popular command line YouTube downloader application. Youtube-dl can be able to download a single track or the entire playlist in one go.

Youtube-dl is not just to download videos from Youtube, but also from a lot of other websites. You can view the complete list of supported sites here.

It is a free and open source program written in Python. It supports GNU/Linux, Mac OS X and Microsoft Windows.

1. Install Youtube-dl On Linux

Youtube-dl can be installed in many ways. Let us them all.

1.1. The officially recommended way to install Youtube-dl

The officially recommended way to install Youtube-dl is just download it, save it in your $PATH, make it executable and start using it right away.

$ sudo curl -L //yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl

If you don't have curl, use wget instead:

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

1.2. Install Youtube-dl using Pip

Alternatively, you can install it using Pip as shown below.

$ sudo -H pip install --upgrade youtube-dl

1.3. Install Youtube-dl using package manager

Youtube-dl is also available in the official repositories of some Linux distributions.

To install Youtube-dl in Alpine Linux, run:

$ sudo apk add youtube-dl

Install Youtube-dl in Arch Linux, EndeavourOS, Manjaro Linux using command:

$ sudo pacman -S youtube-dl

On Debian, Ubuntu, Linux mint, Pop_OS!:

$ sudo apt install youtube-dl

On Fedora:

$ sudo dnf install youtube-dl

On openSUSE:

$ sudo zypper install youtube-dl

1.4. Install FFmpeg on Linux

Youtube-dl depends on FFmpeg to download 720p videos from YouTube and convert videos to other formats. To install FFmpeg on Linux, refer the following guide.

  • How to install FFmpeg on Linux

1.5. Update Youtube-dl

If you've manually installed Youtube-dl using curl or wget, run the following command to update it:

$ sudo youtube-dl -U

If you installed it using pip, do:

$ sudo pip install -U youtube-dl

Those who installed Youtube-dl using the distribution's package manager, just use the appropriate update command. For example, on Arch Linux, you can update Youtube-dl by simply running the following command:

$ sudo pacman -Syu

On Debian, Ubuntu:

$ sudo apt update

Now, let us see some examples to learn to use Youtube-dl.

2. Youtube-dl Tutorial With Examples

Here, I have compiled most commonly used Youtube-dl commands to download a video or playlist from YouTube.

2.1. Download video or playlist

To download a video or the entire playlist from YouTube, just mention the URL like below:

$ youtube-dl //www.youtube.com/watch?v=7E-cwdnsiow

If you want to download video or playlist with a custom name of your choice, the command would be:

$ youtube-dl -o 'abdul kalam inspirational speech' //www.youtube.com/watch?v=7E-cwdnsiow

Replace "abdul kalam inspirational speech" with your own name.

Do you want to save the video in some other location? Use -o flag followed by the target location like below.

$ youtube-dl -o '~/Downloads/abdul kalam speech' //www.youtube.com/watch?v=7E-cwdnsiow

Here I am downloading the video to the Downloads directory.

[youtube] 7E-cwdnsiow: Downloading webpage [download] Destination: /home/sk/Downloads/abdul kalam speech.f271 [download] 100% of 111.86MiB in 01:00 [download] Destination: /home/sk/Downloads/abdul kalam speech.f251 [download] 100% of 6.12MiB in 00:03 [ffmpeg] Merging formats into "/home/sk/Downloads/abdul kalam speech.webm" Deleting original file /home/sk/Downloads/abdul kalam speech.f271 [pass -k to keep] Deleting original file /home/sk/Downloads/abdul kalam speech.f251 [pass -k to keep]

You can also include additional details, such as the title, the uploader name [channel name] and upload date etc., in the file name by using the following command:

$ youtube-dl -o '%[title]s by %[uploader]s on %[upload_date]s in %[playlist]s.%[ext]s' //www.youtube.com/watch?v=7E-cwdnsiow

2.2. Download multiple videos

Sometimes, you might want to download multiple videos from or any other site. If so, just mention the URL of the videos with space-separated like below:

$ youtube-dl

Alternatively, you can put them all in a text file and pass it to Youtube-dl as an argument like below.

$ youtube-dl -a url.txt

This command will download all videos mentioned in the url.txt file.

2.3. Download audio-only from a video

Youtube-dl allows us to download audio only from a YouTube video. If you ever been in a situation to download only the audio, run:

$ youtube-dl -x //www.youtube.com/watch?v=7E-cwdnsiow

By default, Youtube-dl will save the audio in Ogg [opus] format.

If you prefer to download any other formats, for example mp3, run:

$ youtube-dl -x --audio-format mp3 //www.youtube.com/watch?v=7E-cwdnsiow

This command will download the audio from the given video/playlist, convert it to an MP3 and save it in the current directory. Please note that you should install either ffmpeg or avconv to convert the file to mp3 format.

2.4. Download video with description, metadata, annotations, subtitles and thumbnail

To download a video along with its other details such as description, metadata, annotations, subtitles, and thumbnail etc., use the following command:

$ youtube-dl --write-description --write-info-json --write-annotations --write-sub --write-thumbnail //www.youtube.com/watch?v=7E-cwdnsiow

Suggested read:

  • Download YouTube Videos With Subtitles Using Youtube-dl

2.5. List all available formats of video or playlist

To list all available formats that a video or playlist is available in, use the following command:

$ youtube-dl --list-formats //www.youtube.com/watch?v=7E-cwdnsiow

Or,

$ youtube-dl -F //www.youtube.com/watch?v=7E-cwdnsiow

Sample output:

List all available formats of a YouTube video using youtube-dl

As you can see in the above screenshot, Youtube-dl lists all available formats of the given video. From left to right, it displays the video format code, extension and resolution note of the respective video. This can be helpful when you want to download a video at a specific quality or format.

2.6. Display the size of Youtube videos

To retrieve the file size of a video, use -F flag.

$ youtube-dl -F //www.youtube.com/watch?v=7E-cwdnsiow

You will see the file size at the end of each file.

Sample output:

[youtube] 7E-cwdnsiow: Downloading webpage [info] Available formats for 7E-cwdnsiow: format code extension resolution note 249 webm audio only tiny 51k , opus @ 50k [48000Hz], 2.56MiB 250 webm audio only tiny 68k , opus @ 70k [48000Hz], 3.23MiB 140 m4a audio only tiny 128k , m4a_dash container, [emailprotected] [44100Hz], 7.59MiB 251 webm audio only tiny 137k , opus @160k [48000Hz], 6.12MiB 160 mp4 192x144 144p 52k , avc1.4d400c, 30fps, video only, 1.71MiB 278 webm 192x144 144p 73k , webm container, vp9, 30fps, video only, 3.73MiB 133 mp4 320x240 240p 89k , avc1.4d400d, 30fps, video only, 3.12MiB 242 webm 320x240 240p 135k , vp9, 30fps, video only, 6.06MiB 134 mp4 480x360 360p 215k , avc1.4d401e, 30fps, video only, 7.53MiB 243 webm 480x360 360p 242k , vp9, 30fps, video only, 10.39MiB 135 mp4 640x480 480p 382k , avc1.4d401e, 30fps, video only, 14.13MiB 244 webm 640x480 480p 390k , vp9, 30fps, video only, 16.44MiB 136 mp4 960x720 720p 737k , avc1.4d401f, 30fps, video only, 26.99MiB 247 webm 960x720 720p 770k , vp9, 30fps, video only, 31.12MiB 137 mp4 1440x1080 1080p 1391k , avc1.640028, 30fps, video only, 46.50MiB 248 webm 1440x1080 1080p 1421k , vp9, 30fps, video only, 52.19MiB 271 webm 1920x1440 1440p 3462k , vp9, 30fps, video only, 111.86MiB 18 mp4 480x360 360p 360k , avc1.42001E, [emailprotected] 96k [44100Hz], 21.55MiB 22 mp4 960x720 720p 578k , avc1.64001F, [emailprotected] [44100Hz] [best]

2.7. Download videos in certain quality and/or format

By default, Youtube-dl will download the best available quality video. However, it is also possible to download a video or playlist at a specific quality or format.

YouTube is capable of downloading videos in the following qualities:

  • best - Select the best quality format of the given file with video and audio.
  • worst - Select the worst quality format [both video and audio].
  • bestvideo - Select the best quality video-only format [e.g. DASH video]. Please note that it may not be available.
  • worstvideo - Select the worst quality video-only format. May not be available.
  • bestaudio - Select the best quality audio only-format. May not be available.
  • worstaudio - Select the worst quality audio only-format. May not be available.

For example, if you want to download best quality format [both audio and video], just use the following command:

$ youtube-dl -f best //www.youtube.com/watch?v=7E-cwdnsiow

Similarly, to download audio-only with best quality:

$ youtube-dl -f bestaudio //www.youtube.com/watch?v=7E-cwdnsiow

To download worst quality video-only format, use the following command:

$ youtube-dl -f worstvideo //www.youtube.com/watch?v=7E-cwdnsiow

You can also combine different format options like below.

$ youtube-dl -f bestvideo+bestaudio //www.youtube.com/watch?v=7E-cwdnsiow

The above command will download best quality video-only and best quality audio-only formats and merge them together with ffmpeg or avconv. Make sure you have installed any one of these tools on your system.

If you don't want to merge, replace + [plus] operator with , [comma] like below:

$ youtube-dl -f 'bestvideo,bestaudio' //www.youtube.com/watch?v=7E-cwdnsiow -o '%[title]s.f%[format_id]s.%[ext]s'

This command will download best quality video and best quality audio and will not mix them. In this case, you will get two files, one is audio and another is video. In this example, an output template [-o option] is recommended as bestvideo and bestaudio may have the same file name.

We can even download a video or playlist at a specific quality with specific resolution.

For instance, the following command will download the best quality video in 480 pixel resolution [less than or equal to 480p].

$ youtube-dl -f "best[height

Chủ Đề