Using Mopidy with Spotify and ncmpcpp
Around 2 days ago I discovered Mopidy, an MPD “clone” that adds support for Spotify, Soundcloud, and other services. The first thing I thought was: “Hey! I can use ncmpcpp again!”. It turned out only one other person has an article on this, and it’s for Mac. So for all you Linux users, here you go:
The first step is to install Mopidy, this is pretty straight forward:
- Add the Archive GPG Key:
wget -q -O — https://apt.mopidy.com/mopidy.gpg | sudo apt-key add -
- Add the APT repo:
sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/jessie.list
- Update and Install:
sudo apt-get update;sudo apt-get install mopidy mopidy-spotify
NOTE: If you are planning to run Mopidy as a service, configure it in
/etc/mopidy/mopidy.conf, if you are planning to run it under a user, use
~/.config/mopidy/mopidy.conf . The config is the same in either place.
If all you want is Spotify, you’ll need to copy and paste this into your config file: (P.S: If you plan to use other services, Mopidy has documentation here)
output = tee name=t ! queue ! autoaudiosink t. ! queue ! udpsink port=5555
enabled = true
username = [username] # Please note you need Spotify Premium!
password = [password]
bitrate = 320
In a nutshell, the
output = tee name=t ! queue ! autoaudiosink t. ! queue ! udpsink port=5555 line is telling GStreamer to feed the music into your normal audio sink (speakers), as well as spit the raw audio stream out on UDP port 5555. This will allow us to catch it later using
All you’re going to do now is either start Mopidy as a service using
service mopidy start or start it under a user account by doing
nohup mopidy & which will fork it into the background and put the logs under
As I presume you reading this article means you already know how to use ncmpcpp, I am not going to explain how to use it, but here is a getting started guide. All we are going to do here is add the visualization config to ncmpcpp. You’re going to want to add this block to
visualizer_fifo_path = "/tmp/mpd.fifo"
visualizer_output_name = "my_fifo"
visualizer_sync_interval = "30"
visualizer_in_stereo = "yes"
visualizer_type = "spectrum"
visualizer_look = "+|"
This block just enables the visualizer in ncmpcpp and tells it where to look to find the audio data. This file will be come populated in the next step.
This is the final step! You are almost there. This final step is to finish off enabling visualization, if you don’t care for visualization, you are done, and can launch ncmpcpp. Now, to finish visualization:
while :; do; yes $’\n’ | nc -lu 127.0.0.1 5555 > /tmp/mpd.fifo; done &
The first command creates a FIFO file in
/tmp/mpd.fifo. This will be the pipe between netcat and ncmpcpp.
The second command tells netcat to listen to UDP port 5555, and pass all data into
/tmp/mpd.fifo . These 2 commands will have to be re-run every time you reboot or whenever your
/tmp directory gets cleared.
NOTE: I did not write the second command, it was pulled from user s-ol’s comment on this GitHub issue.
All you need to do now is run
ncmpcpp and everything will work as normal! When you reboot, here’s a one-line to start everything:
nohup mopidy &;mkfifo /tmp/mpd.fifo;while :; do yes $’\n’ | nc -lu 127.0.0.1 5555 > /tmp/mpd.fifo; done &;ncmpcpp . Enjoy!