Forum

Full Version: read out XBMC play, pause stop status
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
hello,
i'm working on comining home automitation and media, i found this little script

#!/bin/bash
xbmcurl="http://pc-tv/jsonrpc"


previousvideoplaying=0
while [ 1 ]
do


wget -q -O- --header='Content-Type: application/json' --post-data='{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}' $xbmcurl | grep -v '"video"' > /dev/null
video=$?
wget -q -O- --header='Content-Type: application/json' --post-data='{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": { "playerid": 1, "properties": ["speed"] }, "id": 1}' $xbmcurl | grep '"speed":0' > /dev/null
playing=$?
#echo "video=$video playing=$playing"


if [ $video == 1 ] && [ $playing = 1 ]; then
# echo "Video Playing!"
if [ $previousvideoplaying == 1 ]; then
echo "Video Playing, dimming ligths!"
kaku 123 1 dim 4
fi
previousvideoplaying=1
else
if [ $previousvideoplaying == 1 ]; then
echo "Video Stopped, brighting ligths!"
kaku 123 1 dim 8;

previousvideoplaying=0
fi

done

it only keeps saying "video playing, dimming lights" and dimm my light, i'm running
433Mhzdeamon in no hup ( https://github.com/jeroensteenhuis/433mhzforrpi )

am i missing anything?
luke,

XBian has in core system whole workflow already based on XBMC events.

check /var/log/upstart-xbmc-bridge.log file and you will see generated upstart events.
line like this
Code:
23/01/2014 20:53:08 Send event: ['initctl', 'emit', '-n', 'player', 'ACTION=STOP', 'TYPE=episode']

means there was generated event "player" with action "stop" and the played item was "episode" (tv show).

check
Code:
/usr/local/sbin/upstart-xbmc-bridge.py

for short howto
(26th Jan, 2014 01:12 AM)mk01 Wrote: [ -> ]luke,

XBian has in core system whole workflow already based on XBMC events.

check /var/log/upstart-xbmc-bridge.log file and you will see generated upstart events.
line like this
Code:
23/01/2014 20:53:08 Send event: ['initctl', 'emit', '-n', 'player', 'ACTION=STOP', 'TYPE=episode']

means there was generated event "player" with action "stop" and the played item was "episode" (tv show).

check
Code:
/usr/local/sbin/upstart-xbmc-bridge.py

for short howto
okay, i'm terrible noob, if you can please make me a verry basic script, i can fill it with thing i learned from xbmc-bridge but i dont think i can do it alone...
then start with something like this

create /etc/init/xbmc-events.conf
Code:
start on screensaver or player or library
task

script
    case $UPSTART_EVENTS in
         screensaver)
                 ;;
         player)
                 if [ $ACTION = START ]; then
                     echo "Video Playing, dimming ligths!"
                      kaku 123 1 dim 4
                 else
                      echo "Video Stopped, brighting ligths!"
                      kaku 123 1 dim 8;
                 fi
                 ;;
         library)
                 ;;
         *)
               ;;
     esac

end script
(26th Jan, 2014 03:26 AM)mk01 Wrote: [ -> ]then start with something like this

create /etc/init/xbmc-events.conf
Code:
start on screensaver or player or library
task

env UPSTART_EVENTS
env ACTION
env TYPE

script
    case $UPSTART_EVENT in
         screensaver)
                 ;;
         player)
                 if [ $ACTION = START ]; then
                     echo "Video Playing, dimming ligths!"
                      kaku 123 1 dim 4
                 else
                      echo "Video Stopped, brighting ligths!"
                      kaku 123 1 dim 8;
                 fi
                 ;;
         library)
                 ;;
         *)
               ;;
     esac

end script
okay, how to start it? sudo ./ says commands not found
when i took a look at the event file i saw you could specify the type playing (tv show movie audio)
then i can set that playing movie won't kill the lights, and if i want to set another value like pause , would it be

if [ $ACTION = START ]; then
echo "Video Playing, dimming ligths!"
kaku 123 1 dim 4
elseif [$ACTION = PAUSE]; then
echo "video paused, brighting lights!"
kaku 123 1 dim 7
else
echo "Video Stopped, brighting ligths!"
kaku 123 1 dim 8;
fi


i know that in this case it doesn't matter much but its more for understanding what i write...

Thanks a lot
yes. you got the point.

it is more than likely that there are even more types XBMC is sending, …

you can put before the "case" statement like:

Code:
echo "$(date) $UPSTART_EVENTS $ACTION $TYPE >> /tmp/events.log

and you will see all what you received
(26th Jan, 2014 05:17 AM)mk01 Wrote: [ -> ]yes. you got the point.

it is more than likely that there are even more types XBMC is sending, …

you can put before the "case" statement like:

Code:
echo "$(date) $UPSTART_EVENTS $ACTION $TYPE >> /tmp/events.log

and you will see all what you received

Hmm how to start te script?
there is nothing to start. it will be started when needed.

XBMC send event -> xbmc-bridge-upstart.py receives -> xbmc-bridge-upstart.py transforms and created UPSTART event -> upstart knows from the .conf file that that one is interested in events screensaver, player, library and will run the script. the
script will immediately finish and wait for next event
(26th Jan, 2014 05:23 AM)mk01 Wrote: [ -> ]there is nothing to start. it will be started when needed.

XBMC send event -> xbmc-bridge-upstart.py receives -> xbmc-bridge-upstart.py transforms and created UPSTART event -> upstart knows from the .conf file that that one is interested in events screensaver, player, library and will run the script. the
script will immediately finish and wait for next event

Hmmm il try again tomorrow didnt't work, maybe a typo in the command...
And how to specify play type (audio movie tv show)

