• 1
  • 17
  • 18
  • 19(current)
  • 20
  • 21
  • 23
[RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...)
Hi, I was looking for a way to mount my nfs drives OS level instead of using the builtin nfs:// library as there is a big performance issues over vpn (my storage is located halfway across the world ;-) ).

So, I wrote the startup_script.sh and added it to the startup option

But apparently there seems to be an issue... see logs below

Kodi.log:
http://pastebin.com/peJQLEFq

script:
-rwxr-xr-x 1 rein staff 196B Aug 28 13:40 startup_script.sh


Reins-MacBook-Pro:userdata rein$ cat startup_script.sh
#!/bin/bash
mkdir /Volumes/Series
mkdir /Volumes/Movies
mount -t nfs 192.168.22.51:/mnt/DroboFS/Shares/Series /Volumes/Series
mount -t nfs 192.168.22.51:/mnt/DroboFS/Shares/Movies /Volumes/Movies

Can you help?
Reply
(2015-08-28, 14:09)RaZer0r Wrote: Hi, I was looking for a way to mount my nfs drives OS level instead of using the builtin nfs:// library as there is a big performance issues over vpn (my storage is located halfway across the world ;-) ).

So, I wrote the startup_script.sh and added it to the startup option

But apparently there seems to be an issue... see logs below

Kodi.log:
http://pastebin.com/peJQLEFq

script:
-rwxr-xr-x 1 rein staff 196B Aug 28 13:40 startup_script.sh


Reins-MacBook-Pro:userdata rein$ cat startup_script.sh
#!/bin/bash
mkdir /Volumes/Series
mkdir /Volumes/Movies
mount -t nfs 192.168.22.51:/mnt/DroboFS/Shares/Series /Volumes/Series
mount -t nfs 192.168.22.51:/mnt/DroboFS/Shares/Movies /Volumes/Movies

Can you help?

Very odd!

The log indicates that your version of python doesn't support subprocess.check_ouput:
Code:
13:56:13 T:4589146112  NOTICE: $$$ [xbmc.callbacks2] - Command for onStartup resulted in ERROR: <attribute 'message' of 'exceptions.BaseException' objects>
                                            Traceback (most recent call last):
                                              File "/Users/rein/Library/Application Support/Kodi/addons/service.xbmc.callbacks2-master/default.py", line 515, in run
                                                result = subprocess.check_output(margs, shell=self.needs_shell, stderr=subprocess.STDOUT)
                                            AttributeError: 'module' object has no attribute 'check_output'

but clearly that is part of python 2.7:
https://docs.python.org/2/library/subpro...eck_output

I don't know if anyone else running on OSX has experienced this issue. I googled around and can't seem to find that this is an issue specific to OSX.
Perhaps others on OSX can chime in.

You could try editing line 515 to be subprocess.call instead of subprocess.check_output
Reply
OSX Yosemite has python 2.6 and 2.7.10 installed, with 2.7 being the default.

I both checked 2.6 and 2.7, but the subroutine still failed...
With switching to the subprocess.call it worked.

When you want me to do some more testing let me know :-)
Reply
(2015-08-28, 14:51)KenV99 Wrote:
(2015-08-28, 14:09)RaZer0r Wrote: Hi, I was looking for a way to mount my nfs drives OS level instead of using the builtin nfs:// library as there is a big performance issues over vpn (my storage is located halfway across the world ;-) ).

So, I wrote the startup_script.sh and added it to the startup option

But apparently there seems to be an issue... see logs below

Kodi.log:
http://pastebin.com/peJQLEFq

script:
-rwxr-xr-x 1 rein staff 196B Aug 28 13:40 startup_script.sh


Reins-MacBook-Pro:userdata rein$ cat startup_script.sh
#!/bin/bash
mkdir /Volumes/Series
mkdir /Volumes/Movies
mount -t nfs 192.168.22.51:/mnt/DroboFS/Shares/Series /Volumes/Series
mount -t nfs 192.168.22.51:/mnt/DroboFS/Shares/Movies /Volumes/Movies

Can you help?

Very odd!

