Use the new ItemId from the UserDataChanged WebSocket event

This commit is contained in:
shaun 2015-04-18 12:28:39 +10:00
parent 6f3f91b879
commit 9e004fa1a1
3 changed files with 48 additions and 54 deletions

View file

@ -169,7 +169,6 @@ class LibrarySync():
kodimovie = None kodimovie = None
userData = API().getUserData(item) userData = API().getUserData(item)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), item.get('Id') + ";;" + item.get("Type"))
if(kodimovie != None): if(kodimovie != None):
updated = WriteKodiDB().updateMovieToKodiLibrary_Batched(item, kodimovie, connection, cursor) updated = WriteKodiDB().updateMovieToKodiLibrary_Batched(item, kodimovie, connection, cursor)
@ -379,7 +378,6 @@ class LibrarySync():
return False return False
userData = API().getUserData(episode) userData = API().getUserData(episode)
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), episode.get('Id') + ";;" + episode.get("Type"))
if kodiEpisodes != None: if kodiEpisodes != None:
KodiItem = kodiEpisodes.get(episode.get("Id"), None) KodiItem = kodiEpisodes.get(episode.get("Id"), None)
@ -530,7 +528,6 @@ class LibrarySync():
matchFound = False matchFound = False
userData = API().getUserData(item) 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(item.get("Id"), None) KodiItem = kodiEpisodes.get(item.get("Id"), None)
@ -793,8 +790,6 @@ 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
@ -869,7 +864,6 @@ class LibrarySync():
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'))
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), episode.get('Id') + ";;" + episode.get("Type"))
WINDOW.setProperty(episode.get('Id'), "episode;;" + str(kodishow["tvshowid"]) + ";;" +str(kodiItem['episodeid'])) WINDOW.setProperty(episode.get('Id'), "episode;;" + str(kodishow["tvshowid"]) + ";;" +str(kodiItem['episodeid']))
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
@ -925,60 +919,62 @@ class LibrarySync():
return True return True
def updatePlayCount(self,itemID,type): def updatePlayCount(self, itemID):
#update playcount of the itemID from MB3 to Kodi library #update playcount of the itemID from MB3 to Kodi library
addon = xbmcaddon.Addon(id='plugin.video.emby') addon = xbmcaddon.Addon(id='plugin.video.emby')
WINDOW = xbmcgui.Window( 10000 ) WINDOW = xbmcgui.Window( 10000 )
#process movie
if type=='Movie':
MB3Movie = ReadEmbyDB().getItem(itemID)
kodiItem = ReadKodiDB().getKodiMovie(itemID)
if(self.ShouldStop(None)):
return False
if(MB3Movie == None): embyItem = ReadEmbyDB().getItem(itemID)
return False if(embyItem == None):
return False
type = embyItem.get("Type")
#process movie
if type == 'Movie':
kodiItem = ReadKodiDB().getKodiMovie(itemID)
if(kodiItem == None): if(kodiItem == None):
return False return False
userData=API().getUserData(MB3Movie) if(self.ShouldStop(None)):
timeInfo = API().getTimeInfo(MB3Movie) return False
if kodiItem != None:
userData = API().getUserData(embyItem)
timeInfo = API().getTimeInfo(embyItem)
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")
#write property forced will refresh the item in the list so playcount change is immediately visible
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie",True)
WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "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")
#write property forced will refresh the item in the list so playcount change is immediately visible
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie",True)
WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "movie")
if(self.ShouldStop(None)): if(self.ShouldStop(None)):
return False return False
#process episode #process episode
elif type=='Episode': elif type == 'Episode':
if(self.ShouldStop(None)): if(self.ShouldStop(None)):
return False return False
MB3Episode = ReadEmbyDB().getItem(itemID) kodiItem = ReadKodiDB().getKodiEpisodeByMbItem(embyItem["Id"], embyItem["SeriesId"])
kodiItem = ReadKodiDB().getKodiEpisodeByMbItem(MB3Episode["Id"], MB3Episode["SeriesId"])
if (MB3Episode != None): userData = API().getUserData(embyItem)
userData=API().getUserData(MB3Episode) timeInfo = API().getTimeInfo(embyItem)
timeInfo = API().getTimeInfo(MB3Episode)
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
total = int(round(float(timeInfo.get("TotalTime"))))*60 total = int(round(float(timeInfo.get("TotalTime"))))*60
if kodiresume != resume: if kodiresume != resume:
WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode") WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
#write property forced will refresh the item in the list so playcount change is immediately visible #write property forced will refresh the item in the list so playcount change is immediately visible
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode",True) WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode",True)
WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "episode") WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "episode")
if(self.ShouldStop(None)):
return False
return True return True

View file

@ -90,7 +90,7 @@ class Player( xbmc.Player ):
if(refresh_id != None): if(refresh_id != None):
#report updates playcount and resume status to Kodi and MB3 #report updates playcount and resume status to Kodi and MB3
librarySync.updatePlayCount(item_id,type) librarySync.updatePlayCount(item_id)
self.played_information.clear() self.played_information.clear()
@ -315,7 +315,7 @@ class Player( xbmc.Player ):
server = WINDOW.getProperty('server%s' % username) server = WINDOW.getProperty('server%s' % username)
watchedurl = "%s/mediabrowser/Users/%s/PlayedItems/%s" % (server, userid, id) watchedurl = "%s/mediabrowser/Users/%s/PlayedItems/%s" % (server, userid, id)
self.downloadUtils.downloadUrl(watchedurl, postBody="", type="POST") self.downloadUtils.downloadUrl(watchedurl, postBody="", type="POST")
librarySync.updatePlayCount(id,type) librarySync.updatePlayCount(id)
except: pass except: pass
WINDOW.clearProperty("virtualstrm") WINDOW.clearProperty("virtualstrm")

View file

@ -190,12 +190,10 @@ class WebSocketThread(threading.Thread):
if(userDataList != None): if(userDataList != None):
for userData in userDataList: for userData in userDataList:
self.logMsg("Message : Doing UserDataChanged : UserData : " + str(userData), 0) self.logMsg("Message : Doing UserDataChanged : UserData : " + str(userData), 0)
userKey = userData.get("Key") itemId = userData.get("ItemId")
if(userKey != None): if(itemId != None):
embyItemId = WINDOW.getProperty("EmbyUserKey" + userKey).split(";;") self.logMsg("Message : Doing UserDataChanged : calling updatePlayCount with ID : " + str(itemId), 0)
self.logMsg("Message : Doing UserDataChanged : window data : " + str(embyItemId), 0) LibrarySync().updatePlayCount(itemId)
if(embyItemId != None and len(embyItemId) == 2):
LibrarySync().updatePlayCount(embyItemId[0], embyItemId[1])
elif(messageType != None and messageType == "LibraryChanged"): elif(messageType != None and messageType == "LibraryChanged"):
foldersAddedTo = data.get("FoldersAddedTo") foldersAddedTo = data.get("FoldersAddedTo")