Run script on events?

Hi Guys,

After the topic below, I’m really interested in triggerring scripts on some Kodi events (Start video library update or clean, Found a new tvshow, found new episodes, …)

Do you have any ideas about how to do that ?

Thanks a lot !!!

Look at the ISY Event Handler addon. It triggers some home automation stuff when certain things happen. You could base what you need off that.

Otherwise, if you are writing a script, you can use xbmc.Monitor class to receive notifications when certain events happen: http://mirrors.xbmc.org/docs/python-docs/15.x-isengard/xbmc.html#Monitor

That is probably what the Event Handler uses.

Thanks !

For ISY Event Handler : Allows the user to trigger ISY Home Automation actions when different events occur in XBMC. The possible events are XBMC Starting, XBMC Quitting, Movie Playback Started, Movie Playback Ended, Movie Paused, Movie Resumed, Music Playback Started, Music Playback Ended, Music Paused, Music Resumed. This allows Insteon and X10 lights to react to XBMC events.

=> So nothing about the scan.

For xbmc.Monitor, there is onScanFinished(…) and onScanStarted(…), This is perfect for me. :smiley:

Now, I’m not a python developer but I will try some thing.

Folder: ~/.xbmc/scripts

Script: push-alerts.py

#!/usr/bin/python3.4
import xbmc
import subprocess

class PushAlerts(xbmc.Monitor):

    def __init__(self):
    xbmc.Monitor.__init__(self)

def onScanStarted(video):
    subprocess.call(["/home/pi/push.sh", "title", "Started"])
def onScanFinished(video):
    subprocess.call(["/home/pi/push.sh", "title", "Finished"])

alertmanager = PushAlerts()

After I want that Kodi launch my script automatically, I found an old post about autoexec.py, but it deprecated.

Is there a solution ?

That addon is a Service, which means that it starts when Kodi starts and stays alive until Kodi exits.

Have a look at the source code for a good example of how to do what you are looking to do.

You are talking about ISY Event Handler ?
I think may be it’s better to do it with a py script with xbmc.Monitor because ISY can’t manage my needed events !
https://automic.us/wiki/index.php?title=ISY_Events:Main_Page

I am saying that that addon shows you how to write the script that will stay alive. Edit it for your needs.

I appreciate but I’m not a py developer. I just merged pieces of code from internet.
Can you help me ? :blush:

Head over to the Kodi forums, someone might have already done what you are looking to do.

I will try but if anybody here can help me, I will be grateful !! :blush: