Code:
#!/bin/bash
# Copyright (c) 2007 Juriy Foboss. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# Cheking if all needed programs are installed
for PROGZ in perl mac flac; do
WPROGZ=`which $PROGZ`
if test $? -ne 0; then
# Error message is printed by 'which'
exit 1
fi
done
# Checking if APE files are presented in the directory
WAPE=`ls *.ape 2>&1`
if test $? -ne 0; then
echo "No files to convert! Exiting."
exit 1
fi
# Converting APE->WAV->FLAC
for j in *.ape; do
nice mac "$j" "$j.wav" -d
rm -f "$j"
nice flac -8 "$j.wav"
rm -f "$j.wav"
echo "$j converted."
echo "----------------------------"
done
echo "Renaming all \".ape.flac\" files to \".flac\"..."
for i in *.ape.flac; do mv "$i" "${i/.ape.flac}".flac; done
WCUE=`ls *.cue 2>&1`
if test $? -ne 2; then
for k in *.cue; do
echo "CUE file $k found! Updating..."
ls -1 -b *.cue | xargs perl -pi -w -e 's/.ape/.flac/g;';
done
fi
echo "Work complete!"