Skip to content

Instantly share code, notes, and snippets.

@jansendotsh
Created May 16, 2021 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jansendotsh/e3c922c7455ac9e6c7d77b6968e43049 to your computer and use it in GitHub Desktop.
Save jansendotsh/e3c922c7455ac9e6c7d77b6968e43049 to your computer and use it in GitHub Desktop.
m4bjoin.sh
#!/bin/bash
echo "Checking folders..."
echo
for file in *; do
if [ -d "$file" ]; then
echo "Folder found: $file"
echo "Checking for MP3 files..."
mp3count=`find "$file" -maxdepth 1 -name "*.mp3" | wc -l`
echo $mp3count
if [ "$mp3count" -gt 1 ]; then
echo "Folder is ready to merge..."
brcheck=`find "$file" -name "*.mp3" | head -1`
bitrate=`ffprobe -hide_banner -loglevel 0 -of flat -i "$brcheck" -select_streams a -show_entries format=bit_rate -of default=noprint_wrappers=1:nokey=1`
docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd)/$file":/mnt:z m4b-tool merge "." -n -q --skip-cover --audio-bitrate="$bitrate" --audio-codec=libfdk_aac --jobs=4 --output-file="$file.m4b" --logfile="$file.log"
echo "Merge done... Moving on."
echo
else
echo "Not ready for the merge..."
fi
echo
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment