Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # rips audio from cd and encodes in mp3
- # requires these deb packages: cd-discid cddbcmd cdparanoia lame
- # created by Buzz
- cdrom=/dev/cdrom
- tmp=/tmp/cdrip
- raw=/tmp/cdrip/raw
- mp3=/tmp/cdrip/enc
- bitrate=160 # VBR would require a couple more things
- musicdir=/home/buzz/Music
- cddb() {
- cddbcmd cddb query $(cd-discid $cdrom) |nl -nln
- echo
- echo Choose a number from above cddb results to proceed.
- read n
- discid=`cddbcmd cddb query $(cd-discid $cdrom) |nl -nln |sed -n "$n{p;q}" |awk '{print $2 " " $3}'`
- echo
- echo $discid
- cddbcmd cddb read "$discid" >$tmp/cddb.info
- echo $cddbdata
- }
- encode() {
- for file in *.wav
- do
- track=`ls $file |cut -c6,7`
- trackn=`expr "$track" - 1`
- line=`grep TITLE${trackn}= $tmp/cddb.info`
- title=`echo $line |awk -F= '{print $2}'`
- outfile=`echo $track" - ""$title"" - ""$artist".mp3`
- lame --id3v2-only --tt "$title" --ta "$artist" --tl "$album" --ty \
- "$year" --tg "$genre" -h -b "$bitrate" "$file" $mp3/"$outfile"
- done
- }
- encodec() {
- album="$artist" # first part of cddb data DDITLE= is album, afaik
- for file in *.wav
- do
- track=`ls $file |cut -c6,7`
- trackn=`expr "$track" - 1`
- line=`grep TITLE${trackn}= $tmp/cddb.info |awk -F= '{print $2}'`
- titlesp=`echo $line |awk -F\- '{print $1}'` # contains trailing space
- title=`echo $titlesp |sed 's/[ \t]*$//'` # removes trailing space
- artistsp=`echo $line |awk -F\- '{print $2}'` # contains leading space
- artist=`echo $artistsp |sed 's/^[ \t]*//'` # removes leading space
- albumpath=`echo "$musicdir"/"$album"`
- outfile=`echo $track" - ""$title"" - ""$artist".mp3`
- lame --id3v2-only --tt "$title" --ta "$artist" --tl "$album" --ty \
- "$year" --tg "$genre" -h -b "$bitrate" "$file" $mp3/"$outfile"
- done
- }
- case "$1" in
- rip)
- : ;;
- clean)
- rm -fr $tmp
- exit 0
- ;;
- *)
- echo usage: `basename $0` rip"|"clean
- exit 1
- ;;
- esac
- # not sure how to make this cross-platform :(
- if [ -z $(grep AUDIO /dev/.udev/db/block\:sr0) ];then
- echo error: audio cd not present or drive not ready
- exit 1
- fi
- rm -fr $tmp
- mkdir -p $raw $mp3
- # Let's get the cddb info and proceed
- until [[ "$x" = y ]] || [[ "$x" = c ]]
- do
- cddb
- cat $tmp/cddb.info
- echo "Press y to accept, c to accept compilation or enter to look again."
- read x
- done
- # define some variables here (some will change for a compilation album)
- cd $raw
- artistalbum=`grep DTITLE $tmp/cddb.info |awk -F= '{print $2}'`
- artistmeh=`echo "$artistalbum" |awk -F/ '{print $1}'`
- artist=`echo "$artistmeh" |sed 's/[ \t]*$//'` # removes trailing space from cddb data
- albummeh=`echo "$artistalbum" |awk -F/ '{print $2}'`
- album=`echo $albummeh |sed 's/^[ \t]*//'` # removes leading space from cddb data
- year=`grep YEAR $tmp/cddb.info |awk '{print $3}'`
- albumpath=`echo "$musicdir"/"$artist"" - ""$album"`
- echo "Enter genre"
- read genre
- # rip wav files from cd
- cdparanoia -B
- # encode mp3
- if [ "$x" = c ]
- then
- encodec
- else
- encode
- fi
- # copy files into music directory
- cd $mp3
- mkdir "$albumpath"
- for file in *.mp3
- do
- cp -prv "$file" "$albumpath"/
- done
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement