Created
August 28, 2024 14:59
-
-
Save leemcd56/87559330628ba92f680183f744c21065 to your computer and use it in GitHub Desktop.
Extract and list chapters from YouTube video using yt-dlp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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