Advertisement
Guest User

Buzz

a guest
Jan 14th, 2010
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.25 KB | None | 0 0
  1. #!/bin/bash
  2. # rips audio from cd and encodes in mp3
  3. # requires these deb packages: cd-discid cddbcmd cdparanoia lame
  4. # created by Buzz
  5.  
  6. cdrom=/dev/cdrom
  7. tmp=/tmp/cdrip
  8. raw=/tmp/cdrip/raw
  9. mp3=/tmp/cdrip/enc
  10. bitrate=160            # VBR would require a couple more things
  11. musicdir=/home/buzz/Music
  12.  
  13. cddb() {
  14.    cddbcmd cddb query $(cd-discid $cdrom) |nl -nln
  15.    echo
  16.    echo Choose a number from above cddb results to proceed.
  17.    read n
  18.    discid=`cddbcmd cddb query $(cd-discid $cdrom) |nl -nln |sed -n "$n{p;q}" |awk '{print $2 " " $3}'`
  19.    echo
  20.    echo $discid
  21.    cddbcmd cddb read "$discid" >$tmp/cddb.info
  22.    echo $cddbdata
  23. }
  24.  
  25. encode() {
  26.    for file in *.wav
  27.    do
  28.       track=`ls $file |cut -c6,7`
  29.       trackn=`expr "$track" - 1`
  30.       line=`grep TITLE${trackn}= $tmp/cddb.info`
  31.       title=`echo $line |awk -F= '{print $2}'`
  32.       outfile=`echo $track" - ""$title"" - ""$artist".mp3`
  33.       lame --id3v2-only --tt "$title" --ta "$artist" --tl "$album" --ty \
  34.            "$year" --tg "$genre" -h -b "$bitrate" "$file" $mp3/"$outfile"
  35.    done
  36. }
  37.  
  38. encodec() {
  39.    album="$artist"   # first part of cddb data DDITLE=  is album, afaik
  40.    for file in *.wav
  41.    do
  42.       track=`ls $file |cut -c6,7`
  43.       trackn=`expr "$track" - 1`
  44.       line=`grep TITLE${trackn}= $tmp/cddb.info |awk -F= '{print $2}'`
  45.       titlesp=`echo $line |awk -F\- '{print $1}'`    # contains trailing space
  46.       title=`echo $titlesp |sed 's/[ \t]*$//'`       # removes trailing space
  47.       artistsp=`echo $line |awk -F\- '{print $2}'`   # contains leading space
  48.       artist=`echo $artistsp |sed 's/^[ \t]*//'`     # removes leading space
  49.       albumpath=`echo "$musicdir"/"$album"`
  50.       outfile=`echo $track" - ""$title"" - ""$artist".mp3`
  51.       lame --id3v2-only --tt "$title" --ta "$artist" --tl "$album" --ty \
  52.            "$year" --tg "$genre" -h -b "$bitrate" "$file" $mp3/"$outfile"
  53.    done
  54. }
  55.  
  56. case "$1" in
  57.    rip)
  58.      : ;;
  59.    clean)
  60.      rm -fr $tmp
  61.      exit 0
  62.      ;;
  63.    *)
  64.      echo usage: `basename $0` rip"|"clean
  65.      exit 1
  66.      ;;
  67. esac
  68.  
  69. # not sure how to make this cross-platform :(
  70. if [ -z $(grep AUDIO /dev/.udev/db/block\:sr0) ];then
  71.    echo error: audio cd not present or drive not ready
  72.    exit 1
  73. fi
  74.  
  75. rm -fr $tmp
  76. mkdir -p $raw $mp3
  77.  
  78. # Let's get the cddb info and proceed
  79. until [[ "$x" = y ]] || [[ "$x" = c ]]
  80. do
  81.    cddb
  82.    cat $tmp/cddb.info
  83.    echo "Press y to accept, c to accept compilation or enter to look again."
  84.    read x
  85. done
  86.  
  87. # define some variables here (some will change for a compilation album)
  88. cd $raw
  89. artistalbum=`grep DTITLE $tmp/cddb.info |awk -F= '{print $2}'`
  90. artistmeh=`echo "$artistalbum" |awk -F/ '{print $1}'`
  91. artist=`echo "$artistmeh" |sed 's/[ \t]*$//'` # removes trailing space from cddb data
  92. albummeh=`echo "$artistalbum" |awk -F/ '{print $2}'`
  93. album=`echo $albummeh |sed 's/^[ \t]*//'`     # removes leading space from cddb data
  94. year=`grep YEAR $tmp/cddb.info |awk '{print $3}'`
  95. albumpath=`echo "$musicdir"/"$artist"" - ""$album"`
  96. echo "Enter genre"
  97. read genre
  98.  
  99. # rip wav files from cd
  100. cdparanoia -B
  101.  
  102. # encode mp3
  103. if [ "$x" = c ]
  104. then
  105.    encodec
  106. else
  107.    encode
  108. fi
  109.  
  110. # copy files into music directory
  111. cd $mp3
  112. mkdir "$albumpath"
  113. for file in *.mp3
  114. do
  115.    cp -prv "$file" "$albumpath"/
  116. done
  117. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement