Last active
April 19, 2023 10:52
-
-
Save csssuf/13213f23191b92a7ce77 to your computer and use it in GitHub Desktop.
Adds now playing indicator from spotify or MPD to i3status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
i3status | while : | |
do | |
read line | |
dir=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) | |
spotify_status=$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus' | tail -n1 | cut -d'"' -f2) | |
spotify_artist=$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | awk -f ${dir}/spotify_song.awk | head -n 1 | cut -d':' -f2) | |
spotify_song=$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | awk -f ${dir}/spotify_song.awk | tail -n 1 | cut -d':' -f2) | |
mpd_song=$(mpc current) | |
if [ "$spotify_status" = "Playing" ] ; then | |
echo -n "NP: $spotify_artist - $spotify_song | $line" || exit 1 | |
continue | |
elif [ "$mpd_song" != "" ]; then | |
mpd_status=$(mpc status | tail -2 | head -1 | cut -d' ' -f1 | tr -d '[]') | |
if [ "$mpd_status" = "playing" ]; then | |
echo -n "NP: $mpd_song | $line" || exit 1 | |
continue | |
fi | |
echo -n $line || exit 1 | |
continue | |
fi | |
echo -n $line || exit 1 | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/string *"xesam:artist/{ | |
while (1) { | |
getline line | |
if (line ~ /string "/) { | |
sub(/.*string "/, "artist:", line) | |
sub(/".*$/, "", line) | |
print line | |
break | |
} | |
} | |
} | |
/string *"xesam:title/{ | |
while(1) { | |
getline line | |
if (line ~ /string "/) { | |
sub(/.*string "/, "title:", line) | |
sub(/".*$/, "", line) | |
print line | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To preserve color I enabled
output_format = "i3bar"
in i3status config and mutated the string with sed (line 14):
echo $(echo "$line" | sed 's/{\"name/{\"name\":\"music\",\"full_text\":\"'"$spotify_artist"' - '"$spotify_song"'\"},{\"name/') || exit 1
A bit messy, but it works.
https://gist.github.com/Romern/8cb31ae62b3f8e5dedb90c2c739dac70