From dd54cb27f38ea586cd37652b6c44d06110e1845a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sun, 3 May 2015 20:30:24 +0200 Subject: [PATCH] first work on the video nodes stuff --- resources/lib/KodiMonitor.py | 7 +- resources/lib/ReadKodiDB.py | 4 - resources/lib/WriteKodiDB.py | 141 ++++++++++++++++++++++++++++++++++- 3 files changed, 141 insertions(+), 11 deletions(-) diff --git a/resources/lib/KodiMonitor.py b/resources/lib/KodiMonitor.py index a2e789aa..be4688ef 100644 --- a/resources/lib/KodiMonitor.py +++ b/resources/lib/KodiMonitor.py @@ -28,12 +28,7 @@ class Kodi_Monitor(xbmc.Monitor): def onNotification (self,sender,method,data): addon = xbmcaddon.Addon(id='plugin.video.emby') downloadUtils = DownloadUtils() - print "onNotification:" + method + ":" + sender + ":" + str(data) - #player started playing an item - - if method == "Playlist.OnAdd": - print "playlist onadd is called" - - + if method == "VideoLibrary.OnUpdate": jsondata = json.loads(data) if jsondata != None: diff --git a/resources/lib/ReadKodiDB.py b/resources/lib/ReadKodiDB.py index 14c8c53a..ff41ae02 100644 --- a/resources/lib/ReadKodiDB.py +++ b/resources/lib/ReadKodiDB.py @@ -11,10 +11,6 @@ import os import Utils as utils - -#sleepval is used to throttle the calls to the xbmc json API -sleepVal = 15 - class ReadKodiDB(): diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index afce017a..4735e32d 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -20,7 +20,10 @@ from ReadEmbyDB import ReadEmbyDB from API import API import Utils as utils -sleepVal = 20 +from xml.etree.ElementTree import Element, SubElement, Comment, tostring +from xml.etree import ElementTree +from xml.dom import minidom +import xml.etree.cElementTree as ET class WriteKodiDB(): @@ -909,6 +912,7 @@ class WriteKodiDB(): sql="insert into tag(tag_id, name) values(?, ?)" cursor.execute(sql, (tag_id,tag)) utils.logMsg("AddTagToMedia", "Adding tag: " + tag) + self.addVideoNodesForTag(tag, mediatype) #assign tag to item if doRemove: @@ -931,6 +935,8 @@ class WriteKodiDB(): idTag = idTag + 1 sql="insert into tag(idTag, strTag) values(?, ?)" cursor.execute(sql, (idTag,tag)) + utils.logMsg("AddTagToMedia", "Adding tag: " + tag) + self.addVideoNodesForTag(tag, mediatype) #assign tag to item if doRemove: @@ -1026,6 +1032,139 @@ class WriteKodiDB(): return True + def addVideoNodesForTag(self, tagname, type): + + utils.logMsg("addVideoNodesForTag", "Creating nodes for tag: " + tagname) + libraryPath = xbmc.translatePath("special://userdata/library/video/emby/") + + if type == "movie": + type = "movies" + elif type == "tvshow": + type = "tvshows" + else: + return + + if not xbmcvfs.exists(libraryPath): + #create root node + xbmcvfs.mkdir(libraryPath) + nodefile = os.path.join(libraryPath, "index.xml") + root = Element("node", {"order":"1"}) + SubElement(root, "label").text = "Emby" + SubElement(root, "icon").text = "DefaultMovies.png" + try: + ET.ElementTree(root).write(nodefile, xml_declaration=True) + except: + ET.ElementTree(root).write(nodefile) + + #tagpath + libraryPath = xbmc.translatePath("special://userdata/library/video/emby/%s/" %tagname) + + if not xbmcvfs.exists(libraryPath): + #create tag node - index + xbmcvfs.mkdir(libraryPath) + nodefile = os.path.join(libraryPath, "index.xml") + root = Element("node", {"order":"1"}) + SubElement(root, "label").text = tagname + SubElement(root, "icon").text = "DefaultMovies.png" + try: + ET.ElementTree(root).write(nodefile, xml_declaration=True) + except: + ET.ElementTree(root).write(nodefile) + + #create tag node - all items + nodefile = os.path.join(libraryPath, tagname + "_all.xml") + root = Element("node", {"order":"1", "type":"filter"}) + SubElement(root, "label").text = tagname + SubElement(root, "match").text = "all" + SubElement(root, "content").text = type + SubElement(root, "icon").text = "DefaultMovies.png" + Rule = SubElement(root, "rule", {"field":"tag","operator":"is"}) + SubElement(Rule, "value").text = tagname + try: + ET.ElementTree(root).write(nodefile, xml_declaration=True) + except: + ET.ElementTree(root).write(nodefile) + + #create tag node - recent items + nodefile = os.path.join(libraryPath, tagname + "_recent.xml") + root = Element("node", {"order":"2", "type":"filter"}) + SubElement(root, "label").text = tagname + " - Recently added" + SubElement(root, "match").text = "all" + SubElement(root, "content").text = type + SubElement(root, "icon").text = "DefaultMovies.png" + Rule = SubElement(root, "rule", {"field":"tag","operator":"is"}) + SubElement(Rule, "value").text = tagname + SubElement(root, "order", {"direction":"descending"}).text = "dateadded" + #set limit to 25 --> currently hardcoded --> TODO: add a setting for this ? + SubElement(root, "limit").text = "25" + #exclude watched items --> currently hardcoded --> TODO: add a setting for this ? + Rule2 = SubElement(root, "rule", {"field":"playcount","operator":"is"}) + SubElement(Rule2, "value").text = "0" + + try: + ET.ElementTree(root).write(nodefile, xml_declaration=True) + except: + ET.ElementTree(root).write(nodefile) + + #create tag node - inprogress items + nodefile = os.path.join(libraryPath, tagname + "_progress.xml") + root = Element("node", {"order":"3", "type":"filter"}) + SubElement(root, "label").text = tagname + " - In progress" + SubElement(root, "match").text = "all" + SubElement(root, "content").text = type + SubElement(root, "icon").text = "DefaultMovies.png" + Rule = SubElement(root, "rule", {"field":"tag","operator":"is"}) + SubElement(Rule, "value").text = tagname + #set limit to 25 --> currently hardcoded --> TODO: add a setting for this ? + SubElement(root, "limit").text = "25" + Rule2 = SubElement(root, "rule", {"field":"inprogress","operator":"true"}) + + try: + ET.ElementTree(root).write(nodefile, xml_declaration=True) + except: + ET.ElementTree(root).write(nodefile) + + #add some additional nodes for episodes + if type == "tvshows": + #create tag node - recent episodes + nodefile = os.path.join(libraryPath, tagname + "_recent_episodes.xml") + root = Element("node", {"order":"3", "type":"filter"}) + SubElement(root, "label").text = tagname + " - Recently added episodes" + SubElement(root, "match").text = "all" + SubElement(root, "content").text = "episodes" + SubElement(root, "icon").text = "DefaultMovies.png" + Rule = SubElement(root, "rule", {"field":"tag","operator":"is"}) + SubElement(Rule, "value").text = tagname + SubElement(root, "order", {"direction":"descending"}).text = "dateadded" + #set limit to 25 --> currently hardcoded --> TODO: add a setting for this ? + SubElement(root, "limit").text = "25" + #exclude watched items --> currently hardcoded --> TODO: add a setting for this ? + Rule2 = SubElement(root, "rule", {"field":"playcount","operator":"is"}) + SubElement(Rule2, "value").text = "0" + + try: + ET.ElementTree(root).write(nodefile, xml_declaration=True) + except: + ET.ElementTree(root).write(nodefile) + + #create tag node - inprogress items + nodefile = os.path.join(libraryPath, tagname + "_progress_episodes.xml") + root = Element("node", {"order":"4", "type":"filter"}) + SubElement(root, "label").text = tagname + " - In progress episodes" + SubElement(root, "match").text = "all" + SubElement(root, "content").text = "episodes" + SubElement(root, "icon").text = "DefaultMovies.png" + Rule = SubElement(root, "rule", {"field":"tag","operator":"is"}) + SubElement(Rule, "value").text = tagname + #set limit to 25 --> currently hardcoded --> TODO: add a setting for this ? + SubElement(root, "limit").text = "25" + Rule2 = SubElement(root, "rule", {"field":"inprogress","operator":"true"}) + + try: + ET.ElementTree(root).write(nodefile, xml_declaration=True) + except: + ET.ElementTree(root).write(nodefile) + def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset, connection, cursor): strSet = boxset["Name"] cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(boxsetmovie["Id"],))