From 3ea0216410c2bd7b5487c37156df8011e499374f Mon Sep 17 00:00:00 2001 From: joestandring Date: Sun, 2 Feb 2020 20:52:39 +0000 Subject: [PATCH] Add dwm_spotify --- README.md | 13 ++++++++++-- bar-functions/dwm_spotify.sh | 38 ++++++++++++++++++++++++++++++++++++ dwm_bar.sh | 3 ++- 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100755 bar-functions/dwm_spotify.sh diff --git a/README.md b/README.md index 8cc43e0..a7918ca 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ A modular statusbar for DWM - [dwm_resources](#dwm_resources) - [dwm_cmus](#dwm_cmus) - [dwm_mpc](#dwm_mpc) + - [dwm_spotify](#dwm_mpc) - [dwm_date](#dwm_date) - [dwm_mail](#dwm_mail) - [dwm_weather](#dwm_weather) @@ -67,17 +68,25 @@ Displays information regarding memory, CPU temperature, and storage [🖥 MEM 1.3Gi/15Gi CPU 45C STO 2.3G/200G: 2%] ``` ### dwm_cmus -displays current cmus status, artist, track, position, duration, and shuffle +Displays current cmus status, artist, track, position, duration, and shuffle ``` [▶ The Unicorns - Tuff Ghost 0:43/2:56 🔀] ``` Dependencies: ```cmus``` ### dwm_mpc -displays current mpc status, artist, track, position, duration, and shuffle +Displays current mpc status, artist, track, position, duration, and shuffle ``` [▶ The Unicorns - Tuff Ghost 0:43/2:56 🔀] ``` Dependencies: ```mpc``` +### dwm_mpc +Displays current Spotify status, artist, track, and duration +Unfortunatley a method to display the track position and shuffle status have not been found +``` +[▶ The Unicorns - Tuff Ghost 2:56] +``` +Dependencies: ```spotify, playerctl``` + ### dwm_date Displays the current date and time ``` diff --git a/bar-functions/dwm_spotify.sh b/bar-functions/dwm_spotify.sh new file mode 100755 index 0000000..3ec5338 --- /dev/null +++ b/bar-functions/dwm_spotify.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# A dwm_bar function that shows the current artist, track, duration, and status from Spotify using playerctl +# Joe Standring +# GNU GPLv3 + +# Dependencies: spotify, playerctl + +# TODO: Find a method to get track position data and shuffle status (currently playerctl does not work for this) + +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) + + if [ "$IDENTIFIER" = "unicode" ]; then + if [ "$STATUS" = "Playing" ]; then + STATUS="▶" + else + STATUS="⏸" + fi + else + if [ "$STATUS" = "Playing" ]; then + STATUS="PLA" + else + STATUS="PAU" + fi + fi + + printf "%s%s %s - %s " "$SEP1" "$STATUS" "$ARTIST" "$TRACK" + printf "%0d:%02d" $((DURATION%3600/60)) $((DURATION%60)) + printf "%s\n" "$SEP2" + fi +} + +dwm_spotify diff --git a/dwm_bar.sh b/dwm_bar.sh index 9b3790c..9fbddce 100755 --- a/dwm_bar.sh +++ b/dwm_bar.sh @@ -27,6 +27,7 @@ export SEP2="]" . "$DIR/bar-functions/dwm_transmission.sh" . "$DIR/bar-functions/dwm_cmus.sh" . "$DIR/bar-functions/dwm_mpc.sh" +. "$DIR/bar-functions/dwm_spotify.sh" . "$DIR/bar-functions/dwm_resources.sh" . "$DIR/bar-functions/dwm_battery.sh" . "$DIR/bar-functions/dwm_mail.sh" @@ -43,6 +44,6 @@ export SEP2="]" # Update dwm status bar every second while true do - xsetroot -name "$(dwm_countdown)$(dwm_alarm.sh)$(dwm_transmission)$(dwm_cmus)$(dwm_mpc)$(dwm_resources)$(dwm_battery)$(dwm_mail)$(dwm_backlight)$(dwm_alsa)$(dwm_pulse)$(dwm_weather)$(dwm_vpn)$(dwm_network)$(dwm_keyboard)$(dwm_ccurse)$(dwm_date)" + xsetroot -name "$(dwm_countdown)$(dwm_alarm.sh)$(dwm_transmission)$(dwm_cmus)$(dwm_mpc)$(dwm_spotify)$(dwm_resources)$(dwm_battery)$(dwm_mail)$(dwm_backlight)$(dwm_alsa)$(dwm_pulse)$(dwm_weather)$(dwm_vpn)$(dwm_network)$(dwm_keyboard)$(dwm_ccurse)$(dwm_date)" sleep 1 done