Skip to content

Instantly share code, notes, and snippets.

@Phate6660
Last active May 8, 2021 17:55
Show Gist options
  • Save Phate6660/33f5e213660e799c5692ac382765e7bc to your computer and use it in GitHub Desktop.
Save Phate6660/33f5e213660e799c5692ac382765e7bc to your computer and use it in GitHub Desktop.
A snippet to display music info from MPD or Spotify.
#!/bin/bash
if [ "$(playerctl -p spotify,mpd metadata -f "{{ playerName }}")" == "mpd" ]; then
dunstify "$(echo -e "$(playerctl -p spotify,mpd metadata -f "Player: {{ playerName }}\n\nTIT: {{ title }}\nALB: {{ album }}\nART: {{ artist }}")")" -I "/tmp/cover.png"
elif [ "$(playerctl -p spotify,mpd metadata -f "{{ playerName }}")" == "spotify" ]; then
id="$(basename "$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | awk -F '"' 'BEGIN {RS=" entry"}; /"mpris:artUrl"/ {a = $4} END {print a}')")"
url="https://i.scdn.co/image/$id"
curl "$url" -o "/tmp/cover-spotify.jpg"
dunstify "$(echo -e "$(playerctl -p spotify,mpd metadata -f "Player: {{ playerName }}\n\nTIT: {{ title }}\nALB: {{ album }}\nART: {{ artist }}")")" -I "/tmp/cover-spotify.jpg"
else
dunstify "$(echo -e "$(playerctl -p spotify,mpd metadata -f "Player: {{ playerName }}\n\nTIT: {{ title }}\nALB: {{ album }}\nART: {{ artist }}")")"
fi
@Phate6660
Copy link
Author

Phate6660 commented May 8, 2021

Example output:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment