-
Notifications
You must be signed in to change notification settings - Fork 1
/
spotify_control
executable file
·61 lines (56 loc) · 2.12 KB
/
spotify_control
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
#!/usr/bin/env bash
# Simple Spotify Control
# Just call ./spotify_control --help
CMD="dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player"
GETVOL="dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Volume"
SETVOL="dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Set string:org.mpris.MediaPlayer2.Player string:Volume variant:double:"
VAMT=${2:-0.1}
case "$1" in
"playpause" )
${CMD}.PlayPause
exit $?
;;
"next" )
${CMD}.Next
exit $?
;;
"previous" )
${CMD}.Previous
exit $?
;;
"stop" )
${CMD}.Stop
exit $?
;;
"play" )
${CMD}.Play
exit $?
;;
"vup" )
VOL=$(${GETVOL} | tr -d '\r\n' | awk '{n=split($0,A," "); print(A[n])}')
VOL=$(echo $VOL + $VAMT | bc)
${SETVOL}$VOL
exit $?
;;
"vdown")
VOL=$(${GETVOL} | tr -d '\r\n' | awk '{n=split($0,A," "); print(A[n])}')
VOL=$(echo $VOL - $VAMT | bc)
${SETVOL}$VOL
exit $?
;;
"vget" )
# CC="dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Set string:org.mpris.MediaPlayer2.Player string:Volume variant:double:0.453"
${GETVOL} | tr -d '\r\n' | awk '{n=split($0,A," "); print(A[n])}'
exit $?
;;
"getName" )
MUSIC=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | awk '/title/ {getline; print $0 }' | awk -F'"' '{ print $2 }')
ARTIST=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | awk '/artist/ {getline; getline; print $0 }' | awk -F'"' '{ print $2 }')
echo $MUSIC - $ARTIST
;;
*)
echo "Usage: $0 [command]"
echo " commands are: playpause, next, previous, stop, play, vup, vdown, vget"
exit 1
;;
esac