小智 209
有一个选项,在文档中明确提到:
--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'
Run Code Online (Sandbox Code Playgroud)
例如,要列出视频的所有字幕:
youtube-dl --list-subs https://www.youtube.com/watch?v=Ye8mB6VsUHw
Run Code Online (Sandbox Code Playgroud)
要下载所有字幕,但不下载视频:
youtube-dl --all-subs --skip-download https://www.youtube.com/watch?v=Ye8mB6VsUHw
Run Code Online (Sandbox Code Playgroud)
m3a*_*smi 38
或者你只能下载一个字幕
youtube-dl --write-sub --sub-lang en --skip-download URL
只需运行以下命令
youtube-dl --write-auto-sub --convert-subs=srt --skip-download URL
Run Code Online (Sandbox Code Playgroud)
例如,您正在下载
https://www.youtube.com/watch?v=example。标题为“example”
--convert=srt
的文件将输出到一个名为example.en.srt
whereen
代表英语es
、西班牙语等的文件中。
该文件将具有以下内容:
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.
Run Code Online (Sandbox Code Playgroud)
可选 - 如果您需要清理文本,可以使用 python 稍微清理一下:
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))
Run Code Online (Sandbox Code Playgroud)
输出新文件.txt:
I’m Elon Musk.
What is your claim to fame?
I’m the founder of
Tesla.com.
Run Code Online (Sandbox Code Playgroud)
小智 6
从 YouTube 下载字幕的另一种简单方法是下载Google2SRT。Google2SRT 是适用于 Windows、Mac 和 Linux 的免费开源程序,能够从 YouTube 视频下载、保存和转换多个字幕。
单击链接以查看步骤 1 和 2 的屏幕截图。
查看在SRT 字幕文本框中输入的目标文件夹以定位 SRT 文件。
归档时间: |
|
查看次数: |
177303 次 |
最近记录: |