forked from mgafner/clementine-remote-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clementine-remote-bash.sh
executable file
·162 lines (147 loc) · 4.29 KB
/
clementine-remote-bash.sh
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
# clementine-remote-bash is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# clementine-remote-bash is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this code. If not, see <http://www.gnu.org/licenses/>.
DBUSBASE="org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2"
# Check if clementine is running
function is_clementine_running()
{
ps -A | grep "clementine" | grep -v "remo" > /dev/null
status=$?
if [ $status -ne 0 ]; then
echo "clementine is not running"
exit 1
fi
}
# show usage
function usage()
{
echo "usage: $(basename $0) -g <info-to-get>
OPTIONS:
-c command
commands can be:
play
pause
playpause
prev
next
-g get info
-h list all commands
examples:
$(basename $0) -c play
$(basename $0) -g title
$(basename $0) -g status
"
}
function runcmd()
{
case $1 in
next)
qdbus $DBUSBASE org.mpris.MediaPlayer2.Player.Next
;;
pause)
qdbus $DBUSBASE org.mpris.MediaPlayer2.Player.Pause
;;
play)
qdbus $DBUSBASE org.mpris.MediaPlayer2.Player.Play
;;
playpause)
qdbus $DBUSBASE org.mpris.MediaPlayer2.Player.PlayPause
;;
prev)
qdbus $DBUSBASE org.mpris.MediaPlayer2.Player.Previous
;;
shuffle)
shuffle
;;
*)
echo "command $1 not known or not implemented"
exit 1
;;
esac
return
}
function setvolume()
{
qdbus $DBUSBASE org.freedesktop.DBus.Properties.Set org.mpris.MediaPlayer2.Player Volume $1
}
function shuffle()
{
qdbus $DBUSBASE org.freedesktop.DBus.Properties.Set org.mpris.MediaPlayer2.Player Shuffle false
sleep 1
qdbus $DBUSBASE org.freedesktop.DBus.Properties.Set org.mpris.MediaPlayer2.Player Shuffle true
}
function getinfo()
{
case $1 in
artist)
qdbus $DBUSBASE org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata | awk '/artist:/{$1=""; print substr($0,2)}'
;;
position)
qdbus $DBUSBASE org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Position
;;
shuffle)
qdbus $DBUSBASE org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Shuffle
;;
status)
qdbus $DBUSBASE org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player PlaybackStatus
;;
title)
qdbus $DBUSBASE org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata | awk '/title:/{$1=""; print substr($0,2)}'
;;
volume)
qdbus $DBUSBASE org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Volume
;;
*)
echo "command $1 not known or not implemented"
exit 1
;;
esac
return
}
function main()
{
# check if clementine is running, the function exit if not
is_clementine_running
if [ $# -eq 0 ]; then
usage
exit 1
fi
# When you need an argument that needs a value, you put the ":" right after
# the argument in the optstring. If your var is just a flag, withou any
# additional argument, just leave the var, without the ":" following it.
#
# please keep letters in alphabetic order
#
while getopts ":c:g:hp:s:v:" OPTION
do
case $OPTION in
c)
runcmd "$OPTARG"
;;
g)
getinfo "$OPTARG"
;;
h)
usage
exit 1
;;
p)
setplaylist "$OPTARG"
;;
v)
setvolume "$OPTARG"
;;
esac
done
}
main $@