Skip to content

Instantly share code, notes, and snippets.

Created June 26, 2020 08:20
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
set -x
#Download media + metadata
youtube-dl --write-info-json -x --audio-format mp3 -o "tmp_out.%(ext)s" $1
# Maybe a way to get the file name from previous function
echo :: $INFO $AUDIO ::
# Fetch the title
TITLE=$(cat "$INFO" | jq -r .title | sed -e 's/[^A-Za-z0-9._-]/_/g' )
# ^--- Remove all weird character as we want to use it as filename
# We will put all chapter into a directory
mkdir "$TITLE"
# Chapterization
cat "$INFO" |\
jq -r '.chapters[] | .start_time,.end_time-.start_time,.title ' |\
sed -e 's/[^A-Za-z0-9._-]/_/g' |\
xargs -n3 -t -d'\n' sh -c "ffmpeg -y -ss \$0 -i \"$AUDIO\" -to \$1 -codec:a copy -f mp3 \"$TITLE/\$2.mp3\""
#Remove tmp file
rm tmp_out*
Copy link

Thank you for this script @totetmatt!

@MilesTEG1, on macOS, you can get GNU xargs by installing:

brew install findutils

Then in the script, use gxargs instead of xargs.
It should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment