Skip to content

Commit 9010684

Browse files
authored
Merge pull request #289 from HalbardHobby/fix/dbus-spotify
✨ Added dbus-send query for playback status (spotify)
2 parents e895b85 + d95c27e commit 9010684

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ Austin Beam
3535
Ingo Heimbach
3636
MSempere
3737
kurczynski
38+
Alejandro Espinosa (Halbard) <[email protected]>

segments/now_playing.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ TMUX_POWERLINE_SEG_NOW_PLAYING_MPD_SIMPLE_FORMAT_DEFAULT="%artist% - %title%"
1212
TMUX_POWERLINE_SEG_NOW_PLAYING_PLAYERCTL_FORMAT_DEFAULT="{{ artist }} - {{ title }}"
1313
TMUX_POWERLINE_SEG_NOW_PLAYING_RHYTHMBOX_FORMAT_DEFAULT="%aa - %tt"
1414
TMUX_POWERLINE_SEG_NOW_PLAYING_NOTE_CHAR_DEFAULT=""
15+
TMUX_POWERLINE_SEG_NOW_PLAYING_MUSIC_PLAYER_DEFAULT="spotify"
1516

1617
generate_segmentrc() {
1718
read -d '' rccontents << EORC
1819
# Music player to use. Can be any of {audacious, banshee, cmus, itunes, lastfm, mocp, mpd, mpd_simple, pithos, playerctl, rdio, rhythmbox, spotify, spotify_wine, file}.
19-
export TMUX_POWERLINE_SEG_NOW_PLAYING_MUSIC_PLAYER=""
20+
export TMUX_POWERLINE_SEG_NOW_PLAYING_MUSIC_PLAYER="${TMUX_POWERLINE_SEG_NOW_PLAYING_MUSIC_PLAYER_DEFAULT}"
2021
# File to be read in case the song is being read from a file
2122
export TMUX_POWERLINE_SEG_NOW_PLAYING_FILE_NAME=""
2223
# Maximum output length.
@@ -290,8 +291,7 @@ __np_spotify() {
290291
else
291292
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)
292293
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)
294+
state=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|egrep -A 1 "string"|cut -b 26-|cut -d '"' -f 1|egrep -v ^$)
295295
if [[ $state == "Playing" ]]; then
296296
artist=$(echo "$metadata" | grep -PA2 "string\s\"xesam:artist\"" | tail -1 | grep -Po "(?<=\").*(?=\")")
297297
track=$(echo "$metadata" | grep -PA1 "string\s\"xesam:title\"" | tail -1 | grep -Po "(?<=\").*(?=\")")

0 commit comments

Comments
 (0)