一些 YouTube 内容创作者将他们的视频分成章节。他们中的一部分善意地提供了描述视频中的章节标题列表及其开始时间戳。有时他们决定不展示它们。
如何获取章节标题列表?
Onliner 使用yt-dlp
(更好的替代方案youtube-dl
)和jq
JSON 处理器来执行此操作:
yt-dlp --dump-json videoIDorURL | jq --raw-output ".chapters[].title"
Run Code Online (Sandbox Code Playgroud)
要获取开始时间戳:
| jq --raw-output ".chapters[].start_time" | awk '{printf("%d:%02d:%02d\n",($1/60/60%24),($1/60%60),($1%60))}'
Run Code Online (Sandbox Code Playgroud)
通过过程替换,paste
您
可以将两者结合起来。这是一个可以添加到/的函数:.bashrc
.zshrc
function get_chapters_times() {
paste <(yt-dlp --dump-json $1 | jq --raw-output ".chapters[].start_time" | awk '{printf("%d:%02d:%02d\n",($1/60/60%24),($1/60%60),($1%60))}') <(yt-dlp --dump-json $1 | jq --raw-output ".chapters[].title")
}
Run Code Online (Sandbox Code Playgroud)
将返回:
$ get_chapters_times https://youtu.be/DxL2HoqLbyA
0:00:00 Intro
0:02:15 History
0:04:16 Ideal Engine
0:09:48 Entropy
0:11:03 Energy Spread
0:14:49 Air Conditioning
0:17:26 Life on Earth
0:19:35 The Past Hypothesis
0:21:43 Hawking Radiation
0:23:31 Heat Death of the Universe
0:24:52 Conclusion
Run Code Online (Sandbox Code Playgroud)
用于yt-dlp --split-chapters
下载各章。
归档时间: |
|
查看次数: |
6591 次 |
最近记录: |