Browse Source

Add spotifyd support

patch-fontkeys
Joe Standring 4 years ago
parent
commit
7c3bcf3d4c
2 changed files with 39 additions and 12 deletions
  1. +3
    -3
      README.md
  2. +36
    -9
      bar-functions/dwm_spotify.sh

+ 3
- 3
README.md View File

@ -86,11 +86,11 @@ Dependencies: ```mpc```
### dwm_spotify ### dwm_spotify
Displays current Spotify status, artist, track, and duration Displays current Spotify status, artist, track, and duration
Unfortunatley a method to display the track position and shuffle status have not been found
Either the official Spotify client or spotifyd can be used. Unfortunatley, only spotifyd can provide track position and shuffle status
``` ```
[▶ The Unicorns - Tuff Ghost 2:56]
[▶ The Unicorns - Tuff Ghost 0:43/2:56 🔀]
``` ```
Dependencies: ```spotify, playerctl```
Dependencies: ```spotify/spotifyd, playerctl```
### dwm_date ### dwm_date
Displays the current date and time Displays the current date and time


+ 36
- 9
bar-functions/dwm_spotify.sh View File

@ -4,16 +4,24 @@
# Joe Standring <git@joestandring.com> # Joe Standring <git@joestandring.com>
# GNU GPLv3 # GNU GPLv3
# Dependencies: spotify, playerctl
# Dependencies: spotify/spotifyd, playerctl
# TODO: Find a method to get track position data and shuffle status (currently playerctl does not work for this)
# NOTE: The official spotify client does not provide the track position or shuffle status through playerctl. This does work through spotifyd however.
dwm_spotify () { dwm_spotify () {
if ps -C spotify > /dev/null; then if ps -C spotify > /dev/null; then
ARTIST=$(playerctl -p spotify metadata artist)
TRACK=$(playerctl -p spotify metadata title)
DURATION=$(playerctl -p spotify metadata mpris:length | sed 's/.\{6\}$//')
STATUS=$(playerctl -p spotify status)
PLAYER="spotify"
elif ps -C spotifyd > /dev/null; then
PLAYER="spotifyd"
fi
if [ "$PLAYER" = "spotify" ] || [ "$PLAYER" = "spotifyd" ]; then
ARTIST=$(playerctl metadata artist)
TRACK=$(playerctl metadata title)
POSITION=$(playerctl position | sed 's/..\{6\}$//')
DURATION=$(playerctl metadata mpris:length | sed 's/.\{6\}$//')
STATUS=$(playerctl status)
SHUFFLE=$(playerctl shuffle)
if [ "$IDENTIFIER" = "unicode" ]; then if [ "$IDENTIFIER" = "unicode" ]; then
if [ "$STATUS" = "Playing" ]; then if [ "$STATUS" = "Playing" ]; then
@ -21,17 +29,36 @@ dwm_spotify () {
else else
STATUS="⏸" STATUS="⏸"
fi fi
if [ "$SHUFFLE" = "On" ]; then
SHUFFLE=" 🔀"
else
SHUFFLE=""
fi
else else
if [ "$STATUS" = "Playing" ]; then if [ "$STATUS" = "Playing" ]; then
STATUS="PLA" STATUS="PLA"
else else
STATUS="PAU" STATUS="PAU"
fi fi
if [ "$SHUFFLE" = "On" ]; then
SHUFFLE=" S"
else
SHUFFLE=""
fi
fi fi
printf "%s%s %s - %s " "$SEP1" "$STATUS" "$ARTIST" "$TRACK"
printf "%0d:%02d" $((DURATION%3600/60)) $((DURATION%60))
printf "%s\n" "$SEP2"
if [ "$PLAYER" = "spotify" ]; then
printf "%s%s %s - %s " "$SEP1" "$STATUS" "$ARTIST" "$TRACK"
printf "%0d:%02d" $((DURATION%3600/60)) $((DURATION%60))
printf "%s\n" "$SEP2"
else
printf "%s%s %s - %s " "$SEP1" "$STATUS" "$ARTIST" "$TRACK"
printf "%0d:%02d/" $((POSITION%3600/60)) $((POSITION%60))
printf "%0d:%02d" $((DURATION%3600/60)) $((DURATION%60))
printf "%s%s\n" "$SHUFFLE" "$SEP2"
fi
fi fi
} }


Loading…
Cancel
Save