EOF
}
+# On MacOS, use gfind since AAXtoMP3 needs it.
+FIND=find
+which gfind &> /dev/null
+if [[ $? -eq 0 ]]; then
+ FIND=gfind
+fi
+
debug=0
while getopts "a:dhi:o:" flag; do
case $flag in
which AAXtoMP3 &> /dev/null || die "Failed to locate AAXtoMP3. Please install it."
which audiobooker &> /dev/null || die "Failed to locate audiobooker. Please install it."
which tagger.py &> /dev/null || die "Failed to locate tagger.py. Please install it."
+which mp3splt &> /dev/null || die "Failed to locate mp3splt. Please install it."
[[ -v authcode ]] || die "You must specify the authcode."
[[ -v input ]] || die "You must specify the input file."
[[ -f "${input}" ]] || die "Not a normal file: ${input}"
# For some reason, AAXtoMP3 doesn't give us much control over the output file name.
# Let's find out what it is using the "find" command, and change it to something well-behaved.
pushd "${tmpdir}" &> /dev/null || die "failed to pushd ${tmpdir}"
-find -name '*.mp3' -type f -print0 | xargs -0 -I{} mv {} "${tmpdir}/input.mp3"
+$FIND -name '*.mp3' -type f -print0 | xargs -0 -I{} mv {} "${tmpdir}/input.mp3"
popd &> /dev/null
[[ $? -eq 0 ]] || die "Failed to locate and move the AAXtoMP3 output."
mkdir -p "${tmpdir}/output" || die "failed to create ${tmpdir}/output directory"