MRA3: Installing Mopidy and Iris

This post goes about installing Mopidy with the interface Iris. This player will be connected to Snapcast. If you want to use it with Snapcast, read part 2 about installing it.

The following steps are needed to install Mopidy:

  • Add the archive’s GPG key
  • Add the APT repo to your package sources
  • Install Mopidy and all dependencies
  • Install the Spotify extension
sibrecht@Memien:~$ wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add -
sibrecht@Memien:~$ sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/stretch.list
sibrecht@Memien:~$ sudo apt-get update
sibrecht@Memien:~$ sudo apt-get install mopidy
sibrecht@Memien:~$ sudo apt-get install mopidy-spotify

For installing Iris, the following steps are needed:

  • Instal Iris with pip
  • WARNING: On the GitHub of Iris is a second command. It should give Iris sudo users. I executed this command and the sudoers file was corrupted. I had to reinstall my whole computer. I just did not execute this second command and Iris worked just fine.
sibrecht@Memien:~$ sudo pip install Mopidy-Iris

Automatically, there is a basic file created at /usr/share/mopidy/conf.d. I made an extra standard configuration file at /etc/mopidy/mopidy.conf. This need to be updated with some parameters. If not, you can create this file. There is a smart way to start Mopidy. This player supports multiple instances. To make this easy, we can make a general configuration file and a specific for every instance. When starting Mopidy, we add the configuration files as a parameter.

The general file, called /etc/mopidy/mopidy.conf, looks like this:

[core]
cache_dir = /var/cache/mopidy
config_dir = /etc/mopidy
data_dir = /var/lib/mopidy

[logging]
config_file = /etc/mopidy/logging.conf
debug_file = /var/log/mopidy/mopidy-debug.log

[local]
media_dir = /var/lib/mopidy/media

[m3u]
playlists_dir = /var/lib/mopidy/playlists

[stream]
enabled = true
protocols =
    http
    https
    mms
    rtmp
    rtmps
    rtsp
timeout = 5000

This general file, I left unchanged. The specific files are more interesting.

The specific configuration file for my player, called /etc/mopidy/sibrecht.conf, would look like this:

[spotify]
username = sgoudsme
password = myPasswd
client_id = 12345a67-890b-1234-c567-89de01f2g34h
client_secret = aBCd01EfGHijk2LmNOp3QRs456tU78VwXYzaB9cDEFG-

[spotify_web]
username = sgoudsme
password = myPasswd
client_id = 12345a67-890b-1234-c567-89de01f2g34h
client_secret = aBCd01EfGHijk2LmNOp3QRs456tU78VwXYzaB9cDEFG-

['audio]
output = audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink location=/tmp/snapfifo1

[http]
enabled = true
hostname = ::
port = 6680

[iris]
snapcast_enabled = true
snapcast_port = 6680

In the specific file we can see some blocs:

  • Spotify and Spotify_web: Here you need to add your username and password. Also those client_id’s and client_secret’s need to be made. These two last codes can be obtained from here: https://www.mopidy.com/authenticate/#spotify. You need to authenticate with your credentials, and the codes will appear in the web browser. Just copy and paste.
  • Audio: Remark! remove the ‘ in the audio brackets. I had to add this because of syntax problems in WordPress. Here you can copy the whole line and, if necessary, change the name of /tmp/snapfifo1 to the name of the pipe in your Snapcast configuration.
  • Http and iris: Here you need to change the port for every instance. The first can be at 6680, the second 6681. With this system, the different instances will be accessible by another port.

To run Mopidy, we can now run a simple command with the corresponding config files. We can add as many configuration files as we want. Between every config file, we add a ‘:’. As you can see, I used three config files. Eventually, the command looks like this:

/usr/bin/mopidy --config /usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf:/etc/mopidy/sibrecht.conf

In the standard installation, Mopidy does not run as a service. Therefore we need to make this manually. We need to make a service file. The file is found at /lib/systemd/system/mopidy_sibrecht.service and should look like:

[Unit]
Description=Mopidy music server
After=avahi-daemon.service
After=dbus.service
After=network.target
After=nss-lookup.target
After=pulseaudio.service
After=remote-fs.target
After=sound.target

[Service]
User=mopidy
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p /var/cache/mopidy
ExecStartPre=/bin/chown mopidy:audio /var/cache/mopidy
ExecStart=/usr/bin/mopidy --config /usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf:/etc/mopidy/sibrecht.conf

[Install]
WantedBy=multi-user.target

We can enable the script for starting at startup of the computer and start the script immediately with the following two commands:

sibrecht@Memien:~$ sudo systemctl enable mopidy_sibrecht.service
sibrecht@Memien:~$ sudo systemctl start mopidy_sibrecht.service

When everything goes right, the server should start at port 6680, and you should be able to click and see the Iris interface.

Leave a Reply

Your email address will not be published. Required fields are marked *