Skip to content

Instantly share code, notes, and snippets.

@jimmygle
Created June 1, 2021 23:15
Show Gist options
  • Save jimmygle/203bf008d899aa20ee455b692fa4b8fb to your computer and use it in GitHub Desktop.
Save jimmygle/203bf008d899aa20ee455b692fa4b8fb to your computer and use it in GitHub Desktop.
Converts mp3's to m4b file
#!/usr/bin/env bash
# Jacked from here: https://gist.github.com/butuzov/fa7d456ebc3ec0493c0a10b73800bf42#gistcomment-2830778
abook() {
local DIR="${1}"
if [[ ! -d $DIR || -z $1 ]]; then
DIR=$(pwd)
fi
# generating random name
local NAME=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1)
# generating book
ls -1 "${DIR}/"*.mp3 | awk '{printf "file |%s|\n", $0}' | \
sed -e "s/|/\'/g" > "${DIR}/${NAME}.txt" \
&& ffmpeg -f concat -safe 0 -i "${DIR}/${NAME}.txt" -c copy "${DIR}/${NAME}.mp3" \
&& ffmpeg -i "${DIR}/${NAME}.mp3" "${DIR}/${NAME}.m4a" \
&& mv "${DIR}/${NAME}.m4a" "${DIR}/$(basename "${DIR}").m4b"
# Cleanup
unlink "${DIR}/${NAME}.txt"
unlink "${DIR}/${NAME}.mp3"
}
abook "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment