#!/bin/csh # This was originally a tcsh script, but the if () then did # not seem to nest properly, although it works with csh. ############################################################### # This script pulls in all of the songs off a CD into the # directory whose name is passed in. # # If things work out, an "id" file is created in the directory # with the CD's id stored in it, and a number of MP3 audio files # (one per audio track on the CD) are stored in the directory. # # It stores the list of already-read CDs and their locations # in the catalog file whose name is passed as a second argument # once the copying has been completed. # # It first checks the catalog file to see if the current CD # has been read already. If it has, then it returns with code 1. # # It then checks to see if there is already an entry in the # specified directory. If so, it returns with a non-zero # return code: code 1 if the id in the directory matches the # id of the CD that was inserted, and code 2 if the id is # different than the CD that was inserted. # # 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 directory = $1 if (0 == `echo -n "$directory" | wc -c`) then echo "Usage: $0 directory_to_put_files_in catalog_file" exit 3 endif # Make sure that the directory exists if (-e "$directory") then else echo "Error: directory $directory does not exist" exit 3 endif # Make sure they passed in the name of a directory set catalog = $2 if (0 == `echo -n "$catalog" | wc -c`) then echo "Usage: $0 directory_to_put_files_in catalog_file" exit 3 endif # Make sure that the catalog file exists if (-e "$catalog") then else echo "Error: catalog file $catalog does not exist" exit 3 endif ############################################################## # Media and existence checking # Find out the ID of the disc that is in the CD device. # Make sure that it is valid. set discid = `musicbox_get_disc_id.txt` if ( 0 != $status) then echo "Could not read discID from CD" exit 3 endif # See if we've already read this disc (it will be in the catalog # if so). If so, return code 1. set entry = `grep $discid $catalog` if ( 0 != `echo -n $entry | wc -c` ) then echo "This disc has already been cataloged" exit 1 endif # Check to see if there is an ID file in the directory already. # If so, then return an error code. if ( -e $directory/id ) then echo "There is already another disc in $directory" exit 2 endif ############################################################## # 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 and writing the ID file. Then start saving the # .wav files into that directory. pushd $directory echo $discid > id # Find out how many tracks there are on the disc. This is done # by running cdda2wav again 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" exit 3 endif # Now convert each track into an MP3 file. # Launch the play script after track one has been completed. # Use the 'lame' program for the conversion. 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 cdda2wav -D $device -I cooked_ioctl -v disable -H -t $track -P 0 -n 100 -S 0 -l 200 -Q track_$prettytrack.wav set cddastatus = $status if ( $cddastatus != 0 ) then echo "Error $cddastatus when trying to copy track $track" rm * exit 3 endif @ track ++ end ############################################################## # Delete the information tracks. \rm -f audio_??.inf ############################################################## # Put an entry into the catalog for this CD popd echo $discid $directory >> $catalog exit 0