Add spotify to polybar

This commit is contained in:
CramMK
2020-03-20 16:45:28 +01:00
parent 9044a224e0
commit 4456cd3406
4 changed files with 36 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ green = #00d3a8
accent = ${self.green}
background = #18191E
foreground = #000000
foreground = #fff
###############################################################################
[font]
@@ -25,14 +25,14 @@ height = 35
#padding-left = 0.5
padding-right = 1
foreground = ${colors.background}
foreground = ${colors.foreground}
background = ${colors.background}
module-margin = 1
modules-left = i3tabs title
modules-center = date
modules-right = backlight network volume battery
modules-right = spotify backlight network volume battery
separator =
dim-value = 1.0
@@ -89,13 +89,15 @@ enable-click = true
enable-scroll = false
wrapping-scroll = false
format = <label-state> <label-mode>
foreground = ${colors.accent}
background = #383D41
label-focused = %index%
label-focused-foreground = ${self.foreground}
label-focused-background = ${self.background}
label-focused-underline = #fba922
label-focused-underline = #fff
label-focused-padding = 2
label-unfocused = %index%
@@ -214,3 +216,10 @@ bar-width = 10
bar-indicator = |
bar-fill = -
bar-empty = -
###############################################################################
[module/spotify]
type = custom/script
exec = ~/.config/polybar/spotify.sh %artist% - %title%
tail = true
interval = 2

23
dotfiles/polybar/spotify.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/sh
main() {
if ! pgrep -x spotify >/dev/null; then
echo ""; exit
fi
cmd="org.freedesktop.DBus.Properties.Get"
domain="org.mpris.MediaPlayer2"
path="/org/mpris/MediaPlayer2"
meta=$(dbus-send --print-reply --dest=${domain}.spotify \
/org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:${domain}.Player string:Metadata)
artist=$(echo "$meta" | sed -nr '/xesam:artist"/,+2s/^ +string "(.*)"$/\1/p' | tail -1 | sed 's/\&/\\&/g' | sed 's#\/#\\/#g')
album=$(echo "$meta" | sed -nr '/xesam:album"/,+2s/^ +variant +string "(.*)"$/\1/p' | tail -1| sed 's/\&/\\&/g'| sed 's#\/#\\/#g')
title=$(echo "$meta" | sed -nr '/xesam:title"/,+2s/^ +variant +string "(.*)"$/\1/p' | tail -1 | sed 's/\&/\\&/g'| sed 's#\/#\\/#g')
echo "${*:-%artist% - %title%}" | sed "s/%artist%/$artist/g;s/%title%/$title/g;s/%album%/$album/g"i | sed "s/\&/\&/g" | sed "s#\/#\/#g"
}
main "$@"