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

  Thread Rating:
  • 3 Vote(s) - 4.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
wolfn48 Offline
Junior Member
Posts: 3
Joined: Mar 2015
Reputation: 0
Post: #196
Hello KenV99,
I'm running Openelec/Kodi on a Intel-NUC with USB-HDDs and think about mirroring/backup my music-data to my NAS.
Your addon seems to me the best tool available for this, but I'm new to Kodi and an absolute python-noob...

So I need some 'kickoff'.
My 1st idea is:
1. If Kodi starts - send a WOL to the NAS (afaik is a function in Kodi)
2. when ready start rsync (client on Kodi, is already installed, server runs on the NAS)
- this should be packed into an shell-script.

Do you think I can get this 'wrapped' into your addon?
And, if yes, will this (as long as its running) prevent Kodi from shutting down if no other action takes place?
( I adjusted Kodi to shutdown after the max. possible 120 min.)

I'm not sure how to mix shell, python and this WOL-call.
If you can point me to some further reading...
find quote
KenV99 Offline
Senior Member
Posts: 277
Joined: Nov 2013
Reputation: 8
Post: #197
(2015-03-28 14:26)wolfn48 Wrote:  Hello KenV99,
I'm running Openelec/Kodi on a Intel-NUC with USB-HDDs and think about mirroring/backup my music-data to my NAS.
Your addon seems to me the best tool available for this, but I'm new to Kodi and an absolute python-noob...

So I need some 'kickoff'.
My 1st idea is:
1. If Kodi starts - send a WOL to the NAS (afaik is a function in Kodi)

This is done directly in Kodi, not through this addon: Wake_on_lan (wiki)

(2015-03-28 14:26)wolfn48 Wrote:  2. when ready start rsync (client on Kodi, is already installed, server runs on the NAS)
- this should be packed into an shell-script.

I don't know much about rsync. Unless you can set a long timeout, you will need to find a way to poll to see when the NAS is online in your shell script before you start the sync process.

(2015-03-28 14:26)wolfn48 Wrote:  Do you think I can get this 'wrapped' into your addon?
And, if yes, will this (as long as its running) prevent Kodi from shutting down if no other action takes place?
( I adjusted Kodi to shutdown after the max. possible 120 min.)

I'm not sure how to mix shell, python and this WOL-call.
If you can point me to some further reading...

I doesn't need to be 'wrapped' as best as I can tell. Kodi will do the WOL. You will need to write the shell script and link it to the 'on Startup Event' as a shell executable.

There is no way to abort a Kodi shutdown - scripts are terminated automatically if they do not abort themselves in 5 seconds after shutdown starts. However, since the script executes in a subprocess call, it will likely run until it finishes, but it may cause issues when you retry to restart Kodi because the process may not terminate gracefully. I know this happens in windows, I'm not sure if it happens in Linux.
(This post was last modified: 2015-03-29 01:05 by KenV99.)
find quote
wolfn48 Offline
Junior Member
Posts: 3
Joined: Mar 2015
Reputation: 0
Post: #198
Thank you very much KenV99,

just played around with your addon + found I can call 1x python OR 1x shell OR 1x call to Kodi.
So I will try to write a little python-script to 1st call Kodi for WOL to my NAS, then do some pings for waiting til ready and then start the rsync.
Found in the Kodi-wiki some links for get me going in python, will give it a try...

Thanks again, will report success or problems...
find quote
KenV99 Offline
Senior Member
Posts: 277
Joined: Nov 2013
Reputation: 8
Post: #199
If you want to code sending the WOL magic packet yourself, more power to you, but if you enable it as above and edit the xml, you may be fine. Or you can use the advanced version: Add-on:Advanced_Wake_On_Lan (wiki)
I don't see a direct way of calling the kodi wol routines from python or via json, so you will have to either do it from the shell or download the advanced wol add on and look at how it's coded.
find quote
wolfn48 Offline
Junior Member
Posts: 3
Joined: Mar 2015
Reputation: 0
Post: #200
Hi KenV99,

Advanced_WOL ist already installed and used by Kodi on my NUC - this way the idea with rsync is born...

But just this moment I found the ethtool in Openelec, has a switch for WOL.

Edit: Bad, only for setting the local port. - Searching continues.
Edit2: Just found this:

#!/usr/bin/env python
import socket
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto('\xff'*6+'\xQQ\xQQ\xQQ\xQQ\xQQ\xQQ'*16, ("255.255.255.255",9))

- It works perfectly!!!


If this works for me, then most problems have gone. Then I will write some shell-code for this job.
(looked into Python-doc -- puuuhh, some overkill I think)
(This post was last modified: 2015-03-30 10:47 by wolfn48.)
find quote
Post Reply