aboutsummaryrefslogtreecommitdiff
path: root/scripts/media_is_spotify_playing.sh
blob: f4f32a5f52663f72f75ec12db467aa555d9187f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash

# this script returns 0 if spotify is playing 1 otherwise

# spotify's dbus interface is able to tell us it PlaybackStatus :)

status=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get \
string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus' 2> /dev/null`

if [ $? -ne 0 ]
then
    echo false
    exit 1
fi

status=$(echo $status | grep -o -e \".*\" | cut -d \" -f 2)

if [ $status != "Playing" ]
then
    echo false
    exit 1
fi

echo true

#spotify_running=false

#if pgrep spotify &>/dev/null
#then
    #if type pacmd &>/dev/null
    #then
        #output=$(pacmd list-sink-inputs)
        #state=""
        #spotify_running=false

        #while read -r line; do
            #if [[ $line == *state* ]]
            #then
                #if [[ $line == *RUNNING* ]]
                #then
                    #state="RUNNING"
                #else
                    #state=""
                #fi
            #fi

            #if [[ $line == *application.name* ]]
            #then
                #if [[ $state == "RUNNING" ]] && [[ $line == *Spotify* ]]
                #then
                    #spotify_running=true
                    #break
                #fi
            #fi
        #done <<< "$output"
    #elif lsof | grep /dev/snd | grep spotify &>/dev/null
    #then
        #spotify_running=true
    #fi
#fi

#echo $spotify_running
#if [[ $spotify_running == "true" ]]
#then
    #exit 0
#else
    #exit 1
#fi