I wrote this as a bash script because I wanted to accomplish two things that I didn't find in any of the prebuilt GUI tools I've seen for OS X: First, I wanted to enable accurate ReplayGain, and second, I wanted to avoid clipping in the output, which requires iteratively encoding to home in on the best scale factor to avoid clipping while keeping the audio otherwise at its highest fidelity. I present what I call
semilame semiautomatic LAME:
SDIR=$PWD
TDIR=${PWD}/../../Out
CUT="/usr/bin/cut"
LAME="/usr/local/bin/lame"
for fn in $(/bin/ls -1 *.aif *.aiff *.aifc 2>/dev/null); do
clear
FName="${fn/\.aifc/}"
g_Track=$(echo $FName | $CUT -d÷ -f 1)
g_Artist=${u_Artist:=$(echo $FName | $CUT -d÷ -f 2 | sed -e 's,_,\ ,g')}
g_Title=$(echo $FName | $CUT -d÷ -f 3 | sed -e 's,_,\ ,g')
g_Album=${u_Album:=$(pwd | sed -E -e 's,(.*)/(.*)$,\2,')}
g_Scale="1"
if [[ $u_Qual ]]; then
g_Qual=$u_Qual
else
g_Qual="2"
fi
BOLD="\033[1m"
NORM="\033[0m"
echo -e "${BOLD}FILENAME: ${NORM}====== « ${BOLD}$fn${NORM} »\n"
echo -e "${BOLD}Track: ${NORM}[${BOLD}${g_Track}${NORM}]: \c"
read u_Track
echo -e "${BOLD}Total Tracks: ${NORM}[${BOLD}${g_Total}${NORM}]: \c"
read u_Total
echo -e "${BOLD}Artist: ${NORM}[${BOLD}${g_Artist}${NORM}]: \c"
read u_Artist
echo -e "${BOLD}Title: ${NORM}[${BOLD}${g_Title}${NORM}]: \c"
read u_Title
echo -e "${BOLD}Album: ${NORM}[${BOLD}${g_Album}${NORM}]: \c"
read u_Album
echo -e "${BOLD}Year: ${NORM}[${BOLD}${g_Year}${NORM}]: \c"
read u_Year
echo -e "${BOLD}Quality Level: ${NORM}[${BOLD}${g_Qual}${NORM}]: \c"
read u_Qual
if [[ -z $u_Track ]]; then
u_Track=$g_Track
fi
if [[ -z $u_Total ]]; then
u_Total=$g_Total
elif [[ -z $g_Total ]]; then
g_Total=$u_Total
fi
if [[ -z $u_Artist ]]; then
u_Artist=$g_Artist
fi
if [[ -z $u_Title ]]; then
u_Title=$g_Title
fi
if [[ -z $u_Album ]]; then
u_Album=$g_Album
fi
if [[ -z $u_Year ]]; then
u_Year=$g_Year
elif [[ -z $g_Year ]]; then
g_Year=$u_Year
fi
if [[ -z $u_Qual ]]; then
u_Qual=$g_Qual
elif [[ -z $g_Qual ]]; then
g_Qual=$u_Qual
fi
u_Scale=$g_Scale
while [[ $u_Scale != "0" ]]; do
echo -e "${BOLD}Scale: ${NORM}[${BOLD}${g_Scale}${NORM}]: \c"
read u_Scale
if [[ $u_Scale == "0" ]]; then
g_Scale=1
continue
fi
if [[ -z $u_Scale ]]; then
u_Scale=$g_Scale
elif [[ -z $g_Scale ]]; then
g_Scale=$u_Scale
fi
g_Scale=$u_Scale
LAMEOPTS="--replaygain-accurate
--clipdetect
--big-endian
--nohist
--id3v2-only
--vbr-new
-V
$u_Qual
-q
$u_Qual
--temporal-masking
1
--ignore-tag-errors
"
LAMEARGS="--tt
$u_Title
--tl
$u_Album"
if [[ -n $u_Artist ]]; then
LAMEARGS="$LAMEARGS
--ta
${u_Artist}"
fi
if [[ -n $u_Total ]]; then
LAMEARGS="$LAMEARGS
--tn
${u_Track}/${u_Total}"
else
LAMEARGS="$LAMEARGS
--tn
${u_Track}"
fi
if [[ -n $u_Year ]]; then
LAMEARGS="$LAMEARGS
--ty
$u_Year"
fi
if [[ -n $u_Scale ]]; then
LAMEARGS="$LAMEARGS
--scale
$u_Scale"
fi
OLDIFS=$IFS
IFS='
'
LAMELINE="${LAME}
${LAMEOPTS}
${LAMEARGS}
$fn
${TDIR}/${fn/aifc/mp3}"
$LAMELINE
IFS=$OLDIFS
echo -e "Set Scale to ${BOLD}0${NORM} to continue.\n"
done
done