The log indicates that your version of python doesn't support subprocess.check_ouput:
Code:
13:56:13 T:4589146112  NOTICE: $$$ [xbmc.callbacks2] - Command for onStartup resulted in ERROR: <attribute 'message' of 'exceptions.BaseException' objects>
                                            Traceback (most recent call last):
                                              File "/Users/rein/Library/Application Support/Kodi/addons/service.xbmc.callbacks2-master/default.py", line 515, in run
                                                result = subprocess.check_output(margs, shell=self.needs_shell, stderr=subprocess.STDOUT)
                                            AttributeError: 'module' object has no attribute 'check_output'

but clearly that is part of python 2.7:
https://docs.python.org/2/library/subpro...eck_output

I don't know if anyone else running on OSX has experienced this issue. I googled around and can't seem to find that this is an issue specific to OSX.
Perhaps others on OSX can chime in.

You could try editing line 515 to be subprocess.call instead of subprocess.check_output

So: Something really weird happens now.. The first testings it worked fine, but now not anymore Sad. The only thing I did was adding a stop script (to unmount the volumes) but now nothing gets ran. The log does say the script is being executed...
I tried removing the plugin and reinstalling it (including removing the userdata/service plugin folder) but no go.. it just won't mount the disks anymore...

Any way to debug the outputs of the scripts ran? (although my mount script should not give any output anyway)

Code:
18:51:17 T:4580925440  NOTICE: Thread LanguageInvoker start, auto delete: false
18:51:17 T:140735210930944  NOTICE: Previous line repeats 6 times.
18:51:17 T:140735210930944  NOTICE: initialize done
18:51:17 T:140735210930944  NOTICE: Running the application...
18:51:17 T:140735210930944  NOTICE: starting zeroconf publishing
18:51:17 T:140735210930944  NOTICE: starting upnp client
18:51:17 T:4598071296  NOTICE: Thread JobWorker start, auto delete: true
18:51:17 T:140735210930944  NOTICE: ES: Starting event server
18:51:17 T:4601290752  NOTICE: Thread EventServer start, auto delete: false
18:51:17 T:4601290752  NOTICE: ES: Starting UDP Event server on 0.0.0.0:9777
18:51:17 T:4601290752  NOTICE: UDP: Listening on port 9777
18:51:17 T:4601827328  NOTICE: Thread TCPServer start, auto delete: false
18:51:17 T:4580925440  NOTICE: -->Python Interpreter Initialized<--
18:51:17 T:4642508800  NOTICE: Previous line repeats 6 times.
18:51:17 T:4642508800  NOTICE: Thread JobWorker start, auto delete: true
18:51:17 T:4642508800   ERROR: InputStream: Error opening, /Volumes/Movies/Fast and Furious/Fast & Furious.2009.1080p.BluRay.x264.anoXmous_.mp4
18:51:17 T:4596461568  NOTICE: script.tv.show.next.aired: ### TV Show - Next Aired starting background proc (6.0.14)
18:51:17 T:4596998144  NOTICE:  StorageServer Module loaded RUN
18:51:17 T:4596998144  NOTICE: StorageClient-2.5.4 Starting server
18:51:17 T:4597534720  NOTICE: $$$ [xbmc.callbacks2] - Starting xbmc.callbacks2 version 0.1.0
18:51:17 T:4597534720  NOTICE: $$$ [xbmc.callbacks2] - Executing command: [[u'/Users/rein/Library/Application Support/Kodi/userdata/startup_script.sh']] for event: onStartup
18:51:17 T:4597534720  NOTICE: $$$ [xbmc.callbacks2] - Command for onStartup executed successfully[/quote]

Added logs*
Reply
(2015-08-28, 18:49)RaZer0r Wrote: So: Something really weird happens now.. The first testings it worked fine, but now not anymore Sad. The only thing I did was adding a stop script (to unmount the volumes) but now nothing gets ran. The log does say the script is being executed...
I tried removing the plugin and reinstalling it (including removing the userdata/service plugin folder) but no go.. it just won't mount the disks anymore...

Any way to debug the outputs of the scripts ran? (although my mount script should not give any output anyway)

