Thank you for your donation!

Cloudsmith graciously provides open-source package management and distribution for our project.

[HOWTO] Automated CD ripping, tagging and adding to collection
I remember this was requested as a feature some time ago but was not considered of wide enough interest because mostly you might want to rip CDs on a separate computer. Well I built my Moode player into a 3U 19" case with the  Raspberry Pi 7" touchscreen and wanted an audio source that was pretty independent of needing another computer, so I added a CD-ROM drive and set about integrating it.

The idea is to be as simple as possible: without user interaction, on inserting an audio CD, rip it, tag it, add cover art, move to a sensible place on my Moode player USB storage and add to the mpd collection so it's immediately available to play from Moode's UI.

For anyone else who may find this useful, here's what I did:

1. Research the optical drive, some get better results with CDParanoia than others. I went for a well regarded LiteOn unit.

2. Add a udev rule:

Put the following in /etc/udev/rules.d/99-srX_change.rules
KERNEL=="sr[0-9]", ACTION=="change", ENV{ID_CDROM_MEDIA}=="1", ENV{ID_CDROM_MEDIA_TRACK_COUNT_AUDIO}=="[0-9]|[0-9][0-9]", RUN+="/bin/systemctl start cd-rip.service"
This will trigger on any optical disk containing 1-99 audio tracks (this is the number permitted by the Red Book standard), any other disk will be ignored.

3. Add the systemd service. We will use a oneshot service that can be called but doesn't persist. This is needed because tasks called directly from udev that take longer than 60s get timed out.

Put the following in /etc/systemd/system/cd-rip.service

Description=AutoRip CD on insertion


4. Create the directory /home/pi/bin and add the following into in that directory:



echo "$(date)" >> $LOGFILE


 # Wait for lock on /var/lock/.audio-cd-rip.lock (fd 200) for two hours

       flock -x -w 7200 200 || exit 1

       abcde 2>&1 >> $LOGFILE


       mpc update USB/cdrips 2>&1 >> $LOGFILE

       if [[ $rc != 0 ]] ; then


               exit $rc


) 200>/var/lock/.audio-cd-rip.lock
The script should be made executable by running:

chmod 755

5. You need to install some stuff:

sudo apt-get update
sudo apt install abcde flac mkcue eject

(The items you need to install may vary depending on what format you want to rip to: I'm ripping to flac.)

6. Edit /etc/abcde.conf. You only need to uncomment lines if you want to change the default. My config file is shown below and it will definitely get you going, but you may wish to tweak to taste:

# Personal preference, this works well for me

# Personal preference
# This line is important, it allows abcde to run without interaction. This does take away some control
# from stuff like choosing tagging options but the result is good enough and if necessary a rip can
# be cleaned up afterwards with a better tool like picard.

# This line is important, it applies full paranoia to produce clean rips

# Personal preference but you need at least cddb,read,encode,tag,move,clean

# Personal preference, note if you choose a different format you may need to apt-install support for that format

# Personal preference

# Personal preference

# Limiting to 2 procs till produces acceptable ripping and encoding speed and doesn't load the proc that may be running mpd at the same time.

# Personal preference, I like the tray to eject on completion, you may prefer to press the button

Ensure the directory /media/cdrips exists. On my system it is a symlink to one of my USB storage devices. You can point the OUTPUTDIR somewhere else in abcde.conf but the advantage of doing it this way is that the ripping script calls mpc update on this specific location on completion so that the moode collection is automatically updated. As soon as the disk is ejected you should be able to browse to the newly ripped CD in your collection.

Very clean description, but shouldn't that be "/etc/udev/rules.d/..." and not /etc/udev/udev.d/..."? Also, the script /home/pi/bin/ needs to be marked "executable".

I ultimately chose to keep ripping on a desktop system with interactive control over naming, tagging, and adding coverart but abcde worked fine for me on an RPi running moOde. Your HowTo should be attractive to those who want to keep everything in one system.

For  my tests of abcde in moOde I bought an inexpensive LG GP65NB60 Slim Portable DVD Writer. It worked fine on the RPi4B I was using.

Yes, you're quite right about rules.d - I'll edit the main post so as not to confuse. The nice thing about handling ripping through udev is that if there is no CD player in the system or while it's not being used there's no overhead, although abcde does pull in a fair amount of dependencies.
Thanks for that!  I'm here to report that your instructions were clear enough for a linux newbie to follow with success.

A did add a few minor tweaks on abcde.conf:
- 'musicbrainz' wasn't assigned the correct genres for my music. So I added all the sources. Updated line: CDDBMETHOD=musicbrainz,cddb,cdtext
- For some strange reasons yet to be diagnosed, the album art wasn't showing in moOde. So I removed the 'embedalbumart' and the art is now added as a separate jpg file that moOde displays. Updated line: ACTIONS=cddb,read,encode,tag,getalbumart,cue,move,clean

I added this to the end of /etc/samba/smb.conf so I could manage my music collection from my desktop computer:
comment = USB Storage
path = /media
read only = No
guest ok = Yes

To make the directory for the ripped CDs writable, I did "sudo chmod 775 /media/cdrips" (Originally it was readable, but not writable)
This works really well on a Pi, I did have one problem with my Asus USB drive in that it was underpowered on a Pi 4, a powered hub sorted that out if anyone else is having similar problems.

Forum Jump: