Ever thought it would be great to stream your favorite spotify playlists to your stereo? Now you can with help of raspi and mopidy, a richer MPD alternative. Spotify Premium account is required to use mopidy, but you can try 30 day trial before subscribing.

For starters:

sudo apt-get update sudo apt-get dist-upgrade 1 2 sudo apt - get update sudo apt - get dist - upgrade

and then:

wget -q -O - http://apt.mopidy.com/mopidy.gpg | sudo apt-key add - sudo wget -q -O /etc/apt/sources.list.d/mopidy.list http://apt.mopidy.com/mopidy.list sudo apt-get update sudo apt-get install mopidy 1 2 3 4 wget - q - O - http : / / apt .mopidy .com / mopidy .gpg | sudo apt - key add - sudo wget - q - O / etc / apt / sources .list .d / mopidy .list http : / / apt .mopidy .com / mopidy .list sudo apt - get update sudo apt - get install mopidy

Above commands will add new source to your apt-get to install mopidy from.

By default, config is stored per user, edit it with: sudo nano ~/.config/mopidy/mopidy.conf . Find below explanation for distinct sections of config file:

Logging

Standard configuration will do just fine, if you know what you are doing adjust to suit your needs.

[logging] console_format = %(levelname)-8s %(message)s debug_format = %(levelname)-8s %(asctime)s [%(process)d:%(threadName)s] %(name)s

%(message)s debug_file = mopidy.log config_file = 1 2 3 4 5 [logging] console_format = %(levelname)-8s %(message)s debug_format = %(levelname)-8s %(asctime)s [%(process)d:%(threadName)s] %(name)s

%(message)s debug_file = mopidy.log config_file =

Loglevels

Logging level of python modules.

[loglevels] cherrypy = warning pykka = info 1 2 3 [loglevels] cherrypy = warning pykka = info

Audio

Audio output, for more options read mopidy documentation, for most appliances default alsa sink will work.

[audio] output = alsasink 1 2 [audio] output = alsasink

Proxy

Provide hostname and credentials if you use one.

[proxy] hostname = username = password = 1 2 3 4 [proxy] hostname = username = password =

Spotify

Provide your spotify username and password to log on. You can choose bitrate from 160 up to 320, raspberry won’t break a sweat streaming 320 so I recommend this one (if you are not limited by internet connection). As I mentioned before, you need a Premium account to stream to devices other than PC client and that includes raspi.

[spotify] enabled = true username = #spotify_username# password = #spotify_password# bitrate = 320 timeout = 10 cache_dir = $XDG_CACHE_DIR/mopidy/spotify 1 2 3 4 5 6 7 [spotify] enabled = true username = #spotify_username# password = #spotify_password# bitrate = 320 timeout = 10 cache_dir = $XDG_CACHE_DIR/mopidy/spotify

MPD

To use MPD clients to control mopidy enable mpd plugin. Hostname have to be set to 0.0.0.0 to control mopidy from hosts other than localhost.

[mpd] enabled = true hostname = 0.0.0.0 port = 6600 password = max_connections = 20 connection_timeout = 60 1 2 3 4 5 6 7 [mpd] enabled = true hostname = 0.0.0.0 port = 6600 password = max_connections = 20 connection_timeout = 60

http

A http interface to control mopidy from browser. To enable it set enabled to true and remember to change 127.0.0.1 to 0.0.0.0 to access from your network.

[http] enabled = false hostname = 0.0.0.0 port = 6680 static_dir = 1 2 3 4 5 [http] enabled = false hostname = 0.0.0.0 port = 6680 static_dir =

Stream internet broadcasts

Enable or disable streaming through specific protocols.

[stream] enabled = true protocols = http https mms rtmp rtmps rtsp 1 2 3 4 5 6 7 8 9 [stream] enabled = true protocols = http https mms rtmp rtmps rtsp

Last.fm scrobbler

Provide your last.fm login and scrobble what you are listening to last.fm.

[scrobbler] enabled = false username = # Must be set. password = # Must be set. 1 2 3 4 [scrobbler] enabled = false username = # Must be set. password = # Must be set.

Media Player Remote Interfacing Specification (MPRIS)

Interface that lets you control mopidy through e.g. Ubuntu Sound Menu.

[mpris] enabled = false 1 2 [mpris] enabled = false

Local music collection

Of course, of what use will mopidy be if it weren’t for playing local music?

[local] enabled = true media_dir = /media/wd/muzyka/ playlists_dir = $XDG_DATA_DIR/mopidy/local/playlists tag_cache_file = $XDG_DATA_DIR/mopidy/local/tag_cache 1 2 3 4 5 [local] enabled = true media_dir = /media/wd/muzyka/ playlists_dir = $XDG_DATA_DIR/mopidy/local/playlists tag_cache_file = $XDG_DATA_DIR/mopidy/local/tag_cache

Test your setup by typing mopidy . You can now connect to mopidy and test all its features, just don’t close putty window and don’t stop mopidy. To run mopidy at boot create startup script: sudo nano /etc/init.d/mopidy

#!/bin/bash # mopidy daemon # chkconfig: 345 20 80 # description: mopidy daemon # processname: mopidy ### BEGIN INIT INFO # Provides: mopidy deamon # Required-Start: $remote_fs $syslog $network # Required-Stop: $remote_fs $syslog $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start mopidy daemon at boot time # Description: Enable mopidy music server ### END INIT INFO DAEMON_PATH="/usr/bin/" DAEMON=mopidy DAEMONOPTS="" NAME=mopidy DESC="My mopidy init script" PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME case "$1" in start) echo "Starting Mopidy Daemon" start-stop-daemon --start --chuid pi --background --exec /usr/bin/mopidy \ --pidfile $PIDFILE --make-pidfile \ -- 2>/var/log/mopidy.log ;; stop) echo "Stopping Mopidy Daemon" start-stop-daemon --stop --exec /usr/bin/mopidy --pidfile $PIDFILE ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 esac 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #!/bin/bash # mopidy daemon # chkconfig: 345 20 80 # description: mopidy daemon # processname: mopidy ### BEGIN INIT INFO # Provides: mopidy deamon # Required-Start: $remote_fs $syslog $network # Required-Stop: $remote_fs $syslog $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start mopidy daemon at boot time # Description: Enable mopidy music server ### END INIT INFO DAEMON_PATH = "/usr/bin/" DAEMON = mopidy DAEMONOPTS = "" NAME = mopidy DESC = "My mopidy init script" PIDFILE = / var / run / $NAME .pid SCRIPTNAME = / etc / init .d / $NAME case "$1" in start ) echo "Starting Mopidy Daemon" start - stop - daemon -- start -- chuid pi -- background -- exec / usr / bin / mopidy \ -- pidfile $PIDFILE -- make - pidfile \ -- 2 > / var / log / mopidy .log ; ; stop ) echo "Stopping Mopidy Daemon" start - stop - daemon -- stop -- exec / usr / bin / mopidy -- pidfile $PIDFILE ; ; restart ) $ 0 stop $ 0 start ; ; * ) echo "Usage: $0 {start|stop|restart}" exit 1 esac

Add execute rights:

sudo chmod +x /etc/init.d/mopidy 1 sudo chmod +x /etc/init.d/mopidy

Obligatory test:

sudo service mopidy start 1 sudo service mopidy start

If all works fine:

sudo update-rc.d mopidy enable 1 sudo update-rc.d mopidy enable

Let us know what you think about mopidy. What is your setup? Some helpful hints? Any issues with mopidy? Leave us a comment :)