Download YouTube Videos with Subtitles using Youtube-dl

Download YouTube Videos with subtitles

For those who don’t know, youtube-dl is a free, open source, command line downloader written using Python programming language. Using Youtube-dl program, we can easily download YouTube videos. Not only YouTube videos, we can also download videos from other popular websites such as Dailymotion, Vimeo, BBC, Bloomberg, CNN, ESPN, FOX News, and many more. The complete list of supported websites are given in this link. Youtube-dl is platform independent, so it will work on almost all modern operating systems including Linux, Microsoft Windows, and Mac OS X.

In this tutorial, we will see how to install youtube-dl and how to download YouTube videos with subtitle or without subtitle.

Install youtube-dl on Linux and Unix

Installing youtube-dl is fairly easy.

First download the youtube-dl script using curl or wget as shown below.

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

Or,

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

After downloading youtube-dl program, run the following command to install it.

sudo chmod a+rx /usr/local/bin/youtube-dl

Youtube-dl downloader has been installed now. Let us go ahead and see how to download videos.

Download Youtube videos with subtitles

Let us download the following YouTube video with automatically generated subtitle files.

To do so, run the following command. Replace the URL with your own.

youtube-dl --write-auto-sub 'https://www.youtube.com/watch?v=2hsWBXsNHnQ'

Sample output:

 2hsWBXsNHnQ: Downloading webpage
 2hsWBXsNHnQ: Downloading video info webpage
 2hsWBXsNHnQ: Extracting video information
 2hsWBXsNHnQ: Looking for automatic captions
 2hsWBXsNHnQ: Downloading MPD manifest
[info] Writing video subtitles to: Dr Wayne Dyer - Improve Your Life Using The Wisdom Of The Age-2hsWBXsNHnQ.en.vtt
[download] Destination: Dr Wayne Dyer - Improve Your Life Using The Wisdom Of The Age-2hsWBXsNHnQ.f242.webm
[download] 11.9% of 119.06MiB at 214.24KiB/s ETA 08:21

Download youtube videos

To download the videos with actual sub-titles uploaded by the owner, run:

youtube-dl --write-srt --sub-lang en 'https://www.youtube.com/watch?v=2hsWBXsNHnQ'

If you the video has subtitles, it be downloaded along with its sub-titles. Else, the following error message will appear.

Sample output:

 2hsWBXsNHnQ: Downloading webpage
 2hsWBXsNHnQ: Downloading video info webpage
 2hsWBXsNHnQ: Extracting video information
WARNING: video doesn't have subtitles
 2hsWBXsNHnQ: Downloading MPD manifest
[download] Destination: Dr Wayne Dyer - Improve Your Life Using The Wisdom Of The Age-2hsWBXsNHnQ.f242.webm
[download] 0.3% of 119.06MiB at 118.59KiB/s ETA 17:04

As you see in the above output, the command displays that there is no subtitle files for the specific video.

Now, play the downloaded video to verify whether the subtitle has been downloaded or not.

Download youtube videos using youtube-dl

Great! As you see in the above video, the subtitle has been downloaded.

Download Youtube videos without subtitles

To download any video, just run the following command with the respective URL as shown below.

youtube-dl https://www.youtube.com/watch?v=2hsWBXsNHnQ

Sample output:

 2hsWBXsNHnQ: Downloading webpage
 2hsWBXsNHnQ: Downloading video info webpage
 2hsWBXsNHnQ: Extracting video information
 2hsWBXsNHnQ: Downloading MPD manifest
[download] Destination: Dr Wayne Dyer - Improve Your Life Using The Wisdom Of The Age-2hsWBXsNHnQ.f242.webm
[download] 2.6% of 119.06MiB at 260.88KiB/s ETA 07:35

The above command will immediately start downloading the specified video file in the best available format.

To list of available format of a video, you need to use option “–list-formats” with the youtube-dl command.

youtube-dl --list-formats https://www.youtube.com/watch?v=2hsWBXsNHnQ

Sample output:

 2hsWBXsNHnQ: Downloading webpage
 2hsWBXsNHnQ: Downloading video info webpage
 2hsWBXsNHnQ: Extracting video information
 2hsWBXsNHnQ: Downloading MPD manifest
[info] Available formats for 2hsWBXsNHnQ:
format code extension resolution note
249 webm audio only DASH audio 79k , opus @ 50k (48000Hz), 26.95MiB
250 webm audio only DASH audio 113k , opus @ 70k (48000Hz), 36.82MiB
140 m4a audio only DASH audio 133k , m4a_dash container, mp4a.40.2@128k (44100Hz), 68.39MiB
171 webm audio only DASH audio 138k , vorbis@128k (44100Hz), 53.99MiB
251 webm audio only DASH audio 221k , opus @160k (48000Hz), 95.21MiB
278 webm 192x144 DASH video 124k , webm container, vp9, 15fps, video only, 48.65MiB
160 mp4 192x144 DASH video 128k , avc1.42c00c, 15fps, video only, 58.65MiB
133 mp4 320x240 DASH video 260k , avc1.4d400d, 30fps, video only, 130.15MiB
242 webm 320x240 DASH video 276k , vp9, 30fps, video only, 119.06MiB
17 3gp 176x144 small , mp4v.20.3, mp4a.40.2@ 24k
36 3gp 320x240 small , mp4v.20.3, mp4a.40.2
18 mp4 320x240 medium , avc1.42001E, mp4a.40.2@ 96k
43 webm 640x360 medium , vp8.0, vorbis@128k (best)

To download a specific format, you need to use option “f <format_code>” with ‘youtube-dl’ command.

I want to download “3gp” format audio (Format code number 36), so I entered the following command:

youtube-dl -f 36 https://www.youtube.com/watch?v=2hsWBXsNHnQ

Sample output:

 2hsWBXsNHnQ: Downloading webpage
 2hsWBXsNHnQ: Downloading video info webpage
 2hsWBXsNHnQ: Extracting video information
 2hsWBXsNHnQ: Downloading MPD manifest
[download] Destination: Dr Wayne Dyer - Improve Your Life Using The Wisdom Of The Age-2hsWBXsNHnQ.3gp
[download] 9.3% of 120.22MiB at 259.95KiB/s ETA 07:09

Download youtube videos with youtube-dl

As you see in the above output, the video is being downloaded in 3gp format.


Recommended read:


For more details about youtube-dl command, check the man pages.

man youtube-dl

And, that’s all for now. Hope this helps. If you find our guides useful, please share them on your social, professional networks and support OSTechNix. More good stuffs to come. Stay tuned!

Cheers!!

Reference links:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

  • AlekseyShi

    Mmm… Very well! 🙂 I should try it on my Arch Linux!

    • SK

      I tried this on my Arch Linux desktop, it worked like a charm. Good luck!