Linux Rip Audio CD

by on June 17, 2010 · 4 comments

  1. #!/bin/bash
  2. # A simple shell script to rip audio cd and create mp3 using lame
  3. # and cdparanoia utilities.
  4. # ----------------------------------------------------------------------------
  5. # Written by Vivek Gite <http://www.cyberciti.biz/>
  6. # (c) 2006 nixCraft under GNU GPL v2.0+
  7. # ----------------------------------------------------------------------------
  8. read -p "Starting in 5 seconds ( to abort press CTRL + C ) " -t 5
  9. cdparanoia -B
  10. for i in *.wav
  11. do
  12. lame --vbr-new -b 360 "$i" "${i%%.cdda.wav}.mp3"
  13. rm -f "$i"
  14. done

How Do I Use This Script?

Download the script. Put audio cd into drive. Create directory to store mp3s, enter:
mkdir music
cd music
mkdir "Album name"
cd !!:1
/path/to/ripcd.sh

See HowTo: Linux Rip and Encode Audio CDs



4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

  • Peter Gaal

    petike-nb# abcde -a cddb,read,encode,tag,move,playlist,clean -d /dev/cdrom -o mp3 -V -x

  • Walter

    The script should read

    #!/bin/bash
    # A simple shell script to rip an audio CD and create MP3s using lame
    # and cdparanoia.
    # ----------------------------------------------------------------------------
    # Written by Vivek Gite  and WS
    # (c) 2011 nixCraft under GNU GPL v2.0+
    # ----------------------------------------------------------------------------
    read -p "Starting in 5 seconds (to abort press CTRL + C)" -t 5
    rc=0
    i=
    if ! cdparanoia -B; then
    	echo "cdparanoia ended with error, bailing out" 1>&2
    	exit 1
    fi
    for i in *.wav; do
    	if lame --vbr-new -q 0 "$i" "${i%%.cdda.wav}.mp3"; then
    		rm -f "$i"
    	else
    		echo "Could not encode $i" 1>&2
    		((rc++))
    	fi
    done
    exit $rc
    

    I corrected spelling and added error checking. The script will now abort on a ripping error and won’t delete Wave files which have not been successfully encoded.
    If any error occurs, the exit code is not 0.
    Furthermore, “–vbr-new” and “-b 360″ are contradictory options, the first telling lame to use variable bit rate and the second telling lame to use constant bit rate for encoding. I replaced the second with “-q 0″ to achieve the best possible result.
    The usage example could be simplified with

    mkdir -p "music/Album name"
    cd $?
    /path/to/ripcd.sh
    
  • Walter

    Oops, I used a wrong variable for the usage example ^^

    mkdir -p "music/Album name"
    cd !$
    /path/to/ripcd.sh
  • bas

    Hi,
    thanks!
    Very cool!
    But what about files name?
    Why i have to change handy?

Previous Script:

Next Script: