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
35 -N: don't run cdparanoia
43 while getopts "d:e:hNs:" flag
49 if [ $end_track == 0 ]; then
50 echo "must give non-zero numeric argument";
59 s) start_track=$OPTARG
60 if [ $start_track == 0 ]; then
61 echo "must give non-zero numeric argument";
70 #echo "$flag" $OPTIND $OPTARG
73 ########### checks ###########
74 if [ $UID -eq 0 ]; then
75 echo "DON'T run this as root! chmod the device file to yourself instead."
79 ########### directory stuff ###########
80 base_dir=`pwd | sed 's|^\(.*\)/\([^/]*\)$|\1|'`
81 trailing_dir=`pwd | sed 's|^\(.*\)/\([^/]*\)$|\2|'`
82 lossless_dir="${base_dir}/${trailing_dir} [LL]"
83 echo "base_dir = \"${base_dir}\""
84 echo "lossless_dir = \"${lossless_dir}\""
85 mkdir -p "${lossless_dir}"
87 ############# cdparanoia ###############
88 if [ ${no_cdparanoia} -eq 0 ]; then
89 if [ ${start_track} -ne 0 ]; then
90 if [ ${end_track} -ne 0 ]; then
91 span="${start_track}-${end_track}"
93 span="${start_track}-"
96 if [ ${end_track} -ne 0 ]; then
102 nice -1 cdparanoia -B -d ${cd_dev} ${span}
103 if [ $? -ne 0 ]; then
104 echo "cdparanoia failed; aborting."
109 ############# mp3 ###############
112 ############# flac ###############
113 mv *.wav "${lossless_dir}/"
116 flac -t *.flac && rm -f *.wav