Hi again, Merry Christmas and happy new year to all 🙂
One of my favourite new products in recent months is Google Music, a new cloud-based music system which allows you to keep up to 20,000 tracks on Google’s servers. In a similar fashion to Apple’s iCloud, this music can then be accessed at any time via your Android devices or a web browser. Having used Google Music for nearly 2 months now, I absolutely love it – so much so that I’ve cancelled my Spotify subscription.
Around a year ago the media hard drive in my home server crashed, causing me to lose almost all of my digital music collection. Recently I’ve been starting to re-import my CDs so they can be uploaded to Google Music, going via my laptop. Problem is that the CD importing is happening via iTunes, and my 5-and-a-half-year-old macbook certainly isn’t as fast as it used to be – the spinning beach ball of doom regularly pops up. So why not let my home server take the strain? Pop in a CD, let the server automatically rip it and eject when it’s done, and have that new music automatically uploaded to Google. That’s entirely possible on a headless Debian server.
My starting point was a blog post which deals with ripping CDs on a headless server using ivman to listen for an audio CD being inserted and abcde for ripping. However, I later discovered that ivman has effectively been abandoned and has since been replaced by halevt.
In order to encode into MP3 format, you’ll need the LAME library which is in Debian Squeeze’s Backports library. Add the following line to /etc/apt/sources.list:
deb http://backports.debian.org/debian-backports squeeze-backports main
Once that’s done, you’ll need to update the aptitude library and install halevt, abcde and lame.
# aptitude update # aptitude install halevt abcde lame
There will be a number of dependencies that will also need to be installed, but aptitude will handle this automatically.
Detecting with halevt
Halevt will be used to listen for when a CD will be inserted. When an audio CD is detected it will execute abcde with the parameters we’ll configure later. At the bottom of /etc/halevt/halevt.xml before the final closing tag, add this:
<halevt:Device match="hal.volume.disc.has_audio = true"> <halevt:Insertion exec="abcde >> /home/<username>/path/to/logfile.log"> </halevt:Device>
This listens for an audio CD on any device, and when that CD is inserted calls abcde and logs the output to a log file in my home area.
One gotcha you will need to deal with at this point is permissions. The halevt daemon normally runs as its own user and group, which is fine in most circumstances. However, since halevt will be running another program which will need write access to my music directory and read access to the CD ROM drive, this will cause permission errors. To get around this I changed the user and group which halevt runs as by editing /etc/default/halevt, replacing <username> with the username of your linux account:
# Default settings for halevt initscript # Set this to yes if you want the halevt init-script to start a system-wide daemon START_DAEMON=yes # Run halevt has user/group HALEVT_USER=<username> HALEVT_GROUP=cdrom
Once changed, restart halevt to bring the changes into effect.
# /etc/init.d/halevt restart
Ripping with abcde
The next step is to configure abcde to rip the CD and place the MP3 files in the music folder. Unfortunately I found that abcde didn’t like the -N (no prompts) flag from a script or from halevt directly, so I had to configure everything I needed from the abcde config file. These are the values I changed in /etc/abcde.conf, but take time to look through the file yourself and edit it to your own needs:
# If NOSUBMIT is set to y, then abcde will never prompt asking if you # wish to submit your edited cddb file. NOSUBMIT=y # Keep the wav files after encoding. Set it to "y" and remove "clean" from # the list of default actions, since we purge the temp directory as default. KEEPWAVS=n # Track padding: force abcde to pad tracks using 0, so every song uses a two # digit entry. If set to "y", even a single song encoding outputs a file like # 01.my_song.ext PADTRACKS=y # Define if you want abcde to be non-interactive. # Keep in mind that there is no way to deactivate it right now in the command # line, so setting this option makes abcde to be always non-interactive. INTERACTIVE=n # If you'd like to make a default location that overrides the current # directory for putting mp3's, uncomment this. OUTPUTDIR=/home/<username>/music/ # Or if you'd just like to put the temporary .wav files somewhere else # you can specify that here WAVOUTPUTDIR=/tmp # OUTPUTTYPE can be either "ogg", "mp3", "flac" or "spx", or a combination # of them separated with ",": "ogg,mp3". OUTPUTTYPE=mp3 # Enables nogap encoding when using the 'lame' encoder. NOGAP=y # If you'd like to have abcde eject the cdrom after all the tracks have been # read, uncomment the following line. EJECTCD=y
The most important flags in this list are INTERACTIVE=n, which disables any prompts, and EJECTCD=y which automatically ejects the CD on completion. Everything else is up to you.
I tested this out with two albums last night, and I’m pleased to say this method worked perfectly and the MP3 files turned up in the expected place. If you’re having any issues or if something’s changed since I wrote this piece then please leave a comment and I’ll update the article when I can.
Syncing with Google Music
The next stage for me now is to sync with Google Music, for which I’ll be using this guide as a base. I’ll update this article with my findings once I have it up and running.