242

How can I download subtitles of a list of videos using youtube-dl? I need an option for this. However I could not find an option to download only subtitles

user198350
  • 4,019
fivetech
  • 2,583
  • 21
    the option is --skip-download – 尤川豪 Oct 01 '15 at 08:57
  • 3
    Maybe because he already downloaded the videos, and doesn't want to download them again, just wants to download the subtitles now because he didn't get them before. That's why I'm using this option. – spacefaced May 08 '20 at 01:11
  • Or it messed up the --embed-subtitles step so I want to download them again separately. (Iʼd file a bug report but the repoʼs down for the moment) – Daniel H Oct 28 '20 at 17:25
  • @Prometheus … Perhaps because YouTube subtitles are not in the standard .srt format, he got the YT timestamped formant, now wants .srt … I'm here because I have vids that have no subtitles, so I want to get them easily. – Rowe Morehouse Nov 16 '20 at 04:56
  • 3
    @HashimAziz Judging use-cases is not an answerer's job. – felwithe Jun 05 '21 at 18:16
  • Good news, all these answers seem to work with the more updated yt-dlp as well FWIW... – rogerdpack Jun 27 '23 at 05:47

4 Answers4

298

There is an option, mentioned in the documention:

Subtitle Options:

--write-sub                      Write subtitle file
--write-auto-sub                 Write automatic subtitle file (YouTube only)
--all-subs                       Download all the available subtitles of 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 IETF language tags like 'en,pt'

So for example, to list all subs for a video:

youtube-dl --list-subs https://www.youtube.com/watch?v=Ye8mB6VsUHw

To download all subs, but not the video:

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

If a video only has auto generated subtitles, then --all-subs still won't download it, instead use:

youtube-dl --write-auto-sub --skip-download https://www.youtube.com/watch?v=Ye8mB6VsUHw
rogerdpack
  • 2,226
l'L'l
  • 3,488
  • 70
    I gave the docs a fair look and didn't find the --skip-download option which is hidden under *Verbosity / Simulation Options*. Glad @fivetech asked this question, or I may still be stuck. – Zaz Aug 07 '16 at 19:04
  • 11
    how to download autogenerated subtitles? – brauliobo Sep 07 '17 at 17:39
  • 5
    It's clearly "mentioned in documentation" and "clearly mentioned in this answer": "--write-auto-sub Write automatic subtitle file (YouTube only)" – radekg Sep 16 '17 at 07:41
  • 3
    It's not that "clearly mentioned in documentation". What is the difference between write-sub, write-auto-sub vs all-subs? – Mugen Oct 27 '17 at 05:21
  • 19
    @brauliobo --write-auto-sub from documentation, youtube-dl --sub-lang LANG --write-auto-sub --skip-download URI. – Pablo A Jan 13 '18 at 18:35
  • Trying to download subtitles at the moment gives ERROR: '—list-subs' is not a valid URL. Set —default-search "ytsearch" (or run youtube-dl "ytsearch:—list-subs" ) to search YouTube message. I'm running youtube-dl v2019.02.08. – user198350 Feb 12 '19 at 21:14
  • 1
    @user598527: There should be two dashes preceding the option, not one (--list-subs). – l'L'l Feb 13 '19 at 05:52
  • 1
    @l'L'l: Thank you, I've been using an addon to convert -- to for some days, didn't cross my mind how it can affect code and commands. Thankfully I didn't create a bug report! – user198350 Feb 13 '19 at 08:54
  • 7
    youtube-dl --sub-lang en --write-auto-sub --sub-format srt --skip-download v0uYZ4rTOrk 1. get ENG subtitles 2. get auto-generated subtitles 3. get subtitles in srt format 4. do not download the movie – deadfish Mar 21 '19 at 16:14
  • It never would have occurred to me that --skip-download would still download things. That is not clearly mentioned in the documentation. – Daniel H Oct 28 '20 at 17:27
  • 1
    Alternative documentation link as the original was taken down by evil gremlins. – porkbrain Nov 04 '20 at 22:50
  • I want subs inserted in video (hardcoded): --embed-subtitles and --write-sub do the trick? – Emmanuel Goldstein Feb 10 '21 at 08:03
  • 4
    It should be made clear in the answer above that if the closed captions are auto generated they are NOT downloaded by --all-subs.

    You must use --write-auto-sub instead.

    I think this is a programming/implementation error on the part of youtube-dl, however it is such a great tool that I think we can hardly hold it against them.

    – Jack Hadley Apr 26 '21 at 11:55
  • No subtitle format found matching "srt" ? Is it limited by what the server supports? – fuzzyTew Dec 01 '21 at 10:39
  • 1
    yt-dlp (see https://github.com/yt-dlp/yt-dlp) seems to be way more up-to-date, well-maintained, and functional than youtube-dl today. It is a fork off of youtube-dl. So, if you're having trouble with this answer, try yt-dlp instead. – Gabriel Staples Aug 04 '22 at 00:09
78

Or you can only download one subtitle

youtube-dl --write-sub --sub-lang en --skip-download URL 
m3asmi
  • 881
  • 6
  • 4
29

just run the following command

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

For example you are downloading https://www.youtube.com/watch?v=example. with title "example" --convert=srt will output to a file named example.en.srt where en stands for English es for Spanish etc.

The file will have something like this:

00:00:04.259 --> 00:00:05.259
>> I’m Elon Musk.

00:00:05.259 --> 00:00:06.669 >> What is your claim to fame?

00:00:06.669 --> 00:00:07.669 >> I’m the founder of

00:00:07.669 --> 00:00:08.669 Tesla.com.

OPTIONAL - If you need the text to be cleaned up you can use python to clean it a little:

import re
bad_words = ['-->','</c>']

with open('example.en.vtt') as oldfile, open('newfile.txt', 'w') as newfile: for line in oldfile: if not any(bad_word in line for bad_word in bad_words): newfile.write(line)

with open('newfile.txt') as result: uniqlines = set(result.readlines()) with open('sub_out.txt', 'w') as rmdup: mylst = map(lambda each: each.strip("&gt;&gt;"), uniqlines) print(mylst) rmdup.writelines(set(mylst))

Output newfile.txt:

I’m Elon Musk.
What is your claim to fame?
I’m the founder of
Tesla.com.
  • 1
    Just as a markup from the doc: --convert-subs FORMAT Convert the subtitles to other format (currently supported: srt|ass|vtt|lrc) – lkahtz May 04 '20 at 02:50
  • 9
    convert subs doesn't seem to work if you use the --skip-download option it just gives it in vtt format – pt123 Aug 29 '20 at 22:50
  • 4
    In my case, I still need to run ffmpeg -i foo.vtt foo.srt to convert caption manually. – 林果皞 Feb 25 '21 at 22:23
  • python script does not work well... – nephewtom Jun 06 '21 at 12:52
  • The script works just fine. You need to run 'youtube-dl --write-auto-sub --convert-subs=srt --skip-download URL ' first. Within the same folder run the script. Change bad_words = ['-->'] to bad_words = ['-->',''] since the format seem to have changed a little. hope this helps. – Hernan Pesantez Jun 07 '21 at 14:52
  • 1
    @pt123 not working open issue: https://github.com/ytdl-org/youtube-dl/issues/9073 – Tilo Jun 12 '21 at 04:26
  • Please read the docs if you still have issues. https://github.com/ytdl-org/youtube-dl#subtitle-options – Hernan Pesantez Jun 15 '21 at 17:54
  • 2
    After some testing, I can say that 1) --convert-subs switch doesn't work with the --skip-download one; 2) anyway youtube-dl uses ffmpeg (or avconv from the dead Libav project) to do the subtitle conversion, so the ffmpeg -i foo.vtt foo.srt produces the equal srt file; 3) both --convert-subs=srt and --convert-subs srt options works. – Ivan Shatsky Dec 16 '21 at 00:48
  • --convert-subs seems to work for me with yt-dlp and --skip-download for what it's worth.. – rogerdpack Jun 27 '23 at 05:53
