Automatic CD Ripping With abcde

This tutorial describes how to automate the process of ripping CDs in Ubuntu. While it’s possible to rip CDs with a nice GUI tool, what I want is a completely automated process where all I have to do is put the CD in, then remove it once it’s ripped. I also want to rip to multiple formats simultaneously, specifically FLAC and MP3. The tool I use to do this is called abcde. This is a little known command line program that does everything I want and more. It’s easy to use and produces excellent rips.

To get started, let’s install abcde and its dependencies with the following command:

[sourcecode language=”bash”]
sudo apt-get install abcde flac lame id3v2 vorbis-tools mppenc faac cdparanoia cd-discid
[/sourcecode]

This is everything that’s needed to rip to any of the formats supported by abcde, that is, FLAC, MP3, Ogg Vorbis, and Musepack. Here’s what we’re installing:

  • abcde – command line program for ripping CDs
  • flac – encoder for FLAC files
  • lame – encoder for MP3 files
  • id3v2 – allows adding tags to MP3 files
  • vorbis-tools – encoder for Ogg Vorbis files
  • mppenc – encoder for Musepack files
  • cdparanoia – rips CDs with error detection and correction
  • cd-discid – gets CD information from an online CD database (FreeDB)

Once everything is installed, all you have to do is create a configuration file telling abcde what to do when a CD is inserted. This file is named .abcde.conf (it’s a hidden file, so it starts with a period) and should be placed in your home folder. Here’s a very basic configuration file that will rip MP3s to your Music folder:
[sourcecode language=”bash”]
OUTPUTTYPE="mp3"

OUTPUTDIR="$HOME/Music/"
OUTPUTFORMAT=’${ARTISTFILE}/${ALBUMFILE}/${TRACKNUM} – ${TRACKFILE}’
VAOUTPUTFORMAT=’Various/${ALBUMFILE}/${TRACKNUM} – ${ARTISTFILE} – ${TRACKFILE}’

PADTRACKS=y
EJECTCD=y
[/sourcecode]
The first line specifies that I want to rip MP3 files. Lines 3-5 specify where I’m ripping to and the format of the folder and file names, for both normal albums and various albums (albums with multiple artists). Line 7 says that I want to use two digit track numbers (i.e. 01, 02, etc) and line 8 says that I want the CD to be ejected when the rip is complete.

Unfortunately, this basic version of the configuration file does some things I don’t like. It encodes the MP3s with low quality settings, it replaces blanks with underscores in artist, album and song file names, and it doesn’t take advantage of my multi-core CPU. To fix the MP3 quality we can use the LAMEOPTS setting, to fix the file names we can specify a mungefilename() function, and to use multiple processes we can use the MAXPROCS setting. Here’s what the file looks like after these additions:

[sourcecode language=”bash”]
OUTPUTTYPE="mp3"
LAMEOPTS=’-V 0′

OUTPUTDIR="$HOME/Music/"
OUTPUTFORMAT=’${ARTISTFILE}/${ALBUMFILE}/${TRACKNUM} – ${TRACKFILE}’
VAOUTPUTFORMAT=’Various/${ALBUMFILE}/${TRACKNUM} – ${ARTISTFILE} – ${TRACKFILE}’

PADTRACKS=y
EJECTCD=y
MAXPROCS=4

mungefilename ()
{
echo "$@" | sed s,:,\ -,g | tr / _ | tr -d \’\"\?\[:cntrl:\]
}
[/sourcecode]

This will produce the highest quality MP3s, leave blanks in the file names, and use up to 4 processes (I have a quad core CPU) to do the ripping and encoding. If you want standard quality MP3s just replace the -V 0 with -V 2. If you have a dual core CPU then use MAXPROCS=2.

The above settings are probably what most people will use, but if you’re like me and you also want to rip FLAC files at the same time, and you want the FLAC files to go into a different folder than the MP3 files, then you would want to use something like this:

[sourcecode language=”bash”]
OUTPUTTYPE="mp3,flac"
LAMEOPTS=’-V 0′
FLACOPTS=’–verify –best’

OUTPUTDIR="$HOME/Music/"
OUTPUTFORMAT=’${OUTPUT}/${ARTISTFILE}/${ALBUMFILE}/${TRACKNUM} – ${TRACKFILE}’
VAOUTPUTFORMAT=’${OUTPUT}/Various/${ALBUMFILE}/${TRACKNUM} – ${ARTISTFILE} – ${TRACKFILE}’

PADTRACKS=y
EJECTCD=y
MAXPROCS=4

mungefilename ()
{
echo "$@" | sed s,:,\ -,g | tr / _ | tr -d \’\"\?\[:cntrl:\]
}
[/sourcecode]

Notice that I’ve added flac to the OUTPUTTYPE setting, added a FLACOPTS setting, and used the ${OUTPUT} macro in the path names to create top level flac and mp3 folders. And if you really want to get crazy, and rip all four formats at once, you would change the first three lines to this:

[sourcecode language=”bash”]
OUTPUTTYPE="mp3,flac,ogg,mpc"
LAMEOPTS=’-V 0′
FLACOPTS=’–verify –best’
OGGENCOPTS=’-q 8′
MPPENCOPTS=’–extreme’
[/sourcecode]

Regardless of how you set up the configuration file, once it’s in place, all you have to do is tell Ubuntu to start abcde when an audio CD is inserted. To do this:

  • start up Nautilus by selecting the Places >> Home Folder menu item,
  • select the Edit >> Preferences menu item,
  • go to the Media tab,
  • click on the CD Audio drop down list and select Open with other Application…,
  • click on Use a custom command near the bottom of the Add Application window,
  • enter the following command and press the Add button:gnome-terminal –command “abcde -N”
  • press the Close button in the File Management Preferences window,
  • close Nautilus.

That’s it. Now when you insert a CD, a terminal window will open and abcde will start within that terminal window. When the ripping is complete the terminal window will close and the CD will be ejected. All you have to do is keep inserting CDs, and soon your entire collection will be ripped.

One thought on “Automatic CD Ripping With abcde

  1. FLACOPTS=’–verify –best’

    should be

    FLACOPTS=’–verify –best’

    further I like the program very much 😉

    regards Jeroen Ruijter