pyonos is a remotely controllable spotify client that can be installed on any system with python support and an ALSA-compatible soundcard. It can be accessed locally via an internet browser by navigating to the host's (the system running pyonos) local IP address with the proper port (e.g. 192.168.1.18:5001). From there you can play music in a priority queue. The website is both desktop- and mobile-friendly.
Main window (home):
Search window:
For this to work, it has to run on a computer with an ALSA-compatible soundcard (e.g. Raspberry PI). If no such soundcard exists, you have to modify the audio sink specified in the init-function of the boye.py's Player-class.
Install libspotify
wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add -
sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/mopidy.list
sudo apt-get update
sudo apt-get install libspotify-dev
Install pyspotify (if pip complains about the '--pre' option, remove it)
sudo apt-get install build-essential python-dev python3-dev libffi-dev
sudo pip install --pre pyspotify
Install flask
sudo pip install Flask
Install pyonos
git clone https://github.com/boyeborg/pyonos.git
You also need an application developer key from spotify.
- Go to the Spotify developer pages and login using your Spotify account.
- Find the libspotify application keys management page and request an application key for your application.
- Once the key is issued, download the “binary” version. The “C code” version of the key will not work with pyspotify.
Place the application key in root folder of pyonos (the same folder as app.py is in), and name it "spotify_appkey.key"
You have to make a settings.py-file in the root folder of pyonos (the same folder as app.py is in) containing your spotify username and password. It should look like this:
SPOTIFY_USER = 'username'
SPOTIFY_PASS = 'secret'
If you usaly use facebook for logging in to spotify, and don't know your spotify username, you can find this by going to your profile in the spotify desktop application, clicking on the option-button (scircle with three dots in it, right next to your profile picture), and copy the spotify URI. It will look something like this: spotify:user:username
or spotify:user:0123456789
. The part after "spotify:user:" is your username. You can probably request a (new) password for that username if you don't know it.
On the bottom-most line of app.py you can specify the port of the pyonos server
app.run(debug=True, host='0.0.0.0', port=5001, threaded=True)
The playlists displayed on the front page can be altered easily in app.py. Find the home-function, and add/remove playlist URIs in the list called "pl".
@app.route('/')
def home():
pl = [
'spotify:user:lars_93:playlist:17dahvTFovxEqqEJLsDoNQ',
'spotify:user:pumazz:playlist:2e3fd32clPYmADf809LrM6',
'spotify:user:pumazz:playlist:7dD8A6HTNUYW6kgs9yvh28',
'spotify:user:lars_93:playlist:1cURhgTeJBdZFuurOcjFRg',
'spotify:user:pumazz:playlist:2Qn3V38vhATTp1M7wzYG0p',
'spotify:user:pumazz:playlist:6wnTPemhthfpExS1W8jklx',
'spotify:user:magnode:playlist:5NLNeYg2ZMM8Zb1KR2mtBl'
]
For this to work, the playlist specified has to be public. You can make playlists public and find their URI in the spotify desktop application.
To run pyonos, simply:
sudo python app.py
If you are running it on a server via ssh, and want to prevent it from stop running after the ssh session is terminated, you can either start it in a screen like this:
screen -S pyonos
sudo python app.py
And then detach from the screen with ctrl+a+d
.
To reattach:
screen -r pyonos
To kill/stop/terminate pyonos:
sudo fuser -n tcp -k <port>
The port is 5001 if you have not changed it (see the port configure section).
To access pyonos, visit the local ip of the host running the pyonos server, on the port specified in the port configuration, in your internet browser (IE is not well supported). E.g.: 192.168.1.18:5001