Harry Rose

Home » Shell » Ripcd

Rip CD

This is a script I use when I want to quickly rip an album to disk and encode to mp3. It doesn't do any ID3 information at the moment, to do that I use KID3 (available for Linux and Windows).

The code does depend on you having lame and cdparanoia installed, and should hopefully be fairly easy to configure. Basically to use it you use the following command. It will then proceed to rip the music from the CD to $rootdir/Artist/Album.

$ ripcd "Artist Name" "Album Name"

You can download the script from here.

#!/bin/bash
 
############################
#    Configuration      #
############################
 
# The CD Rom to rip from
    device="/dev/hda"
    lameOptions="-h --preset extreme"
# The directory the files should be stored to (no trailing /)
    rootDir="/home/harry/Music"
 
############################
 
if [ $# -lt 2 ]; then
    echo "Usage: ";
    echo "    $0 Artist Album";
    exit;
fi
artist=$1
album=$2
 
directory="$rootDir/$artist/$album/"
 
if [[ -d $directory ]]; then
    echo "$directory exists";
else
    echo "$directory does not exist, creating a new one"
    mkdir -p "$directory"
fi
 
cd "$directory"
 
echo "Beginning rip"
cdparanoia -B -d $device
 
for file in *.wav
do
    outFile=`echo "$file" | sed "s/\.wav//"`.mp3
    echo "Encoding $file to $outFile";
    lame $lameOptions "$file" "$outFile"
done;
echo "All Done, your files can be found in $directory. Run rm *.wav from within the directory to delete the wav files.";