-
Notifications
You must be signed in to change notification settings - Fork 114
Spotify extension
Skillzore edited this page Oct 18, 2018
·
22 revisions
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 wmctrl which needs to be installed, 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.
This is all done using 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.
#!/bin/bash
# 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 [wmctrl](http://tripie.sweb.cz/utils/wmctrl/) which needs to be installed, 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.
# ![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)
# if spotify is started
if [ "$(pidof spotify)" ]; then
status=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:PlaybackStatus | egrep -A 1 string | cut -d '"' -f 2)
album=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | egrep -A 1 xesam:album | egrep -v xesam:album | cut -d '"' -f 2 | cut -d $'\n' -f 1)
artist=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata |egrep -A 2 xesam:artist |egrep -v xesam:artist |egrep -v array |cut -d '"' -f 2)
title=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | egrep -A 1 xesam:title | egrep -v xesam:title | cut -d '"' -f 2)
finalString=$(echo "$status: $artist - $title" | sed 's/&/\&/')
echo "$finalString | iconName=spotify"
echo "---"
# show play or pause button depending on current status
if [ "$status" == "Paused" -o "$status" == "Stopped" ]; then
echo "Play | iconName=media-playback-start bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause' terminal=false"
else
echo "Pause | iconName=media-playback-pause bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause' terminal=false"
fi
# next button
echo "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
echo "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
echo "Exit Spotify | iconName=application-exit bash='wmctrl -xc spotify.Spotify' terminal=false"
else
echo "Spotify is not running | iconName=spotify"
echo "---"
echo "Start Spotify | iconName=spotify bash='spotify U%' terminal=false"
fi
Save as ~/.config/argos/spotify.1s.sh
and don't forget to make it executable!
Made by Skillzore