Using Mopidy with Spotify and ncmpcpp

Theo B.
Theo B.
May 28, 2017 · 3 min read

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:

Install Mopidy

The first step is to install Mopidy, this is pretty straight forward:

  1. Add the Archive GPG Key: wget -q -O — | sudo apt-key add -
  2. Add the APT repo: sudo wget -q -O /etc/apt/sources.list.d/mopidy.list
  3. Update and Install: sudo apt-get update;sudo apt-get install mopidy mopidy-spotify

Configure Mopidy

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)

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 nc.

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 nohup.out .

Configure ncmpcpp

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~/.ncmpcpp/config .

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.

Setup mpd.fifo

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:

  1. mkfifo /tmp/mpd.fifo
  2. while :; do; yes $’\n’ | nc -lu 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.

You’re done!

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 5555 > /tmp/mpd.fifo; done &;ncmpcpp . Enjoy!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store