Skip to content

Instantly share code, notes, and snippets.

@leemcd56
Created August 28, 2024 14:59
Show Gist options
  • Save leemcd56/87559330628ba92f680183f744c21065 to your computer and use it in GitHub Desktop.
Save leemcd56/87559330628ba92f680183f744c21065 to your computer and use it in GitHub Desktop.
Extract and list chapters from YouTube video using yt-dlp
#!/bin/bash
# Sourced from Unknown's answer (https://unix.stackexchange.com/a/771262)
# Note: Requires awk and gsed
# Define your YouTube URL here
videoUrl=
yt-dlp $videoUrl --dump-json |
jq -r ".chapters[] | {start_time, title}" |
awk -v count="2" '++count==4{$0=sprintf(" \"start\":%d:%02d:%02d",($2/60/60%24),($2/60%60),($2%60));count=0} 1' |
awk -F '":' '{print $2}' |
gsed -r -e '/^\s*$/d' -e 's/^ "|"$//g' |
paste -d " " - -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment