•   
  • 1
  • 5
  • 6
  • 7(current)
  • 8
  • 9
  • 23
  •   
[RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...)
#91
(2014-03-10, 10:28)flarc Wrote: Hello, thanks for your helps.

1) Ok, so currently, my settings.xml is like this:
Code:
<setting id="player_pauses" value="C:\sarah\plugins\fred\bin\huelight_high.bat" />

And the "huelight_high.bat" is like that:
Code:
@echo off
c:
cd C:\sarah\plugins\fred\bin
curl http://192.168.1.21/api/newdeveloper/lights/1/state -X PUT -d "{\"on\":true, \"bri\":228}" >> NUL

This works, but i see a brief console window appear.

2) I tried also this (xml manually edited because .vbs is not displayed in xbmc add-on configuration screen):

settings.xml:
Code:
<setting id="player_pauses" value="C:\sarah\plugins\fred\bin\huelight_high.vbs" />

huelight_high.vbs:
Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
cmd = "C:\sarah\plugins\fred\bin\huelight_high.bat"
Return = WshShell.Run(cmd, 0, True)
set WshShell = Nothing

The huelight_high.bat is unchanged.

If i run manually the vbs, it works without console appearing.
But within XBMC, the command is not performed (which i can see only due to no change of light)

Does not work either with:
settings.xml:
Code:
<setting id="player_pauses" value="wscript C:\sarah\plugins\fred\bin\huelight_high.vbs" />

3) I also tried compiling the .bat into .exe, and updating accordingly the settings.xml, but does not work either.
Code:
<setting id="player_pauses" value="C:\sarah\plugins\fred\bin\huelight_high.exe" />

4) I did not try yet to put directly the long curl command into the settings.xml (i need to see how to manage the quotes within the command).

