Mopidy - Spotify client

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

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

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\n %(message)s debug_file = mopidy.log config_file =

Loglevels

Logging level of python modules.

[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

Proxy

Provide hostname and credentials if you use one.

[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

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.

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.

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

Last.fm scrobbler

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

[scrobbler]

enabled = false username = # Must be set.

Media Player Remote Interfacing Specification (MPRIS)

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

[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

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

# mopidy daemon

# chkconfig: 345 20 80

# description: mopidy daemon

# processname: mopidy

# Provides: mopidy deamon

# Required-Start: $remote_fs $syslog $network

# Required-Stop: $remote_fs $syslog $network

# Default-Stop: 0 1 6

# Short-Description: Start mopidy daemon at boot time

# Description: Enable mopidy music server

DAEMON=mopidy

DAEMONOPTS=""

NAME=mopidy

DESC="My mopidy init script"

PIDFILE=/var/run/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

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

Obligatory test:

sudo service mopidy start

If all works fine:

sudo update-rc.d mopidy enable

Continue reading here: Sickbeard

Was this article helpful?

0 0

Readers' Questions

  • habte
    How to run spotify on raspberry pi mopidy?
    3 months ago
  • To run Spotify on Raspberry Pi with Mopidy, you need to follow these steps:
    1. Update your Raspberry Pi:
    2. - Open the terminal. - Run the following commands: ``` sudo apt-get update sudo apt-get upgrade ```
    3. Install the necessary dependencies:
    4. - Still in the terminal, run the following command: ``` sudo apt-get install mopidy mopidy-spotify ```
    5. Configure Mopidy to use your Spotify Premium account:
    6. - Open the Mopidy configuration file by running this command: ``` sudo nano /etc/mopidy/mopidy.conf ``` - Scroll down to the `[spotify]` section and add your Spotify username and password: ``` [spotify] enabled = true username = your_spotify_username password = your_spotify_password ``` - Press `Ctrl + X`, then `Y`, and finally `Enter` to save and exit the file.
    7. Restart Mopidy:
    8. - Restart the Mopidy service by running the following command: ``` sudo systemctl restart mopidy ```
    9. Access the Spotify player:
    10. - Open your favorite web browser on a device connected to the same network as your Raspberry Pi. - Enter `http://raspberrypi:6680/spotify` in the address bar. - You should now see the Mopidy-Spotify web interface where you can log in and control your Spotify playback. That's it! You have successfully set up Spotify on your Raspberry Pi using Mopidy.