[RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...)

  Thread Rating:
  • 3 Votes - 4.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
pilluli Offline
Fan
Posts: 340
Joined: Jul 2006
Reputation: 1
Post: #31
(2013-06-12 14:40)matbor Wrote:  * I can't run any python script from the commandline (via SSH), but I think that is because I use ATV2's (correct me if i'm wrong here)

I have the impression that this is indeed the problem. You should be able to execute the scripts from the command line for the addon to work. Could you first try to make them executable? So something like:


Code:
chmod +x  xbmc_play.py
./xbmc_play.py

That should work, if not, make sure you have python installed correctly in your system:

Code:
/usr/bin/env python

That should start python (via command line)!

Hope it helps..
find quote
matbor Offline
Senior Member
Posts: 147
Joined: Jun 2004
Reputation: 0
Location: Melbourne, Australia
Post: #32
Yeah, no python installed as it doesn't work from the cli, but how come all my scripts work from within XBMC then? is this something to do with how your plugin works?

list of packages installed.



I wonder if changing your code from using;

subprocess.Popen([script_player_starts,self.playing_type()])

to;

xbmc.executebuiltin('XBMC.RunScript([script_player_starts,self.playing_type()])')

http://wiki.xbmc.org/index.php?title=Bui..._Functions
http://wiki.xbmc.org/index.php?title=Lis..._functions

might fix it, will have a play tonight.

Thx
Matt.

4x ATV2's (v4.3) XBMC Frodo12.2. Raspberry Pi running MYSQL 5.5.31-0+wheezy1. NAS is a Drobo FS
(This post was last modified: 2013-06-24 03:33 by matbor.)
find quote
pilluli Offline
Fan
Posts: 340
Joined: Jul 2006
Reputation: 1
Post: #33
(2013-06-13 03:52)matbor Wrote:  Yeah, no python installed as it doesn't work from the cli, but how come all my scripts work from within XBMC then? is this something to do with how your plugin works?

That is because XBMC installs its own python. One solution is to find the python installed by XBMC in your ATV2 machine and change the first line of your scripts to point to that file (without the env command)

Quote:I wonder if changing your code from using;

subprocess.Popen([script_player_starts,self.playing_type()])

to;

xbmc.executebuiltin('XBMC.RunScript([script_player_starts,self.playing_type()])')

might fix it, will have a play tonight.


Might work but that will only accept python scripts though...

Regards,
find quote
matbor Offline
Senior Member
Posts: 147
Joined: Jun 2004
Reputation: 0
Location: Melbourne, Australia
Post: #34
So on the ATV2, you need to use the xbmc.executebuiltin instead of subprocess.popen, as per my previous post.

Only problem I had was getting the variables to work from settings.xml so in the end I just hard coded it into default.py, not going to change it anytime some! And I have removed what is playing part for now.

Example of one of the sections I edited to get it working for me on my ATV2;
Code:
def onPlayBackStarted(self):
    log('player starts')
    global script_player_starts
    if script_player_starts:
      log('Going to execute script abcdefghij= "' + script_player_starts + '"')
      #subprocess.Popen([script_player_starts,self.playing_type()])
      xbmc.executebuiltin('XBMC.RunScript(special://masterprofile/scripts/xbmc_play.py)')

Thanks for the script!

Matt.

4x ATV2's (v4.3) XBMC Frodo12.2. Raspberry Pi running MYSQL 5.5.31-0+wheezy1. NAS is a Drobo FS
(This post was last modified: 2013-06-24 03:34 by matbor.)
find quote
getsome Offline
Junior Member
Posts: 38
Joined: Aug 2011
Reputation: 0
Post: #35
This is a winner.
find quote
sIRwa2 Offline
Member
Posts: 69
Joined: Oct 2008
Reputation: 0
Post: #36
Great Addon! im using it together with UsbIrToy to shutdown my amp on screen saver. but i love if i could choose for "display to sleep" to invoke a script. Did you manage to look into that yet Piluli?

(2013-03-29 19:45)pilluli Wrote:  
(2013-03-29 16:40)mbw2001 Wrote:  Would it be possible to catch the "Put display to sleep when idle" from Power Saving?

I am currently powering down my projector when the screen saver is activated, but i would like to be able to use Dim for screen saver and only poweroff the projector when idle.

Sorry don't really understand. You don't want to use the "screensaver start" callback but another one which is related to the "put display to sleep"??

I don't know if xbmc publishes that callback to addons though... But I'll check anyway...
find quote
ctshh Offline
Junior Member
Posts: 4
Joined: Jun 2012
Reputation: 0
Post: #37
Do you think it would be possible to add "when entering a favorite" to the script; eg. call the script when a certain favorite is called?
find quote
pilluli Offline
Fan
Posts: 340
Joined: Jul 2006
Reputation: 1
Post: #38
(2013-06-25 20:19)sIRwa2 Wrote:  Great Addon! im using it together with UsbIrToy to shutdown my amp on screen saver. but i love if i could choose for "display to sleep" to invoke a script. Did you manage to look into that yet Piluli?

Happy it works for you. I did look at the "display to sleep" but unfortunately there is no functionality as a callback in XBMC so not possible to implement. My recommendation maybe is to use the "on screensaver" and then use a sleep command in the script to wait for some second to activate anything...


(2013-06-26 09:54)ctshh Wrote:  Do you think it would be possible to add "when entering a favorite" to the script; eg. call the script when a certain favorite is called?

Do you mean calling a script when a favourite is started? Sorry but again XBMC does not provide that functionality Sad However, would it help if the name of the file being called is provided?

Regards,
find quote
sIRwa2 Offline
Member
Posts: 69
Joined: Oct 2008
Reputation: 0
Post: #39
thanks for your answer,

Interesting idea, I could but in a timer in my py script,so it runs irtoy after, say, 10 minuts. but then i need the posibility to cancel the timer on screensaver off...

can this be done? like firing a second script to cancel the first? im not a programmer.
find quote
matbor Offline
Senior Member
Posts: 147
Joined: Jun 2004
Reputation: 0
Location: Melbourne, Australia
Post: #40
Thanks for the script, have got my 4x XBMC's publishing there status using MQTT to a MQTT Broker, screenshot here... more to come....

4x ATV2's (v4.3) XBMC Frodo12.2. Raspberry Pi running MYSQL 5.5.31-0+wheezy1. NAS is a Drobo FS
(This post was last modified: 2013-06-27 03:41 by matbor.)
find quote
pilluli Offline
Fan
Posts: 340
Joined: Jul 2006
Reputation: 1
Post: #41
(2013-06-26 20:40)sIRwa2 Wrote:  thanks for your answer,

Interesting idea, I could but in a timer in my py script,so it runs irtoy after, say, 10 minuts. but then i need the posibility to cancel the timer on screensaver off...

can this be done? like firing a second script to cancel the first? im not a programmer.

Maybe the easiest thing would be to create two scripts.

The first script responds to the screensaver off and just creates a file in a temporal folder:

* Script when screensaver is off
Code:
#/bin/sh
touch /tmp/screensaver_off

The second one responds to screensaver on and removes the previous file, waits for 10min and then rechecks the existence of the file before performing anything...

* Script when screensaver is on
Code:
#/bin/sh
rm /tmp/screensaver_off
sleep 10m
if [ -e /tmp/screensaver_off ]; then
# Do whatever you need here
fi


PS: I am just writing that scripts by heart so they might not have the correct syntax! Also I am assuming linux/mac so /bin/sh works and there is a /tmp folder but you can do a similar thing in any scripting language (python, etc.) and in any folder you want.


(2013-06-27 03:40)matbor Wrote:  Thanks for the script, have got my 4x XBMC's publishing there status using MQTT to a MQTT Broker, screenshot here... more to come....

Nice! sounds like a cool project!! Nod
(This post was last modified: 2013-06-27 10:29 by pilluli.)
find quote
sIRwa2 Offline
Member
Posts: 69
Joined: Oct 2008
Reputation: 0
Post: #42
Tnx piluli, i was talking with a programmer at work just now and he suggested a similar solution, sounds like a nice project for me to keep busy Smile

who knows, might even learn some programming along the way Wink
find quote
sIRwa2 Offline
Member
Posts: 69
Joined: Oct 2008
Reputation: 0
Post: #43
hm.. interesting, First of all, tnx again for the code, they work as a dream, i did reverse it a bit thought. Screensaver on> makes temp file..sleep 10m, if temp file exists> execute. Screensaver off> delete temp file.

but now error: Sad

Code:
21:12:13 T:2774530880  NOTICE: Previous line repeats 2 times.
21:12:13 T:2774530880   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.OSError'>
                                            Error Contents: [Errno 8] Exec format error
                                            Traceback (most recent call last):
                                              File "/home/xbmc/.xbmc/addons/service.xbmc.callbacks-0.2/default.py", line 108, in onScreensaverActivated
                                                subprocess.Popen([script_screensaver_starts,self.get_player_status()])
                                              File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
                                                errread, errwrite)
                                              File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
                                                raise child_exception
                                            OSError: [Errno 8] Exec format error
                                            -->End of Python script error report<--

i have 2 callback entries, on screens on and off. both bash scripts that work from terminal.

Code:
-rwxrwxr-x  1 xbmc xbmc       131 Jul  1 22:10 power.sh and
-rwxrwxr-x  1 xbmc xbmc        33 Jul  1 22:01 delete_screen_tmp_file.sh

love to hear some input..
find quote
matbor Offline
Senior Member
Posts: 147
Joined: Jun 2004
Reputation: 0
Location: Melbourne, Australia
Post: #44
Had a quick google around for you, this is probably the same problem you have.... http://stackoverflow.com/questions/48344...ide-python

4x ATV2's (v4.3) XBMC Frodo12.2. Raspberry Pi running MYSQL 5.5.31-0+wheezy1. NAS is a Drobo FS
find quote
sIRwa2 Offline
Member
Posts: 69
Joined: Oct 2008
Reputation: 0
Post: #45
thank you for thaing the time, i also dig around a little, but i have the feeling this is an rather generic error, and may have to do with incorrect path names or something.. i looked at all my scripts, couldn't really find anything out of the ordinary.

ill dig some more this weekend.
find quote
Post Reply