Two Spotify Instances with FDSify

February 24, 2013

As part of our job as software consultants, we're often asked to DJ at uni house parties. When our services were first called upon, we were mentally prepared (we knew both current and next hype) - the problem was our rig.

The world of DJ software is traditionally a Mac and Windows one. But we enjoy to rail against proprietary technology too much (irony noted) and thus set about finding a Linux solution, not matter how inconvenient.

Lacking any good music ourselves, we wanted to mix tracks from our Spotify accounts (foxxy, eldog). We found a number of existing solutions, but none of them let us play audio from an arbitrary source.

Our custom solution (dubbed "FDSify") was to use just Spotify, with foxxy's account as the left deck and eldog's as the right. This way we'd get all of Spotify's music and features, twice.

It didn't get off to a great start: you can't have have two instances of Spotify executing at the same time. This was a bit depressing until we realised the caveat. You can only have one instance per user. So, we tried running them as different users and, bosh, we're playing Limp Bizkit and Madonna at the same time, in a utterly horrendous mix.

Next, we needed as cross-fader. To do this we needed to automate the UI, but, after an hour, we realised this would be rather difficult. Instead, we worked out that you can just fake key presses using xdo. So we whipped up a wrapper for it with Python and implemented a virtual mixer with flashy features such as cross-fade, quick-fade and mute. Finally we glued the whole thing together with a lovely bit of Bash script.

Excited? You can try this very minimal example now

$ spotify &
$ sudo spotify &

And behold the magic of a multi-user system. Checkout the code on GitHub.