08-27-2019, 02:51 PM
(This post was last modified: 08-27-2019, 08:53 PM by aknaggbaugh.)
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
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
4. Create the directory /home/pi/bin and add the following into abcde-rip.sh in that directory:
The script should be made executable by running:
chmod 755 abcde-rip.sh
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:
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.
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
Code:
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"
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
Code:
[Unit]
Description=AutoRip CD on insertion
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/home/pi/bin/abcde-rip.sh
ExecStop=killall abcde-rip.sh
4. Create the directory /home/pi/bin and add the following into abcde-rip.sh in that directory:
Code:
#!/bin/bash
LOGFILE=/var/log/cdrip.log
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
rc=$?
mpc update USB/cdrips 2>&1 >> $LOGFILE
if [[ $rc != 0 ]] ; then
eject
exit $rc
fi
) 200>/var/lock/.audio-cd-rip.lock
chmod 755 abcde-rip.sh
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:
Code:
# Personal preference, this works well for me
CDDBMETHOD=musicbrainz
CDDBPROTO=6
# Personal preference
PADTRACKS=y
# 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.
INTERACTIVE=n
# This line is important, it applies full paranoia to produce clean rips
CDPARANOIAOPTS=-z
# Personal preference but you need at least cddb,read,encode,tag,move,clean
ACTIONS=cddb,read,encode,tag,getalbumart,embedalbumart,cue,move,clean
OUTPUTDIR=/media/cdrips
# Personal preference, note if you choose a different format you may need to apt-install support for that format
OUTPUTTYPE=flac
# Personal preference
OUTPUTFORMAT='${ARTISTFILE}/${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
# Personal preference
VAOUTPUTFORMAT='Various/${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
# 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.
MAXPROCS=2
# Personal preference, I like the tray to eject on completion, you may prefer to press the button
EJECTCD=y
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.