I spent some of Friday night hacking on rewriting my music queuing webapp from Catalyst (which I wrote it in ages ago, before I discovered Dancer).
It only took a couple of hours of easy and actually fairly enjoyable coding to get it all ported over, and in the process I released two Dancer plugins – Dancer::Plugin::MPD to handle easily getting a working MPD connection, and Dancer::Plugin::DebugDump to easily dump objects and data structures to the debug log to simplify development.
This time round, the code is up on GitHub – DancerJukebox on GitHub. I never released the previous code, it was developed in a private Subversion repository, and I was never happy enough with it to release it.
The basic idea is that you fill the playlist with decent music and leave MPD playing on random. If people want to hear specific songs, they can use the web app to search for whatever they want and add them to a queue.
A separate process watches MPD’s playback, and when it’s almost at the end of a song, if there’s any requests waiting, it picks one at random and plays it. In the old version, this was a separate script which needed to be started individually, but now, the Dancer app simply forks off a new process to run that code.
Writing this in Dancer, using the plugin I wrote, meant things could be as simple as, e.g.:
get '/control/skip' => sub { mpd->next; redirect '/'; };
get '/control/play/:id' => sub { mpd->play(params->{id}); redirect '/'; };
That’s what I call clean and easy :)
I also added a very basic “admin” section to be used from my Android phone, allowing me to skip the playing song and remove requests from the queue in case anyone requests anything silly that I don’t want played, but didn’t actually use it. It only took a couple of minutes to add that feature, though!
The new DancerJukebox already proved itself at a party on Saturday, and will probably see use at New Year’s Eve too.
I’ve just remembered that now I just need to try to remember where I found the turntable image I used as a page background – I didn’t bother asking for approval since it was something only used in my home and not realised, but now I’m releasing the code I ought to find out, and replace it with something offered under a CC licence if the owner objects to its use in this way.
I’ll probably write a little more about the two plugins in a separate post (even though they are rather simple), as I need to get blogging more again!