This file contains 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/sh | |
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 | |
INFO="tmp_out.info.json" | |
AUDIO="tmp_out.mp3" | |
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* |
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
Hello @totetmatt ,
I want to use your script to download audio from a youtube video and splitting with the chapters set on the video.
But, there is an error with xargs on macOS Big Sur :
Is there a workaround to use it on macOS ?
Thanks.