6

I want to download the subtitle of a YouTube playlist with the following specifications:

  1. Only in English
  2. In srt format
  3. Just the subtitles files and not the video itself

I have tried the following code snippet. But it is downloading the subtitles in all available languages and in vtt format.

ydl_opts = {
    'allsubtitles': True,
    'writesubtitles': True,
    'convertsubtitles':True,
    'skip_download':True,
    'outtmpl': 'C:/Users/shrayani.mondal/Desktop/Personal/Python Projects/Speech to text/Subtitles/%(title)s.%(ext)s',
    #'subtitlesformat': 'srt'
    'subtitleslangs':'en',
    'postprocessors': [{
        'key': 'FFmpegSubtitlesConvertor',
        'format': 'srt',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=Lp7E973zozc&list=PLQltO7RlbjPJnbfHLsFJWP-DYnWPugUZ7'])

My second objective is to use auto-generated English subtitles for videos that do not have subtitles available. How do I include the if statement for that?

BSMP
  • 4,596
  • 8
  • 33
  • 44
Shrayani Mondal
  • 160
  • 1
  • 7

2 Answers2

0
# if convert vtt into srt:
# use postprocessors code snippet given below


ytdlp_option = {
            "progress_hooks": [self.track_progress],
            "logger": DownloadVideo.Logger(self),
            "noplaylist": True,
            "format": f'{self.selected_file.get(VIDEO, {}).get("format_id")}+{self.selected_file.get(AUDIO, {}).get("format_id")}',
            "paths": {"home": self.video_download_path},
            "outtmpl": {"default": f"{self.video_file_path}.{self.output_extension}"},
            "postprocessors": [
                {
                    "key": "FFmpegSubtitlesConvertor",
                    "format": "srt",
                }
            ]
            "writesubtitles": True,
            "subtitlesformat": "vtt"
            "subtitleslangs": ["en"],


        }
-1

you can download subtitle only use this way.

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

Default download subtitle language is Eng. more option have in this link or youtube-dl --help (enter link description here

default subtitle format is vtt. can you convert to srt. try with youtube-dl or simply convertor have in internet.

TipVisor
  • 1,022
  • 10
  • 21
  • 1
    The OP is trying to do this programmatically, so suggesting a manual method seems unhelpful (whilst one could argue it's better than nothing, I'm not convinced by the point that it can *only* be done manually) – Neil Nov 14 '20 at 14:45