#!/bin/csh ############################################################### # This script pulls in all of the songs off a CD into a # directory matching the disc's ID number underneath the # directory whose name is passed in. # # If things work out, a number of MP3 audio files # (one per audio track on the CD) are stored in the directory. # # It first checks to see if the current CD # has been read already. If it has, then it returns with code 1. # # It also duplicates the WAV files into a temporary directory # whose name is passed in as a second parameter. This is # the place where the files are played from, to avoid problems # where MP3 files claimed to be changing bit-rates when # they were played while being written (first song from BB King # album did this consistently). # # If there is some other error, it returns code 3 and deletes # all of the files in the directory. On success it returns # code 0. ############################################################## set device = '/dev/cdrom' ############################################################## # Argument checking # Make sure they passed in the name of a directory set rootdir = $1 if (0 == `echo -n "$rootdir" | wc -c`) then echo "Usage: $0 directory_to_put_files_in temporary_directory" exit 3 endif # Make sure that the directory exists if (-e "$rootdir") then else echo "Error: directory $rootdir does not exist" exit 3 endif # Make sure they passed in the name of a temporary directory set tempdir = $2 if (0 == `echo -n "$tempdir" | wc -c`) then echo "Usage: $0 directory_to_put_files_in temporary_directory" exit 3 endif # Make sure that the directory exists if (-e "$tempdir") then else echo "Error: directory $tempdir does not exist" exit 3 endif ############################################################## # Media and existence checking # Find out the ID of the disc that is in the CD device. # If there is not one, exit with an error. set discid = `musicbox_get_disc_id.txt` if ( 0 != $status) then echo "Could not read discID from CD" exit 3 endif set directory = "$rootdir"/"$discid" ############################################################## # All of the checks have been done and we're ready to do our # thing. Start by going into the directory that we are going # to fill up. Then start saving the .mp3 files. pushd $directory # Find out how many tracks there are on the disc. This is done # by running cdda2wav with the -J parameter, which # has the side effect of creating index files for each of # the tracks on the CD. cdda2wav -D $device -I cooked_ioctl -v disable -J >& /dev/null set numtracks = `ls audio_??.inf | wc -w` echo $numtracks tracks found if ( 0 == $numtracks ) then echo "Found no audio tracks on the CD" popd \rm -rf "$directory" exit 3 endif # Save each track. set track = 1 while ( $track <= $numtracks ) set prettytrack = $track if ( $track < 10 ) set prettytrack = 0$track # -S 0 is default (maximum) speed for the device. # -n 100 makes it read 100 sectors whenever it wants one # -l 200 creates a 200-entry circular buffer of sector storage # -H means no info-file # XXX -P 0 will fail to correct for bad reads, but is faster # It did cause us errors while we were reading from several # disks: small noise sounds and pops. # The -h argument for lame makes it do higher-quality compression. # The '-preset standard' argument makes it do even better. # The 'tee' command splits off the output and also sends it into # files into a temporary directory for WAV playback. cdda2wav -D $device -I cooked_ioctl -v disable -H -t $track -P 1 -n 500 -S 0 -l 1000 -Q --stereo - | tee "$tempdir"/track_$prettytrack.wav | lame --quiet -h - track_$prettytrack.mp3 set cddastatus = $status # XXX Why doesn't this catch it when the CD is popped out and # back in and there are tons of I/O errors on a track? It does # catch it if the CD is left out long enough that it fails at the # end of the track. if ( $cddastatus != 0 ) then echo "Error $cddastatus when trying to copy track $track" rm * popd \rm -rf "$directory" exit 3 endif @ track ++ end ############################################################## # Delete the information tracks. \rm -f audio_??.inf ############################################################## # Done! popd exit 0