Code:
18:51:17 T:4580925440  NOTICE: Thread LanguageInvoker start, auto delete: false
18:51:17 T:140735210930944  NOTICE: Previous line repeats 6 times.
18:51:17 T:140735210930944  NOTICE: initialize done
18:51:17 T:140735210930944  NOTICE: Running the application...
18:51:17 T:140735210930944  NOTICE: starting zeroconf publishing
18:51:17 T:140735210930944  NOTICE: starting upnp client
18:51:17 T:4598071296  NOTICE: Thread JobWorker start, auto delete: true
18:51:17 T:140735210930944  NOTICE: ES: Starting event server
18:51:17 T:4601290752  NOTICE: Thread EventServer start, auto delete: false
18:51:17 T:4601290752  NOTICE: ES: Starting UDP Event server on 0.0.0.0:9777
18:51:17 T:4601290752  NOTICE: UDP: Listening on port 9777
18:51:17 T:4601827328  NOTICE: Thread TCPServer start, auto delete: false
18:51:17 T:4580925440  NOTICE: -->Python Interpreter Initialized<--
18:51:17 T:4642508800  NOTICE: Previous line repeats 6 times.
18:51:17 T:4642508800  NOTICE: Thread JobWorker start, auto delete: true
18:51:17 T:4642508800   ERROR: InputStream: Error opening, /Volumes/Movies/Fast and Furious/Fast & Furious.2009.1080p.BluRay.x264.anoXmous_.mp4
18:51:17 T:4596461568  NOTICE: script.tv.show.next.aired: ### TV Show - Next Aired starting background proc (6.0.14)
18:51:17 T:4596998144  NOTICE:  StorageServer Module loaded RUN
18:51:17 T:4596998144  NOTICE: StorageClient-2.5.4 Starting server
18:51:17 T:4597534720  NOTICE: $$$ [xbmc.callbacks2] - Starting xbmc.callbacks2 version 0.1.0
18:51:17 T:4597534720  NOTICE: $$$ [xbmc.callbacks2] - Executing command: [[u'/Users/rein/Library/Application Support/Kodi/userdata/startup_script.sh']] for event: onStartup
18:51:17 T:4597534720  NOTICE: $$$ [xbmc.callbacks2] - Command for onStartup executed successfully[/quote]

Added logs*

Does your script run successfully when running it from the addon settings page?
Did you reset the execute bits on the scripts after reinstalling?

In any case, I pushed an update to github that checks if running OSX and uses subprocess call instead of check_output.
https://github.com/KenV99/service.xbmc.callbacks2

