Showing posts with label SqueezeCenter. Show all posts
Showing posts with label SqueezeCenter. Show all posts

Thursday, June 4, 2009

Auto rip audio CDs in Ubuntu Server

I got my headless Linux server set up to auto rip music CDs and add them to my music library. Pop a CD in the tray and it automatically rips and tags the tracks to FLAC files and ejects the CD... and queues up a task to transcode to mp3 and then rescan my Squeezecenter library later. Here's how:

* Detection of the audio CD and kicking stuff off is done by ivman.
* Ripping and tagging is done by abcde.
* Transcoding is done by flac2mp3.
* Refreshing the library is done using the Squeezecenter CLI.

It took me "a while" to get it working end to end. The tough part was getting ivman configured. But that's the essential part for automation.

Ivman

To install
$ sudo apt-get install ivman
which installs a bunch of dependencies (but no X). Then I enabled an action to start a script when ivman detects an audio CD. This is what I added to /etc/ivman/IvmConfigActions.xml:
<ivm:Match name="hal.volume.disc.type" value="cd_rom">
<ivm:Match name="hal.volume.disc.has_audio" value="true">
<ivm:Match name="hal.volume.disc.has_data" value="false">
<ivm:Option name="exec" value="/home/user_x/bin/rip_cd '$hal.block.device$'"/>
</ivm:Match>
</ivm:Match>
</ivm:Match>
The rip_cd script just invokes abcde and directs its output to a log file.

The problem that broke my heart for ages was that ivman didn't have permission to use the cdrom drive. I got this error in the log file from abcde:
cd-discid: /dev/cdrom: open: Permission denied
[ERROR] abcde: CD could not be read. Perhaps there's no CD in the drive?
No such problem running abcde directly from the command line as the same user ivman ran as, since that user is a member of the group "cdrom".

How I eventually got it working consistently was to configure ivman to run explicitly as the group "cdrom".

Ivman requires you to specify both a user and a group for the daemon to run as - in /etc/ivman/IvmConfigBase.xml). Just because the user you specify is a member of a group, e.g. cdrom, doesn't mean that ivman will run as a member of that group.

In my setup, ivman is now solely configured from /etc/ivman and runs as "user_x" and group "cdrom". And abcde is solely configured from /etc/abcde.conf.

It can help to run ivman in debug mode:
$ sudo /etc/init.d/ivman stop
$ sudo ivman -d --nofork

ABCDE

To install
$ sudo apt-get install abcde
This also installs cd-discid and probably cdparanoia (which I had installed already). Getting abcde configured is easy, especially thanks to a great guide on Andrew's Corner.

I included a post-read hook in /etc/abcde.conf to enqueue a transcoding script when the CD is ripped.
post_read ()
{
atq -q x | while read line; do job=`echo $line | sed -e 's/\([0123456789]*\).*/\1/'`; atrm $job; done
at -q x 01:00AM -f /home/user_x/bin/flac2mp3
}
It would probably be better just to run the transcoding script as a cron job rather than "on demand". But this way works too.

The flac2mp3 script invokes Robin Bowes' flac2mp3, directing its output to a log file, and then invokes the Squeezecenter CLI to rescan the music library.

Of course, abcde would happily take care of ripping to FLAC and mp3 at the same time. But I prefer to rip to FLAC and transcode from there. That way, if I need to change tags, I just update the FLACs and run flac2mp3 to update the tags in my mp3s.

Squeezecenter CLI

Squeezecenter has a telnet-based command line interface. One of the things it supports is executing a rescan of the library. So I included the scriptlet below in my transcoding script, after transcoding completes:
echo `date` "requesting squeezecenter rescan..." >> $log
(
sleep 1;
/bin/echo -e "rescan\r";
sleep 1;
/bin/echo -e "exit\r";
sleep 1;
) | telnet localhost 9090 >> $log 2>&1
echo `date` "telnet exit status: " $? >> $log
Directing the output to a file was useful here (again). It helped me diagnose a problem when the "wrong" version of echo got used when the script was run from the at task, causing the telnet to fail. The fix was to use /bin/echo explicitly.

Of course, I could just let Squeezecenter schedule a regular rescan of the music library instead of doing it on demand. But I wanted to give the CLI a try.

Anyway, that's about it.

Just a note on hardware. I'm still using the fit-PC slim as my server. It doesn't have a CD drive. I connect the internal DVD burner from my old PC through a cheapo IDE-USB adapter cable from ebay.

Wednesday, November 12, 2008

Performance of SqueezeCenter on fit-PC Slim

Here is some data on the performance of SqueezeCenter on my fit-PC Slim.

Library rescan

4004 mp3 files

* Look for new & changed music - 1:50
* Clear library and rescan everything - 18:01


3987 flac files

* Clear library and rescan everything - 13:06

Power consumption was peaked at 9 watts during rescans compared to 7 watts for normal operation.


Web interface*

Full cold load^ of the interface - 15 secs
Warm load - 5 secs

*Firefox 2
^Clear browser cache and restart browser

Thursday, November 6, 2008

SqueezeCenter on the fit-PC Slim

It's a few weeks since I installed SqueezeCenter 7.2 on my mini Linux server. I'm delighted to say that it's working out great.

Music playback on my Squeezebox player is flawless. The responsiveness of the player and web interface is just fine.

My server is the recently released fit-PC Slim (512MB RAM), which I ordered diskless and fitted with a 250GB disk. It's running a minimal server install of Ubuntu 8.04 with a few services including SqueezeCenter.

In its current configuration, my fit-PC draws just 7 watts.

I think that's pretty terrific. I expect to get the power consumption even lower whenever I get around to disabling the WIFI adapter in the BIOS.

I only have one Squeezebox, so can't comment on the ability to serve multiple clients, though I have played to the Squeezebox and my laptop simultaneously without glitches. Also, no problem streaming music while performing other background tasks, like copying on new music files and transcoding from FLAC to mp3.

I reckon the fit-PC is a really great fit for SqueezeCenter.

Monday, October 13, 2008

Installing SqueezeCenter

Running SqueezeCenter to feed the Squeezebox music player is my old server's main duty. So it's first up for installation on my new fit-PC.

Edit /etc/apt/sources.list to add
deb http://debian.slimdevices.com stable main

$ sudo apt-get update
$ sudo apt-get install squeezecenter
The web interface is not available from my laptop until I restart the box (something to do with apparmor?). On restart, I can access the web interface fine.

SqueezeCenter installs mysql (unless you have it already) and SqueezeCenter then runs its own mysql instance, in addition to the default one. I don't want two mysql instances running on my little server, so I'll disable the default one for now:
$ cd /etc/rc2.d
$ cat README
$ sudo mv S18mysql-ndb K82mysql-ndb
$ sudo mv S19mysql K81mysql
$ sudo mv S17mysql-ndb-mgm K83mysql-ndb-mgm
Alternative would be to get squeezecenter to use the default mysql instance instead, and disable the dedicated squeezecenter one. Supposed to be possible. I'll try that whenever I end up with some other application which needs mysql.