Make the UserDataChanged event only update the items that changed

To do this I have had to keep a Windows Prop list of all UserData Keys
to Emby Id
in this I have assumed there is a 1:1 mapping but this migh not be the
case
and it could be a one to many that need to be taken inot account
also is Luke can add it me might be able to get this info from the
server but that is not
there yet
This commit is contained in:
shaun 2015-04-03 10:41:39 +11:00
parent 6b6f77dbff
commit e9646407a0
4 changed files with 33 additions and 7 deletions

View file

@ -151,12 +151,14 @@ class API():
PlaybackPositionTicks = userData.get('PlaybackPositionTicks') PlaybackPositionTicks = userData.get('PlaybackPositionTicks')
else: else:
PlaybackPositionTicks = '' PlaybackPositionTicks = ''
userKey = userData.get("Key", "")
return {'Watched' : watched, return {'Watched' : watched,
'Favorite' : favorite, 'Favorite' : favorite,
'PlayCount': playcount, 'PlayCount': playcount,
'LastPlayedDate': LastPlayedDate, 'LastPlayedDate': LastPlayedDate,
'UnplayedItemCount' : UnplayedItemCount, 'UnplayedItemCount' : UnplayedItemCount,
'PlaybackPositionTicks' : str(PlaybackPositionTicks) 'PlaybackPositionTicks' : str(PlaybackPositionTicks),
'Key' : userKey
} }
def getGenre(self,item): def getGenre(self,item):

View file

@ -85,7 +85,6 @@ class Kodi_Monitor(xbmc.Monitor):
WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0].get('DefaultSubtitleStreamIndex'))) WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0].get('DefaultSubtitleStreamIndex')))
if method == "VideoLibrary.OnUpdate": if method == "VideoLibrary.OnUpdate":
jsondata = json.loads(data) jsondata = json.loads(data)
if jsondata != None: if jsondata != None:
@ -96,6 +95,7 @@ class Kodi_Monitor(xbmc.Monitor):
if playcount != None: if playcount != None:
utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2) utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2)
WriteKodiDB().updatePlayCountFromKodi(item, type, playcount) WriteKodiDB().updatePlayCountFromKodi(item, type, playcount)
if method == "VideoLibrary.OnRemove": if method == "VideoLibrary.OnRemove":
xbmc.log('Intercepted remove from sender: ' + sender + ' method: ' + method + ' data: ' + data) xbmc.log('Intercepted remove from sender: ' + sender + ' method: ' + method + ' data: ' + data)
WINDOW = xbmcgui.Window( 10000 ) WINDOW = xbmcgui.Window( 10000 )

View file

@ -57,7 +57,7 @@ class LibrarySync():
self.MoviesSync(True, False) self.MoviesSync(True, False)
self.MusicVideosSync(True, False) self.MusicVideosSync(True, False)
# set the install done setting # set the install done setting
if(syncInstallRunDone == False and completed): if(syncInstallRunDone == False and completed):
addon = xbmcaddon.Addon(id='plugin.video.emby') #force a new instance of the addon addon = xbmcaddon.Addon(id='plugin.video.emby') #force a new instance of the addon
addon.setSetting("SyncInstallRunDone", "true") addon.setSetting("SyncInstallRunDone", "true")
@ -156,6 +156,9 @@ class LibrarySync():
else: else:
kodimovie = None kodimovie = None
userData = API().getUserData(item)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), item.get('Id') + ";;" + item.get("Type"))
if(kodimovie != None): if(kodimovie != None):
#WriteKodiDB().updateMovieToKodiLibrary(item, kodimovie) #WriteKodiDB().updateMovieToKodiLibrary(item, kodimovie)
updated = WriteKodiDB().updateMovieToKodiLibrary_Batched(item, kodimovie) updated = WriteKodiDB().updateMovieToKodiLibrary_Batched(item, kodimovie)
@ -342,6 +345,9 @@ class LibrarySync():
if(self.ShouldStop(pDialog)): if(self.ShouldStop(pDialog)):
return False return False
userData = API().getUserData(episode)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), episode.get('Id') + ";;" + episode.get("Type"))
#we have to compare the lists somehow #we have to compare the lists somehow
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber")) comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
@ -519,6 +525,9 @@ class LibrarySync():
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber")) comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
matchFound = False matchFound = False
userData = API().getUserData(item)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), item.get('Id') + ";;" + item.get("Type"))
if kodiEpisodes != None: if kodiEpisodes != None:
KodiItem = kodiEpisodes.get(comparestring1, None) KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None): if(KodiItem != None):
@ -775,6 +784,8 @@ class LibrarySync():
userData = API().getUserData(item) userData = API().getUserData(item)
timeInfo = API().getTimeInfo(item) timeInfo = API().getTimeInfo(item)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), item.get('Id') + ";;" + item.get("Type"))
if kodiItem != None: if kodiItem != None:
kodiresume = int(round(kodiItem['resume'].get("position"))) kodiresume = int(round(kodiItem['resume'].get("position")))
resume = int(round(float(timeInfo.get("ResumeTime"))))*60 resume = int(round(float(timeInfo.get("ResumeTime"))))*60
@ -840,6 +851,9 @@ class LibrarySync():
userData=API().getUserData(episode) userData=API().getUserData(episode)
timeInfo = API().getTimeInfo(episode) timeInfo = API().getTimeInfo(episode)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), episode.get('Id') + ";;" + episode.get("Type"))
if kodiItem != None: if kodiItem != None:
WINDOW = xbmcgui.Window( 10000 ) WINDOW = xbmcgui.Window( 10000 )
WINDOW.setProperty("episodeid" + str(kodiItem['episodeid']), episode.get('Name') + ";;" + episode.get('Id')) WINDOW.setProperty("episodeid" + str(kodiItem['episodeid']), episode.get('Name') + ";;" + episode.get('Id'))

View file

@ -177,9 +177,19 @@ class WebSocketThread(threading.Thread):
elif(messageType != None and messageType == "UserDataChanged"): elif(messageType != None and messageType == "UserDataChanged"):
# for now just do a full playcount sync # for now just do a full playcount sync
self.logMsg("Message : Doing UserDataChanged calling updatePlayCounts()", 0) WINDOW = xbmcgui.Window( 10000 )
LibrarySync().updatePlayCounts() self.logMsg("Message : Doing UserDataChanged", 0)
userDataList = data.get("UserDataList")
self.logMsg("Message : Doing UserDataChanged : UserDataList : " + str(userDataList), 0)
if(userDataList != None):
for userData in userDataList:
self.logMsg("Message : Doing UserDataChanged : UserData : " + str(userData), 0)
userKey = userData.get("Key")
if(userKey != None):
embyItemId = WINDOW.getProperty("EmbyUserKey" + userKey).split(";;")
self.logMsg("Message : Doing UserDataChanged : window data : " + str(embyItemId), 0)
if(embyItemId != None and len(embyItemId) == 2):
LibrarySync().updatePlayCount(embyItemId[0], embyItemId[1])
def on_error(self, ws, error): def on_error(self, ws, error):
self.logMsg("Error : " + str(error)) self.logMsg("Error : " + str(error))