README, minor corrections
[BABOOSHKA.TV] / dbuscontrol.sh
1 #!/bin/bash
2
3 #set -x
4
5 OMXPLAYER_DBUS_ADDR="/tmp/omxplayerdbus.${USER:-root}"
6 OMXPLAYER_DBUS_PID="/tmp/omxplayerdbus.${USER:-root}.pid"
7
8 # OMXPLAYER_DBUS_ADDR="/tmp/omxplayerdbus.pi"
9 # OMXPLAYER_DBUS_PID="/tmp/omxplayerdbus.pi.pid"
10
11 export DBUS_SESSION_BUS_ADDRESS=`cat $OMXPLAYER_DBUS_ADDR`
12 export DBUS_SESSION_BUS_PID=`cat $OMXPLAYER_DBUS_PID`
13
14 [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && { echo "Must have DBUS_SESSION_BUS_ADDRESS" >&2; exit 1; }
15
16 case $1 in
17         status)
18                 duration=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:"org.mpris.MediaPlayer2.Player" string:"Duration"`
19                 [ $? -ne 0 ] && exit 1
20                 duration="$(awk '{print $2}' <<< "$duration")"
21
22                 position=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:"org.mpris.MediaPlayer2.Player" string:"Position"`
23                 [ $? -ne 0 ] && exit 1
24                 position="$(awk '{print $2}' <<< "$position")"
25
26                 playstatus=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:"org.mpris.MediaPlayer2.Player" string:"PlaybackStatus"`
27                 [ $? -ne 0 ] && exit 1
28                 playstatus="$(sed 's/^ *//;s/ *$//;' <<< "$playstatus")"
29
30                 paused="true"
31                 [ "$playstatus" == "Playing" ] && paused="false"
32                 echo "Duration: $duration"
33                 echo "Position: $position"
34                 echo "Paused: $paused"
35                 ;;
36
37         volume)
38                 volume=`dbus-send --print-reply=double --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Set string:"org.mpris.MediaPlayer2.Player" string:"Volume" ${2:+double:}$2`
39                 [ $? -ne 0 ] && exit 1
40                 volume="$(awk '{print $2}' <<< "$volume")"
41                 echo "Volume: $volume"
42                 ;;
43
44         list)   # list dbus interfaces
45
46                 dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
47 #               dbus-send --print-reply=literal --type=method_call --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2  org.freedesktop.DBus.Introspectable.Introspect
48                 ;;
49
50         pause)
51                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:16 >/dev/null
52                 ;;
53
54         info)   # doesn't work IMHO
55                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:5
56                 ;;
57
58         action) # universal  
59                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:$2 >/dev/null
60                 ;;
61
62 #       -----------------------------------------------
63
64         subslist)
65                 subslist=`dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.ListSubtitles`
66 #               [ $? -ne 0 ] && exit 1
67                 echo "$subslist" | grep string
68                 ;;
69
70         togglesubtitles)
71                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:12 >/dev/null
72                 ;;
73                 
74         hidesubtitles)
75                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:30 >/dev/null
76                 ;;
77
78         showsubtitles)
79                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:31 >/dev/null
80                 ;;
81         subsnext)
82                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:11 >/dev/null
83                 ;;
84         subsprev)
85                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:10 >/dev/null
86                 ;;
87
88 #       -----------------------------------------------
89
90         audiolist)
91                 audiolist=`dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.ListAudio`
92 #               [ $? -ne 0 ] && exit 1
93                 echo "$audiolist" | grep string
94                 ;;
95
96         audiom)
97                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:6 >/dev/null
98                 ;;
99
100         audiop)
101                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:7 >/dev/null
102                 ;;
103
104 #       -----------------------------------------------
105
106         seekfl) # seek forward large step
107                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:22 >/dev/null
108                 ;;
109
110         seekbl) # seek backward large step
111                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:21 >/dev/null
112                 ;;
113
114         seekf)  # seek forward large step
115                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:20 >/dev/null
116                 ;;
117
118         seekb)  # seek backward large step
119                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:19 >/dev/null
120                 ;;
121
122 #       -----------------------------------------------
123
124         stop)
125                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:15 >/dev/null
126                 ;;
127
128         seek)
129                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek int64:$2 >/dev/null
130                 ;;
131
132         setposition)
133                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetPosition objpath:/not/used int64:$2 >/dev/null
134                 ;;
135
136         setalpha)
137                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetAlpha objpath:/not/used int64:$2 >/dev/null
138                 ;;
139
140         setvideopos)
141                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.VideoPos objpath:/not/used string:"$2 $3 $4 $5" >/dev/null
142                 ;;
143
144         setvideocroppos)
145                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetVideoCropPos objpath:/not/used string:"$2 $3 $4 $5" >/dev/null
146                 ;;
147
148         setaspectmode)
149                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetAspectMode objpath:/not/used string:"$2" >/dev/null
150                 ;;
151
152         hidevideo)
153                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:28 >/dev/null
154                 ;;
155
156         unhidevideo)
157                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:29 >/dev/null
158                 ;;
159
160         volumeup)
161                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:18 >/dev/null
162                 ;;
163
164         volumedown)
165                 dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:17 >/dev/null
166                 ;;
167                 
168         getsource)
169                 source=$(dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.GetSource)
170                 echo "$source" | sed 's/^ *//'
171                 ;;
172         *)
173                 echo "usage: $0 status|pause|stop|seek|volumeup|volumedown|setposition [position in microseconds]|hidevideo|unhidevideo|togglesubtitles|hidesubtitles|showsubtitles|setvideopos [x1 y1 x2 y2]|setvideocroppos [x1 y1 x2 y2]|setaspectmode [letterbox,fill,stretch,default]|setalpha [alpha (0..255)]|getsource" >&2
174                 exit 1
175                 ;;
176 esac
Contact me: dev (at) shalnoff (dot) com
PGP fingerprint: A6B8 3B23 6013 F18A 0C71 198B 83D8 C64D 917A 5717