EDIT: I pushed another update. Please download and try again using Test from Settings. Now on OSX it tries to set the execute bit and then uses subprocess.Popen and Popen.communicate to grab the output from the script (that's why I was using subprocess.check_ouput - so you had some feedback for troubleshooting). When you execute via Test, the output from the script, including errors should be displayed in a dialog box (poorly formatted, but there are limits here Smile )
Reply
Ken: I've been using your addon very successfully for awhile now. It gets kicked off when playback starts and playback ends. When playback ends I pop up a menu that gives me the option to delete the file (TV Show) being viewed.
My TV Show recordings are coming from NextPVR.

Here is the issue, sometimes NextPVR creates this long filename that contains commas. I should mention I am running on Windows 8.1.
So the issue is every-time there is a comma in the filename my python scrip that gets kicked off by your callback2 thinks there is an extra parameter. So in affect the "file" parameter becomes and invalid filename (a file that can't be found as it is really an incomplete filename) and therefore does not execute my python script correctly.
I know when you pass a parameter to a python program you can put quotes ("") around the parameter being sent, which then would allow embedded commas. Could you point me in the right direction in your code so I could add those quotes around the filename?
I am sure this is not an issue for most people, so I would not expect you to make this specific change just for me. But I could modify the code myself if I could find the right spot. I have taken a look at your code and it isn't obvious to me where to make that change.
I'd appreciate any help you might be able to offer.
Reply
(2015-09-03, 17:46)ReplayHarry Wrote: Ken: I've been using your addon very successfully for awhile now. It gets kicked off when playback starts and playback ends. When playback ends I pop up a menu that gives me the option to delete the file (TV Show) being viewed.
My TV Show recordings are coming from NextPVR.

Here is the issue, sometimes NextPVR creates this long filename that contains commas. I should mention I am running on Windows 8.1.
So the issue is every-time there is a comma in the filename my python scrip that gets kicked off by your callback2 thinks there is an extra parameter. So in affect the "file" parameter becomes and invalid filename (a file that can't be found as it is really an incomplete filename) and therefore does not execute my python script correctly.
I know when you pass a parameter to a python program you can put quotes ("") around the parameter being sent, which then would allow embedded commas. Could you point me in the right direction in your code so I could add those quotes around the filename?
I am sure this is not an issue for most people, so I would not expect you to make this specific change just for me. But I could modify the code myself if I could find the right spot. I have taken a look at your code and it isn't obvious to me where to make that change.
I'd appreciate any help you might be able to offer.

I assume that you are creating the menu from python script. Are you running that script as direct python script or via the builtin? Could you post a link to the code of the script that you are running (i.e. upload it to github or pastbin)?

I think it is likely that you need to change line 326 from:

Code:
runtimeargs.append('file=' + self.getPlayingFileEx())

to

Code:
runtimeargs.append('file="%s"' % self.getPlayingFileEx())

but without the specifics, it's just a guess.
Reply
Wink 
(2015-09-03, 20:11)KenV99 Wrote:
(2015-09-03, 17:46)ReplayHarry Wrote: Ken: I've been using your addon very successfully for awhile now. It gets kicked off when playback starts and playback ends. When playback ends I pop up a menu that gives me the option to delete the file (TV Show) being viewed.
My TV Show recordings are coming from NextPVR.

Here is the issue, sometimes NextPVR creates this long filename that contains commas. I should mention I am running on Windows 8.1.
So the issue is every-time there is a comma in the filename my python scrip that gets kicked off by your callback2 thinks there is an extra parameter. So in affect the "file" parameter becomes and invalid filename (a file that can't be found as it is really an incomplete filename) and therefore does not execute my python script correctly.
I know when you pass a parameter to a python program you can put quotes ("") around the parameter being sent, which then would allow embedded commas. Could you point me in the right direction in your code so I could add those quotes around the filename?
I am sure this is not an issue for most people, so I would not expect you to make this specific change just for me. But I could modify the code myself if I could find the right spot. I have taken a look at your code and it isn't obvious to me where to make that change.
I'd appreciate any help you might be able to offer.

I assume that you are creating the menu from python script. Are you running that script as direct python script or via the builtin? Could you post a link to the code of the script that you are running (i.e. upload it to github or pastbin)?

I think it is likely that you need to change line 326 from:

Code:
runtimeargs.append('file=' + self.getPlayingFileEx())

to

Code:
runtimeargs.append('file="%s"' % self.getPlayingFileEx())

but without the specifics, it's just a guess.

Yes, a python script. Once I saw your example code, I immediately found what needed to be fixed. I did have to change it to put the double quote before the file= and after the variable name so that the entire parameter was bracketed with double quotes. It works perfectly and thanks again for your help. I added it to title also since that is sometime an issue (although a minor one).

Again, a big thank you![/php]


Here is the modified code I am now using.

[php] def onPlayBackStartedEx(self):
runtimeargs = []
temp_str = ''
if __options__['arg_mediatype']:
runtimeargs.append('type=' + self.playing_type())
if __options__['arg_filename']:
temp_str = self.getPlayingFileEx()
# runtimeargs.append('file=' + self.getPlayingFileEx())
runtimeargs.append('"' + 'file=' + temp_str + '"')
if __options__['arg_title']:
temp_str = self.getTitle()
# runtimeargs.append('title=' + self.getTitle())
runtimeargs.append('"' + 'title=' + temp_str + '"')
if self.isPlayingVideo():
if __options__['arg_aspectratio']:
runtimeargs.append('aspectratio=' + self.getAspectRatio())
if __options__['arg_resolution']:
runtimeargs.append('resolution=' + self.getResoluion())
self.dispatcher.dispatch('onPlaybackStarted', runtimeargs)
Reply
Ok, I was putting the quotes just around the filename, but all that matters is that it works for you.
Usually if I need to concatenate a string more than once ($ + $), I use the alternative python notation that I showed above because string concatenation is slow in python. But I doubt that it really matters in this instance.

To do it this way with quotes around the whole statement, you would use:

Code:
runtimeargs.append('"file=%s"' % self.getPlayingFileEx())

See https://docs.python.org/2/library/stdtyp...operations

There is more than one way to do string formatting - using .format instead of the % operator and there are differences between 2.7 and 3.+, but the gist of it is that if you need to place a string variable in the middle of hard coded string, you can use %s in the hard coded string to represent the variable and then after the string use the % operator followed by the string variable.
Reply
Thanks. I will make this change as it seems it should be more efficient.
But it does work now and I appreciate the help.
I've done a lot of programming in my day, mostly Pascal and assembler (under MS-DOS), so I sure don't claim to be a python expert, but I am getting better at it. Most of the time I can make things work, but I am sure I am not always doing it the best way.

Again, Thanks Ken.
Reply
Ken: Just to let you know I did put that last format change in you gave me in your last post. It worked perfectly, so I am all set.
Thanks again for your help.
Reply
I am trying to use the XBMC is Idle option but it is not working. Screensaver on and off work but not the idle option. I am calling some python scripts to turn my TV on and off. I would like the TV to turn off a few minuets after my screen saver so I kind of have a warning before it shuts off.

Thanks in advanced!
Check out all my How-To's at http://KnightCinema.com
Maine, USA.
Using XBMC since Dharma 2010
Reply
(2015-09-13, 01:09)jknight2014 Wrote: I am trying to use the XBMC is Idle option but it is not working. Screensaver on and off work but not the idle option. I am calling some python scripts to turn my TV on and off. I would like the TV to turn off a few minuets after my screen saver so I kind of have a warning before it shuts off.

Thanks in advanced!

I tested the idle function on Isengard RC2 and it seems to be working on my system. I pushed a new version that will log idle time information to the log for you to troubleshoot. You will have to edit default.py in the addon's directory to turn the debug on and off. On line 23 change 'idledebug = False' to 'idledebug = True'.

As far as turning your TV off a few minutes after the screen saver starts, obviously you will need to write a timer delay into whatever it is you are calling to turn off the TV. If you want help with that you will need to provide specifics as to what computer and OS you are using, how you are invoking your code from the addon and the code itself.

If you are still having trouble with OnIdle, post your kodi.log to pastebin with the above-mentioned 'idledebug' switch set to True and post the link to the log here.
Reply
Quick question Ken - sorry if I've missed something, but should this be working on Helix?
I'm using openelec 5.08 (kodi14.2) and I've set up to return to the home page (built-in - XBMC.ActivateWindow(Home)) on screensaver, sleep (poweroff) and resume. It works great on the screensaver but not the other 2.
Have I missed something obvious, or should I post some logs?
TIA.
Reply
Code:
08:15:31 T:139753114765056 WARNING: CPythonInvoker(191): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
08:15:31 T:139753114765056  NOTICE: $$$ xbmc.callbacks2 - Starting tester.py from cwd: /home/kodi/.kodi/addons/service.xbmc.callbacks2-master
08:15:31 T:139753114765056   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.ImportError'>
                                            Error Contents: No module named pydevd
                                            Traceback (most recent call last):
                                              File "/home/kodi/.kodi/addons/service.xbmc.callbacks2-master/tester.py", line 52, in <module>
                                                from default import Dispatcher, read_settings, __options__
                                              File "/home/kodi/.kodi/addons/service.xbmc.callbacks2-master/default.py", line 34, in <module>
                                                import pydevd
                                            ImportError: No module named pydevd
                                            -->End of Python script error report<--

This hapend when I tried to test. I set it to 3 minuets and waited 10 and nothing hapend. No new lines in the log. The Screen Saver came on so it is idle.
Check out all my How-To's at http://KnightCinema.com
Maine, USA.
Using XBMC since Dharma 2010
Reply
  • 1
  • 17
  • 18
  • 19(current)
  • 20
  • 21
  • 23

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