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
4 Answers
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
- 2,226
- 3,488
-
70I gave the docs a fair look and didn't find the
--skip-downloadoption 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
-
5It'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
-
3It'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-subfrom 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 YouTubemessage. 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 v0uYZ4rTOrk1. 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-downloadwould still download things. That is not clearly mentioned in the documentation. – Daniel H Oct 28 '20 at 17:27 -
1Alternative 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-subtitlesand--write-subdo the trick? – Emmanuel Goldstein Feb 10 '21 at 08:03 -
4It 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-subinstead.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 thanyoutube-dltoday. It is a fork off ofyoutube-dl. So, if you're having trouble with this answer, tryyt-dlpinstead. – Gabriel Staples Aug 04 '22 at 00:09
Or you can only download one subtitle
youtube-dl --write-sub --sub-lang en --skip-download URL
- 881
- 6
- 4
-
26Or
--write-auto-subfor downloading the automatically generated subtitles! – Lenar Hoyt Nov 22 '19 at 16:19 -
1@pouya will your option download both autogenerated and proper subtitles of english lang, for example? – Alex Jones Feb 01 '21 at 07:10
-
The accepted answer is painfully lacking the required flag. This should be accepted answer. – Soheil Oct 17 '22 at 00:06
-
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(">>"), 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.
- 399
-
1Just 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 -
9convert 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
-
4In my case, I still need to run
ffmpeg -i foo.vtt foo.srtto convert caption manually. – 林果皞 Feb 25 '21 at 22:23 -
-
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
-
2After some testing, I can say that 1)
--convert-subsswitch doesn't work with the--skip-downloadone; 2) anywayyoutube-dlusesffmpeg(oravconvfrom the dead Libav project) to do the subtitle conversion, so theffmpeg -i foo.vtt foo.srtproduces the equal srt file; 3) both--convert-subs=srtand--convert-subs srtoptions works. – Ivan Shatsky Dec 16 '21 at 00:48 -
--convert-subsseems to work for me withyt-dlpand--skip-downloadfor what it's worth.. – rogerdpack Jun 27 '23 at 05:53
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.
Paste the URL in the Google subtitles text box and click Read.
Choose the language by selecting the appropriate check box provided and press Go.
View the destination folder that was input in the SRT subtitles textbox to locate the SRT files.
-
10The 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
-
1Thanks 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
-
-
2@PhaniRithvij nope,
# youtube-dl --write-auto-sub --skip-download https://www.youtube.com/watch?v=nv99gj1xxWwworks fine on2021.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
--embed-subtitlesstep 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:25yt-dlpas well FWIW... – rogerdpack Jun 27 '23 at 05:47