From ddb7ec4bbde23f5ceb8e24677b5de3f717308b82 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Sun, 17 May 2015 00:37:53 -0500 Subject: [PATCH] Second attempt at fixing playcount situation This should also reflect the actual Emby playcount. The websocket didn't echo, but what I did is kill the echo caused by the video library update after userdata change happens. --- resources/lib/API.py | 2 +- resources/lib/KodiMonitor.py | 34 ++++++++++++++++--------------- resources/lib/PlaybackUtils.py | 3 +++ resources/lib/Player.py | 2 +- resources/lib/WebSocketClient.py | 10 ++++----- resources/lib/WriteKodiVideoDB.py | 15 ++++++-------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/resources/lib/API.py b/resources/lib/API.py index f13c0de9..68caeae6 100644 --- a/resources/lib/API.py +++ b/resources/lib/API.py @@ -158,7 +158,7 @@ class API(): else: favorite=False if(userData.get("Played") == True): - playcount="1" + playcount= userData.get('PlayCount') else: playcount="0" if userData.get('UnplayedItemCount') != None: diff --git a/resources/lib/KodiMonitor.py b/resources/lib/KodiMonitor.py index 653b51f6..1b8699a2 100644 --- a/resources/lib/KodiMonitor.py +++ b/resources/lib/KodiMonitor.py @@ -34,22 +34,24 @@ class Kodi_Monitor(xbmc.Monitor): downloadUtils = DownloadUtils() if method == "VideoLibrary.OnUpdate": - jsondata = json.loads(data) - if jsondata != None: - - playcount = None - playcount = jsondata.get("playcount") - item = jsondata.get("item").get("id") - type = jsondata.get("item").get("type") - prop = WINDOW.getProperty('Played%s%s' % (type,item)) - processWatched = WINDOW.getProperty('played_skipWatched') - - if (playcount != None) and (prop != "true") and (processWatched != "true"): - WINDOW.setProperty("Played%s%s" % (type,item), "true") - utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2) - WriteKodiVideoDB().updatePlayCountFromKodi(item, type, playcount) - - self.clearProperty(type,item) + if WINDOW.getProperty('prevent_libraryUpdate') != "true": + jsondata = json.loads(data) + if jsondata != None: + + playcount = None + playcount = jsondata.get("playcount") + item = jsondata.get("item").get("id") + type = jsondata.get("item").get("type") + prop = WINDOW.getProperty('Played%s%s' % (type,item)) + processWatched = WINDOW.getProperty('played_skipWatched') + + if (playcount != None) and (prop != "true") and (processWatched != "true"): + WINDOW.setProperty("Played%s%s" % (type,item), "true") + utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2) + WriteKodiVideoDB().updatePlayCountFromKodi(item, type, playcount) + + self.clearProperty(type,item) + WINDOW.clearProperty('prevent_libraryUpdate') if method == "System.OnWake": xbmc.sleep(10000) #Allow network to wake up diff --git a/resources/lib/PlaybackUtils.py b/resources/lib/PlaybackUtils.py index 3b80b597..cac84968 100644 --- a/resources/lib/PlaybackUtils.py +++ b/resources/lib/PlaybackUtils.py @@ -101,6 +101,9 @@ class PlaybackUtils(): #show the additional resume dialog if launched from a widget if xbmc.getCondVisibility("Window.IsActive(home)"): + if userData.get("PlaybackPositionTicks") != 0: + reasonableTicks = int(userData.get("PlaybackPositionTicks")) / 1000 + seekTime = reasonableTicks / 10000 if seekTime != 0: displayTime = str(datetime.timedelta(seconds=seekTime)) display_list = [ self.language(30106) + ' ' + displayTime, self.language(30107)] diff --git a/resources/lib/Player.py b/resources/lib/Player.py index 4fb45d76..5f8dc484 100644 --- a/resources/lib/Player.py +++ b/resources/lib/Player.py @@ -296,7 +296,7 @@ class Player( xbmc.Player ): 'SubtitleStreamIndex': subtitleindex, 'playmethod': playMethod, 'Type': itemType, - 'PositionTicks': int(seekTime) + 'currentPosition': int(seekTime) } self.played_information[currentFile] = data self.logMsg("ADDING_FILE: %s" % self.played_information, 1) diff --git a/resources/lib/WebSocketClient.py b/resources/lib/WebSocketClient.py index 0fd37d01..14e074e6 100644 --- a/resources/lib/WebSocketClient.py +++ b/resources/lib/WebSocketClient.py @@ -32,6 +32,8 @@ class WebSocketThread(threading.Thread): doUtils = DownloadUtils() clientInfo = ClientInformation() KodiMonitor = KodiMonitor.Kodi_Monitor() + WINDOW = xbmcgui.Window(10000) + addonName = clientInfo.getAddonName() client = None @@ -101,13 +103,8 @@ class WebSocketThread(threading.Thread): messageType = result.get("MessageType") data = result.get("Data") WINDOW = xbmcgui.Window( 10000 ) - playedItemId = WINDOW.getProperty('played_itemId') - if (playedItemId != '') and (playedItemId in message): - # Prevent feedback for watched - WINDOW.clearProperty('played_itemId') - - elif(messageType != None and messageType == "Play" and data != None): + if(messageType != None and messageType == "Play" and data != None): itemIds = data.get("ItemIds") playCommand = data.get("PlayCommand") @@ -289,6 +286,7 @@ class WebSocketThread(threading.Thread): LibrarySync().IncrementalSync(itemsToUpdate) def user_data_update(self, userDataList): + self.WINDOW.setProperty('prevent_libraryUpdate', "true") itemsToUpdate = list() for userData in userDataList: itemId = userData.get("ItemId") diff --git a/resources/lib/WriteKodiVideoDB.py b/resources/lib/WriteKodiVideoDB.py index 33d1c76d..38c9ba5f 100644 --- a/resources/lib/WriteKodiVideoDB.py +++ b/resources/lib/WriteKodiVideoDB.py @@ -117,9 +117,8 @@ class WriteKodiVideoDB(): else: dateadded = None - playcount = 0 - if userData.get("PlayCount") == "1": - playcount = 1 + if userData.get("PlayCount") != "0": + playcount = int(userData.get('PlayCount')) else: playcount = None #playcount must be set to NULL in the db @@ -267,9 +266,8 @@ class WriteKodiVideoDB(): else: dateadded = None - playcount = 0 - if userData.get("PlayCount") == "1": - playcount = 1 + if userData.get("PlayCount") != "0": + playcount = int(userData.get('PlayCount')) else: playcount = None #playcount must be set to NULL in the db @@ -550,9 +548,8 @@ class WriteKodiVideoDB(): else: lastplayed = None - playcount = None - if userData.get("PlayCount") == "1": - playcount = 1 + if userData.get("PlayCount") != "0": + playcount = int(userData.get('PlayCount')) else: playcount = None #playcount must be set to NULL in the db