diff --git a/README.md b/README.md index 417eb73..eb98afa 100644 --- a/README.md +++ b/README.md @@ -86,11 +86,11 @@ Dependencies: ```mpc``` ### dwm_spotify 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 Displays the current date and time diff --git a/bar-functions/dwm_spotify.sh b/bar-functions/dwm_spotify.sh index 3ec5338..2d8123d 100755 --- a/bar-functions/dwm_spotify.sh +++ b/bar-functions/dwm_spotify.sh @@ -4,16 +4,24 @@ # Joe Standring # 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 () { 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 [ "$STATUS" = "Playing" ]; then @@ -21,17 +29,36 @@ dwm_spotify () { else STATUS="⏸" fi + + if [ "$SHUFFLE" = "On" ]; then + SHUFFLE=" 🔀" + else + SHUFFLE="" + fi else if [ "$STATUS" = "Playing" ]; then STATUS="PLA" else STATUS="PAU" fi + + if [ "$SHUFFLE" = "On" ]; then + SHUFFLE=" S" + else + SHUFFLE="" + 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 }