Edit: shouldn't there be a ";" after the first time dim 4 ?
Olay, i edited the script with the given log code ( i only changed it to log to my home dir)
It's added with this post, did I do it wrong , it doesn't make a log after watching a movie?
we forgot to make the variables available to script:

Code:
env UPSTART_EVENTS
env ACTION
env TYPE

put it anywhere outside the "script ….. end script" definition

(i updated the original post for reference)
(26th Jan, 2014 11:10 PM)mk01 Wrote: [ -> ]we forgot to make the variables available to script:

Code:
env UPSTART_EVENTS
env ACTION
env TYPE

put it anywhere outside the "script ….. end script" definition

(i updated the original post for reference)
(27th Jan, 2014 12:53 AM)lukeg01 Wrote: [ -> ]
(26th Jan, 2014 11:10 PM)mk01 Wrote: [ -> ]we forgot to make the variables available to script:

Code:
env UPSTART_EVENTS
env ACTION
env TYPE

put it anywhere outside the "script ….. end script" definition

(i updated the original post for reference)
It still doesn't work?
Where to put the log rule, then i can see if it at least recieve the status change
check /run/upstart-ev.log

in that file you will see EACH job and its state changes when triggered. that means, you should at least see that it is being called. I just copied the script from my post #5, saved under the name as shown there and started a video. immediately I have events generated.


Code:
14273.86 4753.61 started xbmc-events                      0.23 0.55 0.81 4/197 4929
14273.97 4753.61 stopped xbmc-events                      0.23 0.55 0.81 6/201 4939
14274.10 4753.61 started xbmc-priority                    0.23 0.55 0.81 6/201 4953
14274.26 4753.61 stopped xbmc-screensaver                 0.23 0.55 0.81 4/197 4961
14274.38 4753.61 stopped xbmc-priority                    0.23 0.55 0.81 3/195 4966
14352.33 4764.25 started xbian-xbmc-player                1.46 0.81 0.88 5/209 5018
14352.34 4764.25 started xbmc-events                      1.46 0.81 0.88 4/206 5018
14352.48 4764.25 stopped xbmc-events                      1.46 0.81 0.88 4/204 5023
14352.67 4764.25 started xbmc-priority                    1.46 0.81 0.88 4/206 5030
14352.96 4764.25 stopped xbmc-priority                    1.59 0.85 0.89 3/204 5036
14358.65 4764.25 stopped xbian-xbmc-player                1.62 0.87 0.89 6/206 5049
14358.66 4764.25 started xbmc-events                      1.62 0.87 0.89 6/206 5049
14358.82 4764.25 stopped xbmc-events                      1.62 0.87 0.89 5/201 5054

JUST ONE CORRECTION INDEED:

case $UPSTART_EVENT in => case $UPSTART_EVENTS in

eventS, not event. everywhere else is correct.
(3rd Feb, 2014 06:32 AM)mk01 Wrote: [ -> ]check /run/upstart-ev.log

in that file you will see EACH job and its state changes when triggered. that means, you should at least see that it is being called. I just copied the script from my post #5, saved under the name as shown there and started a video. immediately I have events generated.


Code:
14273.86 4753.61 started xbmc-events                      0.23 0.55 0.81 4/197 4929
14273.97 4753.61 stopped xbmc-events                      0.23 0.55 0.81 6/201 4939
14274.10 4753.61 started xbmc-priority                    0.23 0.55 0.81 6/201 4953
14274.26 4753.61 stopped xbmc-screensaver                 0.23 0.55 0.81 4/197 4961
14274.38 4753.61 stopped xbmc-priority                    0.23 0.55 0.81 3/195 4966
14352.33 4764.25 started xbian-xbmc-player                1.46 0.81 0.88 5/209 5018
14352.34 4764.25 started xbmc-events                      1.46 0.81 0.88 4/206 5018
14352.48 4764.25 stopped xbmc-events                      1.46 0.81 0.88 4/204 5023
14352.67 4764.25 started xbmc-priority                    1.46 0.81 0.88 4/206 5030
14352.96 4764.25 stopped xbmc-priority                    1.59 0.85 0.89 3/204 5036
14358.65 4764.25 stopped xbian-xbmc-player                1.62 0.87 0.89 6/206 5049
14358.66 4764.25 started xbmc-events                      1.62 0.87 0.89 6/206 5049
14358.82 4764.25 stopped xbmc-events                      1.62 0.87 0.89 5/201 5054

JUST ONE CORRECTION INDEED:

case $UPSTART_EVENT in => case $UPSTART_EVENTS in

eventS, not event. everywhere else is correct.

i got
Code:
173.68 0.61 started xbian-xbmc-player                2.83 1.59 0.63 7/203 2660
173.68 0.61 started xbmc-events                      2.83 1.59 0.63 7/203 2660
173.89 0.61 stopped xbmc-events                      2.83 1.59 0.63 6/201 2664
174.17 0.61 started xbmc-priority                    2.83 1.59 0.63 7/203 2670
174.79 0.61 stopped xbmc-priority                    2.83 1.59 0.63 5/202 2678
257.74 0.61 stopped xbian-xbmc-player                3.57 2.16 0.92 6/204 3278
257.76 0.61 started xbmc-events                      3.57 2.16 0.92 5/204 3278
257.96 0.61 stopped xbmc-events                      3.57 2.16 0.92 5/202 3282
258.20 0.61 started xbmc-priority                    3.57 2.16 0.92 4/203 3288
258.65 0.61 stopped xbmc-priority                    3.57 2.16 0.92 4/201 3295
but loggin in /tmp/ does not work.... i have put it between [script] and [case]
Pages: 1 2 3
Reference URL's