-
Notifications
You must be signed in to change notification settings - Fork 113
Spotify extension
This is a simple Spotify extension that displays the currently playing/paused song with artist and title. There are also some simple controls to pause/play, go to next or previous song and to exit spotify. Exit Spotify uses a separate python script which needs to be created, or you can just remove the exit button from the script.
If spotify isn't running, "Spotify is not running" is displayed together with a button to start Spotify.
Note: I have now added album, which is not represented in picture.
To edit the text, change the string variable below the comment Edit display string here in the script to your liking.
This is all done using python and Mopidy, and their Spotify extension. It should be included when installing Spotify (at least I can't remember installing it separately), but should you need to install it for some reason, it can be found here. The script uses the python module psutil, install it using pip install psutil
. You also need python-dbus, install it using sudo apt install python-dbus
.
#!/usr/bin/env python3
# This is a simple Spotify extension that displays the currently playing/paused song with artist and title. There are also some simple controls to pause/play, go to next or previous song and to exit spotify. To kill the spotify application, a separate python script is used. If spotify isn't running, "Spotify is not running" is displayed together with a button to start Spotify.
# Kill script:
#import sys
#import psutil
#
#for proc in psutil.process_iter():
# if proc.name() == sys.argv[1]:
# proc.kill()
#
# ![Spotify extension screenshot running](https://i.imgur.com/bF2NGBr.png)
# ![Spotify extension screenshot not running](https://i.imgur.com/fFhEEZs.png)
# Made by [Skillzore](https://github.com/Skillzore)
import dbus
import psutil
def isRunning(name):
for proc in psutil.process_iter():
if proc.name() == name:
return True
if(isRunning("spotify")):
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object('org.mpris.MediaPlayer2.spotify', '/org/mpris/MediaPlayer2')
spotify_properties = dbus.Interface(spotify_bus, 'org.freedesktop.DBus.Properties')
metadata = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
playbackStatus = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')
fixAmpChar = (playbackStatus + ": " + metadata['xesam:artist'][0] + " | " + metadata['xesam:album'] + " | " + metadata['xesam:title']).replace("&","&")
finalString = fixAmpChar.replace("|","|")
print(finalString + " | iconName=spotify ")
print("---")
# show play or pause button depending on current status
if(playbackStatus == "Paused" or playbackStatus == "Stopped"):
print("Play | iconName=media-playback-start bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play' terminal=false")
else:
print("Pause | iconName=media-playback-pause bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause' terminal=false")
# next button
print("Next | iconName=media-skip-forward bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next' terminal=false")
# previous buton
print("Previous | iconName=media-skip-backward bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous' terminal=false")
# exit spotify
print("Exit Spotify | iconName=application-exit bash='python3 /home/simonc/.config/argos/.kill.py spotify' terminal=false")
else:
print("Spotify is not running | iconName=spotify")
print("---")
print("Start Spotify | iconName=spotify bash='spotify U%' terminal=false")
Save as ~/.config/argos/spotify.1s.py
and don't forget to make it executable!
Made by Skillzore