Thanks for your reply,
I meant calling a plugin from inside my plugin (sorry, quite new to this, learning from you guys as I go...)
While pasting it here, I noticed I missed a parentheses at the end of the string !
It was the red one here:
eg.plugins.RTISimpelTCPServer.SendString('Kodi_Control@' + str(currDict['control_label']) + '#')
Works great now, can't believe it was just that !
Cheers
Code: Select all
import eg
eg.RegisterPlugin(
name = "Kodi to RTI",
author = "Simon Tether",
version = "0.1",
kind = "other",
description = "Monitor Kodi for variable changes and generate events to send to RTI processor"
)
import threading, urllib2, json
class KODI2RTI(eg.PluginBase):
def __init__(self):
self._event = None
self._thread = None
def __start__(self):
if self._thread is None:
self._event = threading.Event()
self._thread = threading.Thread(target=self.run)
self._thread.daemon = True
self._thread.start()
def __stop__(self):
if self._event is not None:
self._event.set()
self._thread.join(3.0)
def run(self):
while not self._event.isSet():
try:
currPlayer = json.loads(urllib2.urlopen('http://192.168.1.51:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}', timeout=0.5).read())
window = json.loads(urllib2.urlopen('http://192.168.1.51:8080/jsonrpc?request={"jsonrpc":"2.0","method":"GUI.GetProperties","params":{"properties":["currentwindow"]},"id":1}', timeout=0.5).read())
control = json.loads(urllib2.urlopen('http://192.168.1.51:8080/jsonrpc?request={"jsonrpc":"2.0","method":"GUI.GetProperties","params":{"properties":["currentcontrol"]},"id":1}', timeout=0.5).read())
except:
eg.PrintError("Error connecting to Kodi")
if currPlayer['result']:
playerid = currPlayer['result'][0]['playerid']
if playerid == 0 or playerid == 1:
try:
playing = json.loads(urllib2.urlopen('http://192.168.1.51:8080/jsonrpc?request={"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "season", "episode", "duration", "showtitle"], "playerid": ' + str(playerid) + '}, "id": "1"}', timeout=0.5).read())
except:
pass
channel_label, channel_title = playing['result']['item']['label'], playing['result']['item']['title']
else:
channel_label, channel_title = "-", "-"
control_label = control['result']['currentcontrol']['label']
window_id, window_label = window['result']['currentwindow']['id'], window['result']['currentwindow']['label']
currDict = {'channel_label' : channel_label, 'channel_title' : channel_title,'control_label' : control_label, 'window_id' : window_id, 'window_label' : window_label}
try:
lastDict = eg.globals.lastKodiControlDict
valueChange = [item for item in lastDict if lastDict[item] != currDict[item]]
for item in valueChange:
if item == 'control_label':
eg.TriggerEvent("Control." + str(currDict['control_label']), prefix="Kodi to RTI")
eg.plugins.RTISimpelTCPServer.SendString('Kodi_Control@' + str(currDict['control_label']) + '#')
if item == 'window_label':
eg.TriggerEvent("Window." + str(currDict['window_id']) + "." + str(currDict['window_label']), prefix="Kodi to RTI")
eg.plugins.RTISimpelTCPServer.SendString('Kodi_Window@' + str(currDict['window_id']) + "." + str(currDict['window_label']) + '#')
if item == 'channel_label':
eg.TriggerEvent("Playing." + str(currDict['channel_label']) + "." + str(currDict['channel_title']), prefix="Kodi to RTI")
eg.plugins.RTISimpelTCPServer.SendString('Kodi_Window@' + str(currDict['channel_label']) + "." + str(currDict['channel_title']) + '#')
except:
eg.Print('Kodi to RTI: First time run')
eg.globals.lastKodiControlDict = currDict
self._event.wait(0.1)
self._event = None
self._thread = None