6 # Shell script to rip an audio CD-ROM.
8 # To use this, first create a directory for the mp3s, and cd to that
9 # directory. Then run this script. This script also saves lossless copies of
10 # the mp3s in a directory ending with [LL].
12 # One of these days I'm going to rewrite this in Ruby or some other language,
13 # and include more advanced features, like the ability to rip multiple
14 # CD-ROMs at once. For now, this script works, and is a good example of
15 # using getopts with bash.
30 audiorip: a CD-ripping script
36 -N: don't run cdparanoia
47 while getopts "Bd:e:hNs:" flag
58 if [ $end_track == 0 ]; then
59 echo "must give non-zero numeric argument";
68 s) start_track=$OPTARG
69 if [ $start_track == 0 ]; then
70 echo "must give non-zero numeric argument";
79 #echo "$flag" $OPTIND $OPTARG
82 ########### checks ###########
83 if [ $UID -eq 0 ]; then
84 echo "DON'T run this as root! chmod the device file to yourself instead."
88 ########### directory stuff ###########
89 base_dir=`pwd | sed 's|^\(.*\)/\([^/]*\)$|\1|'`
90 trailing_dir=`pwd | sed 's|^\(.*\)/\([^/]*\)$|\2|'`
91 lossless_dir="${base_dir}/${trailing_dir} [LL]"
92 echo "base_dir = \"${base_dir}\""
93 echo "lossless_dir = \"${lossless_dir}\""
94 [ $flac == 1 ] && mkdir -p "${lossless_dir}"
96 ############# cdparanoia ###############
97 if [ ${no_cdparanoia} -eq 0 ]; then
98 if [ ${start_track} -ne 0 ]; then
99 if [ ${end_track} -ne 0 ]; then
100 span="${start_track}-${end_track}"
102 span="${start_track}-"
105 if [ ${end_track} -ne 0 ]; then
111 nice -1 cdparanoia -B -d ${cd_dev} ${span}
112 if [ $? -ne 0 ]; then
113 echo "cdparanoia failed; aborting."
118 ############# mp3 ###############
119 wav_to_mp3 $lame_bitrate $lame_q
122 ############# flac ###############
123 if [ $flac == 1 ]; then
124 mv *.wav "${lossless_dir}/"
127 flac -t *.flac && rm -f *.wav