Kodi Community Forum
[RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: Add-on Support (https://forum.kodi.tv/forumdisplay.php?fid=27)
+---- Forum: Service Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=152)
+---- Thread: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) (/showthread.php?tid=151011)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - pilluli - 2013-06-12

(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..


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - matbor - 2013-06-13

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=Built-in_scripting#List_of_Built_In_Functions
http://wiki.xbmc.org/index.php?title=List_of_built-in_functions

might fix it, will have a play tonight.

Thx
Matt.


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - pilluli - 2013-06-13

(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,


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - matbor - 2013-06-22

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.


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - getsome - 2013-06-24

This is a winner.


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - sIRwa2 - 2013-06-25

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...



RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - ctshh - 2013-06-26

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?


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - pilluli - 2013-06-26

(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,


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - sIRwa2 - 2013-06-26

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.


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - matbor - 2013-06-27

Thanks for the script, have got my 4x XBMC's publishing there status using MQTT to a MQTT Broker, screenshot here... more to come....


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - pilluli - 2013-06-27

(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


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - sIRwa2 - 2013-06-27

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


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - sIRwa2 - 2013-07-03

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..


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - matbor - 2013-07-04

Had a quick google around for you, this is probably the same problem you have.... http://stackoverflow.com/questions/4834483/is-this-the-right-way-to-run-a-shell-script-inside-python


RE: [RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...) - sIRwa2 - 2013-07-04

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.