From 27b21f214ea1eee1c3b8018e3134c2dc54d9e4c7 Mon Sep 17 00:00:00 2001 From: im85288 Date: Thu, 19 Mar 2015 17:40:29 +0000 Subject: [PATCH] added individual playcount update --- resources/lib/LibrarySync.py | 69 ++++++++++++++++++++++++++++++++++++ resources/lib/Player.py | 4 ++- resources/lib/ReadEmbyDB.py | 17 +++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 691969a3..b5d0c2c1 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -622,6 +622,75 @@ class LibrarySync(): return True + def updatePlayCount(self,itemID,type): + #update playcount of the itemID from MB3 to Kodi library + + addon = xbmcaddon.Addon(id='plugin.video.mb3sync') + WINDOW = xbmcgui.Window( 10000 ) + #process movie + if type=='Movie': + MB3Movie = ReadEmbyDB().getItem(itemID) + allKodiMovies = ReadKodiDB().getKodiMovies(False) + + if(self.ShouldStop()): + return True + + if(MB3Movie == None): + return False + + if(allKodiMovies == None): + return False + + kodiItem = None + for kodimovie in allKodiMovies: + if itemID in kodimovie["file"]: + kodiItem = kodimovie + break + + userData=API().getUserData(MB3Movie) + timeInfo = API().getTimeInfo(MB3Movie) + if kodiItem != None: + WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie") + kodiresume = int(round(kodiItem['resume'].get("position"))) + resume = int(round(float(timeInfo.get("ResumeTime"))))*60 + total = int(round(float(timeInfo.get("TotalTime"))))*60 + if kodiresume != resume: + WriteKodiDB().setKodiResumePoint(kodiItem['movieid'],resume,total,"movie") + + if(self.ShouldStop()): + return True + + #process episode + elif type=='Episode': + if(self.ShouldStop()): + return True + + MB3Episode = ReadEmbyDB().getItem(itemID) + kodiEpisodes = ReadKodiDB().getKodiEpisodes(MB3Episode.get("SeriesId"),False) + if (MB3Episode != None): + kodiItem = None + comparestring1 = str(MB3Episode.get("ParentIndexNumber")) + "-" + str(MB3Episode.get("IndexNumber")) + matchFound = False + if kodiEpisodes != None: + xbmc.log("episode playcount kodiepisodes found") + kodiItem = kodiEpisodes.get(comparestring1, None) + + userData=API().getUserData(MB3Episode) + timeInfo = API().getTimeInfo(MB3Episode) + if kodiItem != None: + if kodiItem['playcount'] != int(userData.get("PlayCount")): + WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode") + kodiresume = int(round(kodiItem['resume'].get("position"))) + resume = int(round(float(timeInfo.get("ResumeTime"))))*60 + total = int(round(float(timeInfo.get("TotalTime"))))*60 + if kodiresume != resume: + WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode") + + if(self.ShouldStop()): + return True + + return True + def ShouldStop(self): if(xbmc.Player().isPlaying() or xbmc.abortRequested): return True diff --git a/resources/lib/Player.py b/resources/lib/Player.py index f67e28a7..cb98ab8c 100644 --- a/resources/lib/Player.py +++ b/resources/lib/Player.py @@ -88,10 +88,12 @@ class Player( xbmc.Player ): item_id = data.get("item_id") refresh_id = data.get("refresh_id") currentFile = data.get("currentfile") + type = data.get("Type") if(refresh_id != None): #TODO: trigger update of single item, for now trigger full playcounts update - librarySync.updatePlayCounts() + xbmc.log("Invoking refresh of playcounts") + librarySync.updatePlayCount(item_id,type) if(currentPosition != None and self.hasData(runtime)): runtimeTicks = int(runtime) diff --git a/resources/lib/ReadEmbyDB.py b/resources/lib/ReadEmbyDB.py index 047096be..6c3299dd 100644 --- a/resources/lib/ReadEmbyDB.py +++ b/resources/lib/ReadEmbyDB.py @@ -41,6 +41,23 @@ class ReadEmbyDB(): return result + def getItem(self, id): + result = None + + addon = xbmcaddon.Addon(id='plugin.video.mb3sync') + port = addon.getSetting('port') + host = addon.getSetting('ipaddress') + server = host + ":" + port + + downloadUtils = DownloadUtils() + userid = downloadUtils.getUserId() + + jsonData = downloadUtils.downloadUrl("http://" + server + "/mediabrowser/Users/" + userid + "/Items/" + id + "?format=json&ImageTypeLimit=1", suppress=False, popup=1 ) + if jsonData != None and jsonData != "": + result = json.loads(jsonData) + + return result + def getTVShows(self, fullinfo = False, fullSync = False): result = None