The DIY Music Streamer Part 3.



I am going to use Mopidy as an alternative to the stock Spotify client and for playback of local media like my CD albums ripped as lossless FLAC files. Mopidy is just a server like MPD but it is extensible and got some really nice extensions. I will not go crazy and add a lot of them. I will use some to access my Spotify Premium account, some for access to my local media and one to access everything as a web-client.

There are many ways to let my Raspberry Pi access my media files. I could use some local media storage like a USB flash drive or hard drive. I keep my media on a separate file server running Linux so I will NFS mount my media. You could do the same if you keep your media on a server or a NAS. Windows users might feel more at home using SMB instead of NFS. SMB can be mounted by the Raspberry Pi using Samba but I will stick to NFS in my example. The IP address 192.168.1.2 is used for the file server.
Logon to your Raspberry Pi and install what is needed to run as a NFS client with the command:

sudo apt install nfs-common

Create a directory where we are going to mount our media:

sudo mkdir /mnt/music

Run the following command:

sudo nano /etc/fstab

And add the following line:

192.168.1.2:/path/to/music/files /mnt/music nfs ro,async,soft,intr,noexec 0 0

Save and exit with Ctrl-X, then Y. It will mount the external media read only with the command:

sudo mount /mnt/music/

The mount will be persistent between boots and you can check the content with:

ls /mnt/music/

Great, we got access to our media, time to install Mopidy. We will install as much as possible trough apt since it is then updated with the rest of the OS. Start with the following commands:

sudo apt-get install mopidy
sudo apt-get install mopidy-spotify
sudo apt-get install mopidy-spotify-tunigo
sudo apt-get install mopidy-local-sqlite

sudo apt install python-pip

Some of what we need in not in the Raspbian repository so we need to install it through pip. The last command in the following list installed pip. Continue with the following commands:

sudo pip install Mopidy-Spotify-Web
sudo pip install Mopidy-Local-Images
sudo pip install Mopidy-Iris


That is all we need to start with. Next step is to configure Mopidy and our extensions. Open the config file for editing with the following command:

sudo nano /etc/mopidy/mopidy.conf

There are a lot of settings available but start with the basics like:

[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]
enabled = true
media_dir = /mnt/music
library = images
scan_flush_threshold = 100

[local-images]
enabled = true
library = sqlite

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

[spotify]
enabled = true
bitrate = 320
username = YourUserName
password = YourPassword
client_id = eb294a1a-fdba-FAKE-aa4e-bfce188b9a3e
client_secret = x8yAYohtFAKEknvO8Jv13CTFfJzgLOHX33rOMt5LfagM=

[spotify_tunigo]
enabled = true

[spotify_web]

enabled = true 
client_id = eb294a1a-fdba-FAKE-aa4e-bfce188b9a3e
client_secret = x8yAYohtFAKEknvO8Jv13CTFfJzgLOHX33rOMt5LfagM=
 

[iris]
enabled = true

[http]
enabled = true
hostname = 127.0.0.1
port = 6680
zeroconf = Mopidy HTTP server on $hostname
allowed_origins = 127.0.0.1
csrf_protection = true


Before starting Mopidy, you must add your Spotify Premium username and password to your Mopidy configuration file and also visit https://www.mopidy.com/authenticate/#spotify to authorize this extension against your Spotify account (the red bold text above needs to be replaced). Read more about it on the Spotify extension page.

You enable and restart the Mopidy service with the following commands:

sudo systemctl enable mopidy
sudo systemctl restart mopidy


You should now be able to access your Mopidy server on the following address (given the IP addresses I use in my example):

http://192.168.1.10:6680

There you will find links to extensions like the web-client Iris.
You should now have a basic installation of Mopidy with access both to your local media files (in this example served from an external file server) and your Spotify Premium account. This setup is still a bit rough around the edges, something I will address in my next post.