Spotify support for polybar

lightmode
E. Almqvist 3 years ago
parent 5c0f077621
commit 1970483fbd
  1. 30
      .config/polybar/config
  2. 50
      .config/polybar/scripts/get_spotify_status.sh
  3. 12
      .config/polybar/scripts/scroll_spotify_status.sh

@ -60,7 +60,7 @@ module-margin = 1
modules-left = dwm title
modules-center = time
modules-right = cmus pulseaudio wlan battery date
modules-right = cmus spotify pulseaudio wlan battery date
#################################################
# MODULES #
@ -170,6 +170,33 @@ format-underline = ${colors.line}
label = %output%
label-maxlen = 80
[module/spotify]
type = custom/script
tail = true
; prefix symbol is shown before the text
format-prefix = " "
format = <label>
exec = ~/.config/polybar/scripts/scroll_spotify_status.sh
[module/spotify-prev]
type = custom/script
exec = echo "<previous-song-symbol>"
format = <label>
click-left = playerctl previous spotify
[module/spotify-play-pause]
type = custom/ipc
hook-0 = echo "<playing-symbol>"
hook-1 = echo "<pause-symbol>"
initial = 1
click-left = playerctl play-pause spotify
[module/spotify-next]
type = custom/script
exec = echo "next-song-symbol"
format = <label>
click-left = playerctl next spotify
[module/wlan]
type = internal/network
interface = wlp1s0
@ -178,7 +205,6 @@ interval = 3.0
format-connected = <ramp-signal> <label-connected>
format-connected-underline = ${colors.foreground}
label-connected = %essid%
format-disconnected =
;format-disconnected = <label-disconnected>
;format-disconnected-underline = ${self.format-connected-underline}

@ -0,0 +1,50 @@
#!/bin/bash
# The name of polybar bar which houses the main spotify module and the control modules.
PARENT_BAR="now-playing"
PARENT_BAR_PID=$(pgrep -a "polybar" | grep "$PARENT_BAR" | cut -d" " -f1)
# Set the source audio player here.
# Players supporting the MPRIS spec are supported.
# Examples: spotify, vlc, chrome, mpv and others.
# Use `playerctld` to always detect the latest player.
# See more here: https://github.com/altdesktop/playerctl/#selecting-players-to-control
PLAYER="spotify"
# Format of the information displayed
# Eg. {{ artist }} - {{ album }} - {{ title }}
# See more attributes here: https://github.com/altdesktop/playerctl/#printing-properties-and-metadata
FORMAT="{{ title }} - {{ artist }}"
# Sends $2 as message to all polybar PIDs that are part of $1
update_hooks() {
while IFS= read -r id
do
polybar-msg -p "$id" hook spotify-play-pause $2 1>/dev/null 2>&1
done < <(echo "$1")
}
PLAYERCTL_STATUS=$(playerctl --player=$PLAYER status 2>/dev/null)
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
STATUS=$PLAYERCTL_STATUS
else
STATUS="No player is running"
fi
if [ "$1" == "--status" ]; then
echo "$STATUS"
else
if [ "$STATUS" = "Stopped" ]; then
echo "No music is playing"
elif [ "$STATUS" = "Paused" ]; then
update_hooks "$PARENT_BAR_PID" 2
playerctl --player=$PLAYER metadata --format "$FORMAT"
elif [ "$STATUS" = "No player is running" ]; then
echo "$STATUS"
else
update_hooks "$PARENT_BAR_PID" 1
playerctl --player=$PLAYER metadata --format "$FORMAT"
fi
fi

@ -0,0 +1,12 @@
#!/bin/bash
# see man zscroll for documentation of the following parameters
zscroll -l 30 \
--delay 0.1 \
--scroll-padding " " \
--match-command "$HOME/.config/polybar/scripts/get_spotify_status.sh --status" \
--match-text "Playing" "--scroll 1" \
--match-text "Paused" "--scroll 0" \
--update-check true "$HOME/.config/polybar/scripts/get_spotify_status.sh" &
wait
Loading…
Cancel
Save