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')
else:
PlaybackPositionTicks = ''
userKey = userData.get("Key", "")
return {'Watched' : watched,
'Favorite' : favorite,
'PlayCount': playcount,
'LastPlayedDate': LastPlayedDate,
'UnplayedItemCount' : UnplayedItemCount,
'PlaybackPositionTicks' : str(PlaybackPositionTicks)
'PlaybackPositionTicks' : str(PlaybackPositionTicks),
'Key' : userKey
}
def getGenre(self,item):

View file

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

View file

@ -57,7 +57,7 @@ class LibrarySync():
self.MoviesSync(True, False)
self.MusicVideosSync(True, False)
# set the install done setting
# set the install done setting
if(syncInstallRunDone == False and completed):
addon = xbmcaddon.Addon(id='plugin.video.emby') #force a new instance of the addon
addon.setSetting("SyncInstallRunDone", "true")
@ -155,6 +155,9 @@ class LibrarySync():
kodimovie = allKodiMovies.get(item["Id"], None)
else:
kodimovie = None
userData = API().getUserData(item)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), item.get('Id') + ";;" + item.get("Type"))
if(kodimovie != None):
#WriteKodiDB().updateMovieToKodiLibrary(item, kodimovie)
@ -340,7 +343,10 @@ class LibrarySync():
kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],True,True)
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
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
@ -519,6 +525,9 @@ class LibrarySync():
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
matchFound = False
userData = API().getUserData(item)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), item.get('Id') + ";;" + item.get("Type"))
if kodiEpisodes != None:
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
@ -775,6 +784,8 @@ class LibrarySync():
userData = API().getUserData(item)
timeInfo = API().getTimeInfo(item)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), item.get('Id') + ";;" + item.get("Type"))
if kodiItem != None:
kodiresume = int(round(kodiItem['resume'].get("position")))
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
@ -840,6 +851,9 @@ class LibrarySync():
userData=API().getUserData(episode)
timeInfo = API().getTimeInfo(episode)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), episode.get('Id') + ";;" + episode.get("Type"))
if kodiItem != None:
WINDOW = xbmcgui.Window( 10000 )
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"):
# for now just do a full playcount sync
self.logMsg("Message : Doing UserDataChanged calling updatePlayCounts()", 0)
LibrarySync().updatePlayCounts()
WINDOW = xbmcgui.Window( 10000 )
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):
self.logMsg("Error : " + str(error))