This guide helps you setup a configuration like: mopidy -> icecast -> listner (bot) Where you can use mopidy to play from a wide selection of sources for example Spotify. At the moment I know of no Discord bots capable of controlling an mpd/mopidy server so the adding of playlists have to go through a webinterface or similar. In this guide I will focus on setting up Spotify. The full config files will also be in the gist.
The oficcial documentation have guides for installing Mopidy: https://docs.mopidy.com/en/latest/installation/
You will also need to install mopidy-spotify and a interface, I am using Iris, but other interfaces should work.
You can get your ID and SECRET using this tool: https://www.mopidy.com/authenticate/#spotify (NOTE: You have to have Spotify Premium for this to work)
~/.config/mopidy/mopidy.conf
[core]
max_tracklist_length = 10000
[logging]
color = true
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
[audio]
mixer = software
mixer_volume = # Default if no value set is 100.
output = lamemp3enc ! shout2send mount=mopidy ip=127.0.0.1 port=8000 password=hackme
[file]
enabled = false
[http]
enabled = true
hostname = 0.0.0.0 # Will have to be this to take request from outside of localhost.
port = 6680
static_dir =
zeroconf = Mopidy HTTP server on $hostname
[iris]
country = gb # Can be changed to match your local country and locale.
locale = en_GB
[spotify]
username = USERNAME
password = PASSWORD
client_id = ID
client_secret = SECRET
You can either get Icecast though you distros pacakge repo (NOTE: It may be called Icecast2 (Ubuntu)) or get it from the official site
Because mopidy does not work properly with streams of audio you will need to setup a fallback stream. (mopidy#1306) This can be done by adding the following to your icecast config file, add it where the commented mounts are as well:
/etc/icecast.xml
<mount>
<mount-name>/mopidy</mount-name>
<fallback-mount>/silence.mp3</fallback-mount>
<fallback-override>1</fallback-override>
</mount>
You will also need to add a mp3 file containing silence in the folder specified by <webroot>...</webroot>
in /etc/icecast.xml
I am using the 500 ms of silence from anars/blank-audio (NOTE: I am not sure this is optimal, I have to test more.)
The best way to start is;
- Start the Icecast2 server
# systemctl start icecast.service
- Start the mopidy server
$ mopidy
(NOTE: Can also be run as an service) - Add music to the playlist.
- Connect the bot
;;play http://example.com/mopidy
- The stream may become unresponsive if you skip a lot of songs or have it is paused for an extended amount of time. (This may have something to do with the length of
silence.mp3
) - You have to use a webinterface (This could be solved by having a secondary bot to connect to the mpd/mopidy server)