204

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

5
  • 18
    the option is --skip-download
    – 尤川豪
    Oct 1, 2015 at 8:57
  • 2
    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 8, 2020 at 1: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, 2020 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. Nov 16, 2020 at 4:56
  • @HashimAziz Judging use-cases is not an answerer's job.
    – felwithe
    Jun 5, 2021 at 18:16

4 Answers 4

250

There is an option, clearly 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
15
  • 61
    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 7, 2016 at 19:04
  • 9
    how to download autogenerated subtitles?
    – brauliobo
    Sep 7, 2017 at 17:39
  • 4
    It's clearly "mentioned in documentation" and "clearly mentioned in this answer": "--write-auto-sub Write automatic subtitle file (YouTube only)"
    – radekg
    Sep 16, 2017 at 7:41
  • 17
    @brauliobo --write-auto-sub from documentation, youtube-dl --sub-lang LANG --write-auto-sub --skip-download URI.
    – Pablo A
    Jan 13, 2018 at 18:35
  • 5
    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, 2019 at 16:14
58

Or you can only download one subtitle

youtube-dl --write-sub --sub-lang en --skip-download URL 
2
  • 22
    Or --write-auto-sub for downloading the automatically generated subtitles!
    – Lenar Hoyt
    Nov 22, 2019 at 16:19
  • @pouya will your option download both autogenerated and proper subtitles of english lang, for example? Feb 1, 2021 at 7:10
17

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.
8
  • 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 4, 2020 at 2:50
  • 7
    convert subs doesn't seem to work if you use the --skip-download option it just gives it in vtt format
    – pt123
    Aug 29, 2020 at 22:50
  • 4
    In my case, I still need to run ffmpeg -i foo.vtt foo.srt to convert caption manually.
    – 林果皞
    Feb 25, 2021 at 22:23
  • 1
    @pt123 not working open issue: github.com/ytdl-org/youtube-dl/issues/9073
    – Tilo
    Jun 12, 2021 at 4:26
  • 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. Dec 16, 2021 at 0:48
5

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.

6
  • 9
    The issue with this is that it only works with YouTube; youtube-dl supports hundreds of other sites. Nov 14, 2016 at 2:48
  • 9
    The question is about youtube-dl.
    – user598527
    Apr 18, 2017 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). Feb 4, 2018 at 6:31
  • 3
    @miles-wolbe I'd appreciate it if you could mention a YouTube video where youtube-dl failed.
    – naki
    Mar 19, 2019 at 7:37
  • 1
    @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, 2021 at 9:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.