youtube-dl/yt-dlp を使用して YouTube 動画の章のタイトルを一覧表示する方法

youtube-dl/yt-dlp を使用して YouTube 動画の章のタイトルを一覧表示する方法

一部の YouTube コンテンツ制作者は、動画を複数の章に分割します。彼らの中には、説明ビデオにチャプタータイトルのリストとスタートタイムスタンプを親切に提供しました。時々彼らは示さないことにします。

章のタイトルのリストを取得するには?

ベストアンサー1

これを行うには、1行のコードを使用してください。yt-dlp(より良い選択肢youtube-dl)とjqJSONハンドラ:

yt-dlp --dump-json  videoIDorURL | jq --raw-output ".chapters[].title"

開始タイムスタンプを取得するには:

 | jq --raw-output ".chapters[].start_time" | awk '{printf("%d:%02d:%02d\n",($1/60/60%24),($1/60%60),($1%60))}'

そしてpasteそしてプロセスの交換 2つを組み合わせることができます。.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")
}

次を返します。

$ 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

使用yt-dlp --split-chaptersすべての章をダウンロードしてください。

おすすめ記事