From c3784d1fd4f2cf16c49386b9d64a5b898dc71e8e Mon Sep 17 00:00:00 2001 From: Johannes Rothe Date: Wed, 19 Sep 2018 22:58:27 +0200 Subject: [PATCH] scripts: add spotify script --- scripts/spotify.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 scripts/spotify.sh diff --git a/scripts/spotify.sh b/scripts/spotify.sh new file mode 100755 index 0000000..2f10f95 --- /dev/null +++ b/scripts/spotify.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# https://raw.githubusercontent.com/NicholasFeldman/dotfiles/master/polybar/.config/polybar/spotify.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 "$@"