README, minor corrections
[BABOOSHKA.TV] / remoteir.sh
1 #!/bin/bash
2
3 irw > /tmp/remote_command &
4
5 CCONTROL_PID=$!
6
7 # BABOOSHKA_HOME=/home/pi       # assigned in start.babooshka.sh
8
9 DBUS_CTRL_FILE=/tmp/dbuscontrol_command
10 SAVEPATH=$BABOOSHKA_HOME
11
12 # --------------------------------------
13
14 killCCONTROL() {        # function called by trap (Ctrl-C handler)
15
16         echo CCONTROL_PID $CCONTROL_PID
17
18         kill -9 $CCONTROL_PID 2> /dev/null
19         echo "Have a nice day..."
20         exit 0
21 }
22
23 trap 'killCCONTROL' 2
24
25 # --------------------------------------
26
27 beep (){
28         play -n synth sin %41 fade q 0.0 0.1 0.01 gain -25 &>/dev/null </dev/null &
29 }
30
31 prevData=0
32 musicPlay=0
33 pressCnt=0
34
35 while [ 1 ]; do
36
37         data=$(stdbuf -i0 -o0 -e0 tail -1 /tmp/remote_command | awk -F' ' '{print $3; exit}' | xargs )
38
39         pressCnt=$(($pressCnt + 1))
40
41         # ---- note repeatable -----
42
43         if [ "$prevData" != "$data" ]; then
44         
45                 case "$data" in
46                         "qqqq")
47                                 $BABOOSHKA_HOME/dbuscontrol.sh stop
48                                 echo qqqq
49                         ;;
50                         "wwww")
51                                 echo wwww
52                         ;;
53                 esac
54
55                 prevData=$data
56         fi 
57
58         # ---- repeatable ---------
59
60         case "$data" in
61
62                         # next
63
64                         "ARR_DOWN")
65                                 beep
66                                 echo "NEXT" > "$DBUS_CTRL_FILE"
67                                 $BABOOSHKA_HOME/dbuscontrol.sh stop
68                                 echo "NEXT"
69                         ;;
70
71                         # prev
72
73                         "ARR_UP")
74                                 beep
75                                 echo "PREV" > "$DBUS_CTRL_FILE"
76                                 $BABOOSHKA_HOME/dbuscontrol.sh stop
77                                 echo "PREV"
78                         ;;
79
80                         # forward +10min
81
82                         "ARR_RIGHT")
83                                 beep
84                                 echo "NEXT" > "$DBUS_CTRL_FILE"
85                                 $BABOOSHKA_HOME/dbuscontrol.sh seekfl
86                                 echo ">>"
87                         ;;
88
89                         # backward -10min
90
91                         "ARR_LEFT")
92                                 beep
93                                 $BABOOSHKA_HOME/dbuscontrol.sh seekbl
94                                 echo "<<"
95                         ;;
96
97                         # play/pause toggle
98
99                         "ARR_OK")
100                                 beep
101                                 status=$(./dbuscontrol.sh status 2>/dev/null)
102
103                                 if [ "$status" != "" ]; then
104                                         position=$( echo "$status" | grep Position | awk '{split($0,a,":"); print a[2]}' )
105                                         position=$(( $position / (1000000) ))   # sec
106                                         echo $position > $SAVEPATH/currentpos
107                                         paused=$( echo "$status" | grep Paused | awk '{split($0,a,":"); print a[2]}' | xargs )
108                                 fi
109
110                                 if [ "$paused" == "true" ] || [ "$status" == "" ]; then # has been paused 
111                                         echo "PLAY"
112                                         if [ "$status" == "" ]; then echo "PLAY" > "$DBUS_CTRL_FILE"; fi
113                                 else 
114                                         echo "PAUSE"
115                                 fi
116                                 $BABOOSHKA_HOME/dbuscontrol.sh pause
117                         ;;
118
119
120                         # pause on switching-off
121
122                         "EXT"|"ON_OFF") # AV or ON_OFF
123                                 beep
124
125                                 status=$(./dbuscontrol.sh status 2>/dev/null)
126
127                                 if [ "$status" != "" ]; then
128                                         position=$( echo "$status" | grep Position | awk '{split($0,a,":"); print a[2]}' )
129                                         position=$(( $position / (1000000) ))   # sec
130                                         echo $position > $SAVEPATH/currentpos
131                                         paused=$( echo "$status" | grep Paused | awk '{split($0,a,":"); print a[2]}' | xargs )
132                                 fi
133
134 #                               paused=$( echo "$status" | grep Paused | awk '{split($0,a,":"); print a[2]}' | xargs )
135
136                                 if [ "$paused" == "false" ]; then # not paused 
137                                         $BABOOSHKA_HOME/dbuscontrol.sh pause
138 #                                       echo "$status" > status
139                                         echo "PAUSED"
140                                 fi
141                                 echo "AV or ON-OFF"
142                         ;;
143
144                         # stop
145
146                         "KEY_TEXT")
147                                 beep
148
149                                 status=$(./dbuscontrol.sh status 2>/dev/null)
150
151                                 if [ "$status" != "" ]; then
152                                         position=$(echo "$status" | grep Position | awk '{split($0,a,":"); print a[2]}' )
153                                         position=$(( $position / (1000000) ))   # sec
154                                         echo $position > $SAVEPATH/currentpos
155
156                                         echo "STOP" > "$DBUS_CTRL_FILE"
157                                         $BABOOSHKA_HOME/dbuscontrol.sh stop
158                                         echo "STOP"
159                                 else
160                                         echo "STOP / NOT PLAYING"
161                                 fi
162
163                         ;;
164
165                         # audio track switch            
166
167                         "KEY_RED")
168                                 audioTracks=$( $BABOOSHKA_HOME/dbuscontrol.sh audiolist 2>/dev/null ) 
169                                 trackCnt=$( echo "$audioTracks" | sed '/^\s*$/d' | wc -l )
170                                 currentTrack=$( echo "$audioTracks" | awk '/active/{ print NR; exit }' )
171                                 beep
172                                 if [ "$trackCnt" != "0" ]; then
173                                         if [ "$currentTrack" -lt "$trackCnt" ]; then 
174                                                 $BABOOSHKA_HOME/dbuscontrol.sh audiop
175                                                 echo "AUDIO CHANGE" 
176                                         else 
177                                                 for var in $audioTracks; do
178                                                         $BABOOSHKA_HOME/dbuscontrol.sh audiom
179                                                 done 
180                                                 echo "AUDIO REVIND"
181                                         fi 
182                                 fi
183                                 echo "AUDIO: $trackCnt, $currentTrack"
184                         ;;
185
186                         # subtitles switch              
187
188                         "KEY_YELLOW")
189                                 subsTracks=$( $BABOOSHKA_HOME/dbuscontrol.sh subslist 2>/dev/null ) 
190                                 subsCnt=$( echo "$subsTracks" | sed '/^\s*$/d' | wc -l )
191                                 currentSub=$( echo "$subsTracks" | awk '/active/{ print NR; exit }' )
192                                 beep
193                                 if [ "$subsCnt" != "0" ]; then
194                                         if [ "$currentSub" -lt "$subsCnt" ]; then 
195                                                 $BABOOSHKA_HOME/dbuscontrol.sh subsnext
196                                                 echo "SUBS CHANGE" 
197                                         else 
198                                                 if [ "$subsOff" != "1" ]; then 
199                                                         $BABOOSHKA_HOME/dbuscontrol.sh hidesubtitles
200                                                         subsOff=1
201                                                         echo "SUBS HIDE"
202                                                 else  
203                                                         $BABOOSHKA_HOME/dbuscontrol.sh showsubtitles
204                                                         for var in $subsTracks; do
205                                                                 $BABOOSHKA_HOME/dbuscontrol.sh subsprev
206                                                         done 
207                                                         subsOff=0
208                                                         echo "SUBS REVIND"
209                                                 fi
210                                         fi 
211                                 fi
212                                 echo "SUBS: $subsCnt, $currentSub"
213                         ;;
214
215                         *)
216 #                               echo ------
217                         ;;
218         esac
219
220         : > /tmp/remote_command
221
222         sleep 0.5
223 done
224
225
226
227
228
Contact me: dev (at) shalnoff (dot) com
PGP fingerprint: A6B8 3B23 6013 F18A 0C71 198B 83D8 C64D 917A 5717