5) Last thing i would try (but i do not know yet how to do it) is calling directly a python script (that would be interpreted by xbmc's own python lib) to change hue lights.

If you have an idea to make option#1 or #2 work, it would be helpful, because i would prefer those ways of doing it. But if option#5 would work, i will take it.

The way the plugin is currently written, it does not parse the string 'wscript C:\..\huelight_high.vbs' into two separate arguments to be passed to subprocess.call().
And that python call needs the 'wscript' argument to be passed because it is being called without the shell=true option.
If I have time I might fork the master branch and come up with a way to parameterize the strings for interpretation. Something along the lines of enclosing each individual parameter in curly brackets and then have the script parse them into a tuple that can be passed in subprocess.call().

Maybe pilluli can weigh in at some point...
Reply
#92
(2014-03-10, 18:00)KenV99 Wrote: The way the plugin is currently written, it does not parse the string 'wscript C:\..\huelight_high.vbs' into two separate arguments to be passed to subprocess.call().
And that python call needs the 'wscript' argument to be passed because it is being called without the shell=true option.
If I have time I might fork the master branch and come up with a way to parameterize the strings for interpretation. Something along the lines of enclosing each individual parameter in curly brackets and then have the script parse them into a tuple that can be passed in subprocess.call().

Maybe pilluli can weigh in at some point...


Indeed KenV99 is right, the addon does not support adding arguments to scripts. flarc, can you try this:

Go to the "default.py" file in the service.xbmc.callbacks addon (let me know if you cannot find the file) and substitute the line:

Code:
subprocess.call([script_player_pauses,self.playing_type()])

with this one:

Code:
subprocess.call(script_player_pauses + " " + self.playing_type(), shell=True)

save the file, restart XBMC and configure the addon so it calls wscript with an argument:

Code:
<setting id="player_pauses" value="wscript C:\sarah\plugins\fred\bin\huelight_high.vbs" />

Let me know if it works...
Reply
#93
I created a fork: https://github.com/KenV99/service.xbmc.callbacks
This OPTIONALLY allows for individual commands and/or arguments to be enclosed by curly brackets in the settings.xml file.
These will then be parsed and passed when subprocess.call is invoked.
For example for 'wscript c:\test.vbs' at the command line, the xml should have '{wscript}{c:\test.vbs}'.
Or more precisely, using the example from flarc the full line in the xml file would be:
Code:
<setting id="player_pauses" value="{wscript}{C:\sarah\plugins\fred\bin\huelight_high.vbs}" />
I have only tested this in windows and with my limited knowledge of other OS's I'm not sure if the curly brackets are going to cause issues if they are commonly used by the shell/command line.
Let me know if this works and/or causes problems for anyone.

Thanks again to pilluli for the original script/code.
Reply
#94
KenV99 and Pilluli, thank you very much for such quick answer to my issue.
As soon as back from business trip i will test your solutions and get back to you.
Reply
#95
hello,i have no programing skills at all,i just want a script to make http request like "http://192.168.1.120/?button2on".
What is the easiest way to do it?Thank you.

EDIT: got it,i have 2 scripts ,lightson.py and lightsoff.py,when i run them they work fine,but from within the addon dont work.
my settings:
Code:
<settings>
    <setting id="db_update" value="" />
    <setting id="idle_time" value="10" />
    <setting id="player_pauses" value="C:\Python33\lightson.py" />
    <setting id="player_resumes" value="C:\Python33\lightsoff.py" />
    <setting id="player_starts" value="C:\Python33\lightsoff.py" />
    <setting id="player_stops" value="C:\Python33\lightson.py" />
    <setting id="screensaver_starts" value="" />
    <setting id="screensaver_stops" value="" />
    <setting id="xbmc_idle" value="" />
    <setting id="xbmc_starts" value="" />
</settings>

what am i doing wrong?
tested both frodo and gotham ,win8.1
Reply
#96
(2014-03-12, 23:28)wolfgr Wrote: hello,i have no programing skills at all,i just want a script to make http request like "http://192.168.1.120/?button2on".
What is the easiest way to do it?Thank you.

EDIT: got it,i have 2 scripts ,lightson.py and lightsoff.py,when i run them they work fine,but from within the addon dont work.
my settings:
Code:
<settings>
    <setting id="db_update" value="" />
    <setting id="idle_time" value="10" />
    <setting id="player_pauses" value="C:\Python33\lightson.py" />
    <setting id="player_resumes" value="C:\Python33\lightsoff.py" />
    <setting id="player_starts" value="C:\Python33\lightsoff.py" />
    <setting id="player_stops" value="C:\Python33\lightson.py" />
    <setting id="screensaver_starts" value="" />
    <setting id="screensaver_stops" value="" />
    <setting id="xbmc_idle" value="" />
    <setting id="xbmc_starts" value="" />
</settings>

what am i doing wrong?
tested both frodo and gotham ,win8.1

That looks like it should work. Is there anything in XBMC.log to indicate why it failed?
Reply
#97
xbmc log doent shows anything relevant...
my scripts are lights on
Code:
import os
import time
import sys
import urllib.request
urllib.request.urlopen("http://192.168.1.120/?button2on").read()

and lights off
Code:
import os
import time
import sys
import urllib.request
urllib.request.urlopen("http://192.168.1.120/?button2off").read()

i have instaled Python 33 and scripts are working in windows.
I just cant make them work inside xbmc.

Edit: got them to work inside xbmc,run when execute from file manager just fine(i removed "request").
But still nothing works from the addon...
Reply
#98
(2014-03-13, 14:57)wolfgr Wrote: xbmc log doent shows anything relevant...
my scripts are lights on
Code:
import os
import time
import sys
import urllib.request
urllib.request.urlopen("http://192.168.1.120/?button2on").read()

and lights off
Code:
import os
import time
import sys
import urllib.request
urllib.request.urlopen("http://192.168.1.120/?button2off").read()

i have instaled Python 33 and scripts are working in windows.
I just cant make them work inside xbmc.

Edit: got them to work inside xbmc,run when execute from file manager just fine(i removed "request").
But still nothing works from the addon...

I realized it's the same reason that flarc was having issues. The subprocess.call() in the script does not allow calling a program without designating it's executable. So you would have to create a .bat with something like "C:\python33\python.exe c:\python33\lightson.py" and call the .bat file. Or you could try using my fork and put the two commands in curly brackets. Or lastly, you could edit the the script's default.py as pilluli suggested, including the argument shell=true.
Reply
#99
tested all solutions....scripts and .bat files are working outside addon,with the addon i get crasses,python.exe has stoped working messages and syntax errors. ....i give up Sad
Reply
What do the logs say? They should show the add on calling the script ...
and then the error is??
Reply
(2014-03-13, 20:06)wolfgr Wrote: tested all solutions....scripts and .bat files are working outside addon,with the addon i get crasses,python.exe has stoped working messages and syntax errors. ....i give up Sad
OK, if you have turned debug on in XBMC and have no error messages and would prefer not to pursue any further help, then best of luck. However, since this is an free, open source project, your experience could help the developers and other users if you are willing to work on it a bit more.

If you change your mind, I think we need the info from the logs. If you tried the .bat file, exactly what the bat file looked like and the exact error message or crash situation. If you tried the curly brackets, exactly what you had in the xml file. If you tried editing the python script directly, the actual code that you finally left in the script.
Reply
Rainbow 
(2014-03-10, 22:06)KenV99 Wrote: I created a fork: https://github.com/KenV99/service.xbmc.callbacks
This OPTIONALLY allows for individual commands and/or arguments to be enclosed by curly brackets in the settings.xml file.
These will then be parsed and passed when subprocess.call is invoked.
For example for 'wscript c:\test.vbs' at the command line, the xml should have '{wscript}{c:\test.vbs}'.
Or more precisely, using the example from flarc the full line in the xml file would be:
Code:
<setting id="player_pauses" value="{wscript}{C:\sarah\plugins\fred\bin\huelight_high.vbs}" />
I have only tested this in windows and with my limited knowledge of other OS's I'm not sure if the curly brackets are going to cause issues if they are commonly used by the shell/command line.
Let me know if this works and/or causes problems for anyone.

Thanks again to pilluli for the original script/code.

Hello KenV99.

Your method+modified script worked! Big Grin Thanks. Please note that replacing python script + changing settings.xml + restarting xbmc was not enough to make it work. i do not know why, but within xbmc i add to go into add-on configuration and revalidate it by clicking "ok" for the change to be taken into account. Probably a cache somewhere Huh.
Either way, my problem is solved.

Now, for the sake of science Smile, i will test this week-end pilluli's method also.

Thx again.
Reply
Please do as if that works it requires less configuration changes than kenv99 approach.
Reply
Hello Pilluli,
I tried you method this morning it works too. Thanks.

I just however discovered an issue with the plugin, whether i use your default.py or KenV99: the plugin works only when i go into its settings and validate them before playing a video.
Let me explain better:
- scenario1: i just start xbmc, and then start a video: plugin does not trigger
- scenario2: i start xbmc, go into plugin config page, validate the config without changing it, return to homepage, and then start a video: it works.

I activated XBMC debug to see what happened.

In scenario2 (working case after config), i see that in the logs:
Code:
10:56:55 T:3004  NOTICE: -----------------------------------------------------------------------
10:56:55 T:3004  NOTICE: Starting XBMC (12.0 Git:20130127-fb595f2), Platform: Windows 7 32-bit, build 7600. Built on Jan 28 2013 (compiler 1600)
[...]
10:57:34 T:3004   DEBUG: ------ Window Init (DialogAddonSettings.xml) ------
[...]
10:57:37 T:4072   DEBUG: XBMC callbacks: Reading properties
10:57:37 T:4072   DEBUG: XBMC callbacks: script xbmc starts = ""
10:57:37 T:4072   DEBUG: XBMC callbacks: script player starts = "wscript C:\sarah\plugins\fred\bin\huelight_low.vbs"
10:57:37 T:4072   DEBUG: XBMC callbacks: script player stops = "wscript C:\sarah\plugins\fred\bin\huelight_high.vbs"
10:57:37 T:4072   DEBUG: XBMC callbacks: script player pauses = "wscript C:\sarah\plugins\fred\bin\huelight_high.vbs"
10:57:37 T:4072   DEBUG: XBMC callbacks: script player resumes = "wscript C:\sarah\plugins\fred\bin\huelight_low.vbs"
10:57:37 T:4072   DEBUG: XBMC callbacks: script screensaver starts = ""
10:57:37 T:4072   DEBUG: XBMC callbacks: script screensaver stops = ""
10:57:37 T:4072   DEBUG: XBMC callbacks: script idle = ""
10:57:37 T:4072   DEBUG: XBMC callbacks: db update = ""
[...]
10:57:50 T:4072   DEBUG: XBMC callbacks: player starts
10:57:50 T:4072   DEBUG: XBMC callbacks: Going to execute script = "wscript C:\sarah\plugins\fred\bin\huelight_low.vbs"

When i am in scenario1 (default case, not working), i see in the logs:
Code:
10:53:24 T:4824  NOTICE: -----------------------------------------------------------------------
10:53:24 T:4824  NOTICE: Starting XBMC (12.0 Git:20130127-fb595f2), Platform: Windows 7 32-bit, build 7600. Built on Jan 28 2013 (compiler 1600)
[...]
10:55:53 T:3032   DEBUG: XBMC callbacks: player starts

I looked into the default.py code, and it seems to me that in default case the properties are not loaded, so even though the event "player starts" is properly catched it does not trigger the subprocesscall.
For the properties to be read, i have to validate them at each xbmc start.
But, why?
I do not know if it is pertinent, but please note that i use xbmc in portable mode (started with '-p' )

My solution proposal would be to modify the default.py to hardcode within each callback function the value of the variable from settings.xml, so that it works even if the settings are not read.

Any other idea?
Reply
Thanks Pilluli and KenV99. The work both of you did saved me a lot of time and effort. I use vbs so KenV99 fork worked out easiest for me since I just need to replace one file rather than make several edits.
Reply
  •   
  • 1
  • 5
  • 6
  • 7(current)
  • 8
  • 9
  • 23
  •   
 
Thread Rating:
  • 4 Vote(s) - 4.5 Average



Logout Mark Read Team Forum Stats Members Help
[RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...)4.54