Thanks! That helped a lot. I will post more later, but in case anyone else would like a working example of how you can access these plugins from code, I'll do a little snippet.
Short explanation:
Prior to this script I have another script that picks up fresh episode downloads and moves them into the right place in my tv library + writes a small log file with some details about this process. Then there's this script here below, that is started by a directory watcher when a new .log file is created. The purpose of the script is to start XBMC library updates for the show that just got a new episode + send a popup notification to the xbmc, so it will show on screen that there is a new episode available. I have (at the moment) two xbmc's to update, and wanted it to be easy to extend to more xbmcs in the future.
The 'trick' is how to associate an XBMCRepeater instance with a certain xbmc, which is done by storing a reference to the httpapi function for each xbmc instance in a dictionary, as shown below. When I add more xbmc's, I just add another entry in the xbmcs dict.
I'm just starting to get a hang of this Python thing, so any suggestions for improvements are most welcome
Code: Select all
import sys
import os
import re
FileName = ''.join(eg.event.payload)
BaseName = ''.join(os.path.basename(FileName))
#Ignore files not ending with .log and files starting with _
if BaseName[-4:] != '.log' or BaseName[0] == '_':
sys.exit()
# Reference to XBMCRepeater plugins linked to the xbmc's you want to update and notify + path to tv series in XBMC's library
xbmcs = {'Kontoret' : {'function' : eg.plugins.XBMC2.HTTPAPI, 'libpath' : 'Z:\\Video\\TV\\Series\\'},
'Stuegris' : {'function' : eg.plugins.XBMC3.HTTPAPI, 'libpath' : 'Z:\\Video\\TV\\Series\\'} }
LogContents = []
LogDict = {}
LogFile = open(FileName, 'r')
for LogLine in LogFile:
LogContents.append(LogLine)
LineTuple = LogLine.split(':',1)
if LineTuple[0] <> '':
LogDict[LineTuple[0].lstrip().rstrip()] = LineTuple[1].lstrip().rstrip()
LogFile.close()
for xbmc in xbmcs:
ScanPath = xbmcs[xbmc]['libpath'] + LogDict['Series name'] + '\\'
NotificationMsg = 'New Episode' + ',' + '{0} {1}x{2}'.format(LogDict['Series name'], LogDict['Season number'],LogDict['Episode number'])
try:
xbmcs[xbmc]['function']('ExecBuiltin', 'XBMC.updatelibrary(video, %s)' % (ScanPath), 5, False)
xbmcs[xbmc]['function']('ExecBuiltin', 'Notification(%s)' % (NotificationMsg), 5, False)
except Exception:
sys.exc_clear()
Now, one more question: What is the "5" for, in the HTTPAPI function call? I glanced at the source code for the plugin, and can see that the parameter is called 'category', but it doesn't seem to be used for anything inside the actual function?
-Tusse
Edit: Added try/except around HTTPAPI calls, to prevent the script from exiting if one of the xbmc's are turnet off.