我想下载具有以下规范的YouTube播放列表的字幕:
我已经尝试了以下代码片段。但是它正在以所有可用的语言和vtt格式下载字幕。
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'])
我的第二个目标是为没有字幕的视频使用自动生成的英语字幕。我如何包括这方面的if语句?
发布于 2022-07-13 15:02:24
# 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"],
}
发布于 2020-03-27 12:24:03
你只能用这种方式下载字幕。
youtube-dl --write-sub --write-auto-sub --skip-download YOURLINK
默认下载字幕语言是英语。此链接或youtube-dl --帮助(在这里输入链接描述 )中有更多选项。
默认的字幕格式是vtt。你能转换成srt吗。尝试使用youtube-dl或简单的网络转换器。
https://stackoverflow.com/questions/58218836
复制相似问题