Download only subtitles of videos using youtube-dl Command


👤 Diwas Poudel    🕒 15 Oct 2022    📁 TECH

There are a number of different approaches to getting subtitles for videos on YouTube. There is a wide variety of software available online that gives users the ability to download subtitles. If, on the other hand, you are already familiar with youtube-dl and wish to use it to download only subtitles from videos, then you have arrived at the correct location.

What is Youtube-dl?

YouTube-dl is a command-line program that allows you to download videos and subtitles from YouTube.com and a few other video sites. It runs on Unix, Linux, Windows, and Mac OS X and requires only a Python interpreter (2.6, 2.6, or 3.2+).

In the youtube-dl documentation, there is clearly mention of Subtitle Options.

Subtitle-Options Descriptions
--write-sub  Write subtitle file
--write-auto-sub Create a file with automatically generated subtitles (YouTube only)
--all-subs Download all of the subtitles that are currently available for the video
--list-subs List all available subtitles for the video
--sub-format FORMAT  Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"
--sub-lang LANGS  Languages of the subtitles to download(optional) separated by commas, use
  for available language tags

So, let's play with these options for downloading subtitles only from Videos.

For demonstration, we will be using Youtube, but you can use other videos as well.

1 Download only the intact subtitles from Video.

You can download all of the subtitles for a video with the following command if the owner/author of the YouTube video personally created the subtitles and added them along with the video.

youtube-dl --all-subs --skip-download VideoURL 

Example:

youtube-dl --all-subs --skip-download https://www.youtube.com/watch?v=wdqapiuJmbQ

Here, —all-subs tells YouTube to download all of the subtitles for video URL "https://www.youtube.com/watch?v=wdqapiuJmbQ" and —skip-download tells it to stop downloading the video.

Download intact subtitle from Youtube Video
fig. Download intact subtitle from Youtube Video
Also read: How to download playlist from Youtube in bulk?

2 Download auto-generated subtitles from Video 

If the owner does not have any subtitles set manually, the above command will fail. YouTube will generate subtitle scripts for you in such videos. So, if you want to download these auto-generated subtitles, use the script below.

youtube-dl --write-auto-sub --skip-download VideoURL 

Example:

youtube-dl --write-auto-sub --skip-download https://www.youtube.com/watch?v=Ns5YsDtzA4M

This youtube URL doesn't have subtitles so it will download auto-generated subtitles and also keep downloading the video.

Download auto generate subtitles from youtube video
fig. Download auto-generate subtitles from youtube video
Also read: How to increase Youtube playback speed more than 2x?

3 List all the available subtitles for the video 

It will list all of the video's subtitle languages and formats. The command for this is as follows:

youtube-dl --list-subs VideoURL 

Example:

List all available Subtitles for the video
fig. List all available Subtitles for the video
youtube-dl --list-subs https://www.youtube.com/watch?v=wdqapiuJmbQ

4 Download Subtitles on Youtube in various languages using youtube-dl 

youtube-dl --write-sub --sub-lang LANG --skip-download URL 

With the above, we have a video that has two languages en and es. So, let's download subtitles in Spanish Language(es) as shown below:

youtube-dl --write-sub --sub-lang es --skip-download https://www.youtube.com/watch?v=wdqapiuJmbQ

If you want auto-generated subtitles in es then use --write-auto-sub instead of --write-sub

5 Download Subtitle in srt format

If you want to download only in srt format then you can use the below command:

youtube-dl --write-auto-sub --convert-subs=srt --sub-lang en --skip-download URL 

For the video: https://www.youtube.com/watch?v=abcxyz, the file named will be abcxyz.en.srt 

6 Download autogenerated only if the manually generated file is not present.

For this, you can combine both --write-sub and --write-auto-sub options in one command as shown below.

youtube-dl --write-sub --write-auto-sub --skip-download VIDEOURL

Conclusion:

This article might be helpful to you if you just want to download video subtitles only using youtube-dl

FAQ:

Why not able to download subtitles using youtube-dl?

For various reasons, the video's author can disable automatic captioning. If they did not include manual subtitles, none are available.You will also be unable to download those types of subtitles. Also, there might be another reason like you might be using the wrong command for generating subtitles.