Skip to content

Commit e895b85

Browse files
itaysaadiaerikw
andauthored
Added support for windows (over WSL) for NP (spotify) (#288)
* Added support for windows (over WSL) for NP (spotify) parsed tasklist for getting the now playing to work * Refactor + supress stderr and stdout on WSL check * Move linefeed stripping back in to WSL section * Fix mistake Co-authored-by: Erik Westrup <[email protected]>
1 parent 8c08432 commit e895b85

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

segments/now_playing.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,19 @@ __np_playerctl() {
284284

285285
__np_spotify() {
286286
if shell_is_linux; then
287-
metadata=$(dbus-send --reply-timeout=42 --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' 2>/dev/null)
288-
if [ "$?" -eq 0 ] && [ -n "$metadata" ]; then
289-
# TODO how do one express this with dbus-send? It works with qdbus but the problem is that it's probably not as common as dbus-send.
290-
state=$(qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player PlaybackStatus)
291-
if [[ $state == "Playing" ]]; then
292-
artist=$(echo "$metadata" | grep -PA2 "string\s\"xesam:artist\"" | tail -1 | grep -Po "(?<=\").*(?=\")")
293-
track=$(echo "$metadata" | grep -PA1 "string\s\"xesam:title\"" | tail -1 | grep -Po "(?<=\").*(?=\")")
294-
np=$(echo "${artist} - ${track}")
287+
if type tasklist.exe >/dev/null 2>&1; then # WSL
288+
np=$(tasklist.exe /APPS /fo list /v /fi "IMAGENAME eq Spotify.exe" | grep " - " | cut -d" " -f3-)
289+
np="${np//[$'\t\r\n']}"
290+
else
291+
metadata=$(dbus-send --reply-timeout=42 --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' 2>/dev/null)
292+
if [ "$?" -eq 0 ] && [ -n "$metadata" ]; then
293+
# TODO how do one express this with dbus-send? It works with qdbus but the problem is that it's probably not as common as dbus-send.
294+
state=$(qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player PlaybackStatus)
295+
if [[ $state == "Playing" ]]; then
296+
artist=$(echo "$metadata" | grep -PA2 "string\s\"xesam:artist\"" | tail -1 | grep -Po "(?<=\").*(?=\")")
297+
track=$(echo "$metadata" | grep -PA1 "string\s\"xesam:title\"" | tail -1 | grep -Po "(?<=\").*(?=\")")
298+
np=$(echo "${artist} - ${track}")
299+
fi
295300
fi
296301
fi
297302
elif shell_is_osx; then

0 commit comments

Comments
 (0)