Heres that code I promised:
#Little script to automatically encode .aiff files to mp3sIts got a few comments in there, but I had a bad habit of adding crap and forgetting to document it.
#It also takes the directories around it to figure out
# artist and album info (I'm too lazy to keep looking for a
# means of taking them from the .aiff files
#It then hides the original aiff file by affixing a . to th beginning
#iterates through the working directory looking for .aiff files
#(In several instances, I had some files that were just .aif
# and others that were .aiff, so I just stuck the wildcard on the end
dir="*.aif*"
if [ $1 = "all" ]
then
dir="*/*/*.aif*"
fi
for file in $dir
do
#takes the full path and chops everything but the working directory itself
# the ## represent taking the longest suitable string from the LEFT side
temp=${file##/*/}
album=${temp%/*}
#takes the album off of the front, essentially
temp=${file%/*/*}
#takes the rest of the path off, hopefully keeping the artist
artist=${temp##/*/}
#checks to see if the user selected to automatically pick out
# the track number from the beginning of the filename
num=""
if [ $# -gt 0 ] && [ $1 = "trackno" ] || [ $1 = "all" ]
then
temp=${file##*/}
num="--tn ${temp%%\ *}"
fi
if [ $# -lt 2 ]
then
#runs the sublimely simple lame encoder command with 192 kbps bitrate
lame -h -b 192 "$file" "${file%.*}.mp3" --ta "$artist" --tl "$album" $num
#if the user supplies "album", it assumes that the only relevant directory
#corresponds to the album name
elif [ $2 = "album" ]
then
lame -h -b 192 "$file" "${file%.*}.mp3" --tl "$album" $num
#if the user supplies "artist", it assumes that the only relevant directory
#corresponds to the artist name
elif [ $2 = "artist" ]
then
lame -h -b 192 "$file" "${file%.*}.mp3" --ta "$album" $num
else
echo "incorrect parameters"
fi
#these two below are so that apache, obsidianmusic and amarok can work
# with the files to their hearts content
sudo chmod 777 "${file%.*}.mp3"
sudo chown dhcp "${file%.*}.mp3"
#Hides the old aiff files so that it doesn't do them twice.
mv "$file" "${file%/*}/.${file##*/}"
done
More descriptions on it later!
No comments:
Post a Comment