home of the madduck/ blog/
Discovering MPD

I have a server with libapache2-mod-musicindex serving several hundreds of gigabytes. I also have a headless router at home with a soundcard. My desire was to figure out how to make the router stream music from that server before I went to sleep.

Just short of coming up with a quick'n'ugly hack, Decklin Foster saved my day by pointing me to mpd. It runs as a daemon and accepts network commands. It wasn't until I found out that you can pipe the playlists served by libapache2-mod-musicindex to mpc add that I completely fell in love.

Now I hacked together a script, playstream, which I can integrate with mailcap:

$ cat <<_eof >> ~/.mailcap
audio/mpegurl;     ~/bin/playstream -q '%s'; nametemplate=%s.m3u
audio/x-mpegurl;   ~/bin/playstream -q '%s'; nametemplate=%s.m3u
audio/x-scpls;     ~/bin/playstream -q '%s'; nametemplate=%s.pls

The -q option queues the playlist up next. Other options I've added are -a for append (the default), and -r for replace.

I know I should have this in version control, but that's all under construction right now. I have asked the mpc maintainer to include it.

Update: Firefox is once again really annoying. I appreciate the fact that it tries to honour the mailcap standard. However, if I say that the handler if playstream -q %s, I really mean that, including the -q; Firefox apparently just reads the first word and appends the downloaded file. Argh.