Jvanrhijn / polybar-spotify

🎶 Spotify artist and song module for Polybar
MIT License
583 stars 57 forks source link

Add feature: Custom text based upon playback status #4

Closed soundscape84 closed 6 years ago

soundscape84 commented 6 years ago

Wondering whether or not it would be possible to have additional text in the song title depending on whether the player is Playing or Paused? I'd fork and make an attempt myself, but I really don't know what I'm doing.

dietervanhoof commented 6 years ago

I've made some changes myself to this to get roughly the same thing. I don't like the way I've implemented it and might look for a different way of solving it but...

I created the following SH script:

#!/bin/bash

# if spotify is started
if [ "$(pidof spotify)" ]; then
    # status can be: Playing, Paused or Stopped
    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 -b 26-|cut -d '"' -f 1|egrep -v ^$`
    if [ "$status" = "Playing" ]; then
        echo "";
    else
        echo "";
    fi
else
        echo "Not running"
fi

With the following config:

[module/playpause]
type = custom/script
interval = 2
format = "%{T3}<label>"
exec = ~/scripts/spotify/isplaying.sh

This makes it run the isplaying.sh script every 2 seconds. That script will return either a play button or a pause button depending on whether your music is playing.

You can even make it interactive by adding the following under the exec=... part: click-left = "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"

That allows you to pause and resume playing music if you click on the button. I made it look like this: Playing image Paused image

Let me try and make a fork of this with my changes. I'll get back to you with the URL ASAP. Perhaps in the future I can make it work better by listening for event changes on the dbus instead of polling it.

EDIT: You can check out my github for a fork of this project as well as a newer version which doesn't poll.

Jvanrhijn commented 6 years ago

I added this feature in the latest commit, closing this for now. @dietervanhoof Nice work! I'm keeping my version up as a smaller-scope alternative.