4

Another simple way to download subtitles from YouTube is to download Google2SRT. Google2SRT is a free, open source program for Windows, Mac and Linux that is able to download, save and convert multiple subtitles from YouTube videos.

Usage

Click the links to see screenshots of steps 1 and 2.

  1. Paste the URL in the Google subtitles text box and click Read.

  2. Choose the language by selecting the appropriate check box provided and press Go.

  3. View the destination folder that was input in the SRT subtitles textbox to locate the SRT files.

jegadesh
  • 97
  • 1
  • 2
  • 10
    The issue with this is that it only works with YouTube; youtube-dl supports hundreds of other sites. – Hayden Schiff Nov 14 '16 at 02:48
  • 11
    The question is about youtube-dl. – user198350 Apr 18 '17 at 20:53
  • 1
    Thanks so much, jegadesh! Google2SRT is just what I needed to download auto-generated closed captions/subtitles from YouTube, since youtube-dl does not handle them properly (instead returning foo has no subtitles). – Miles Wolbe Feb 04 '18 at 06:31
  • 4
    @miles-wolbe I'd appreciate it if you could mention a YouTube video where youtube-dl failed. – naki Mar 19 '19 at 07:37
  • @naki https://youtu.be/nv99gj1xxWw – Phani Rithvij Mar 05 '20 at 17:46
  • 2
    @PhaniRithvij nope, # youtube-dl --write-auto-sub --skip-download https://www.youtube.com/watch?v=nv99gj1xxWw works fine on 2021.04.17 – pzkpfw Apr 25 '21 at 09:11
  • Doesn't seem to work with URL like https://www.youtube.com/watch?v=C63moDmemSY ... – rogerdpack Jun 27 '23 at 05:56
  • one advantage this has is that it's has zero alerts on VirusTotal (of 61 virus programs) per 8 oktober 2023. Nitpicking: 10-11 programs can't check .MSI applications... https://www.virustotal.com/gui/file/93a89aaba675446c7c4aa3f8fdebfa0a63ad329316549d8485cbc8873a3d787c – GwenKillerby Oct 08 '23 at 12:58