Fix userdata not correctly syncing

This commit is contained in:
tomkat83 2016-02-11 12:44:12 +01:00
parent 28517b509a
commit 413e48e19c
2 changed files with 24 additions and 14 deletions

View file

@ -237,9 +237,11 @@ class Items(object):
""" """
for mediaitem in xml: for mediaitem in xml:
API = PlexAPI.API(mediaitem) API = PlexAPI.API(mediaitem)
itemid = API.getRatingKey()
# Get key and db entry on the Kodi db side # Get key and db entry on the Kodi db side
fileid = self.emby_db.getItem_byId(itemid)[1] try:
fileid = self.emby_db.getItem_byId(API.getRatingKey())[1]
except:
continue
# Grab the user's viewcount, resume points etc. from PMS' answer # Grab the user's viewcount, resume points etc. from PMS' answer
userdata = API.getUserData() userdata = API.getUserData()
# Write to Kodi DB # Write to Kodi DB

View file

@ -218,7 +218,7 @@ class LibrarySync(threading.Thread):
self.__dict__ = self._shared_state self.__dict__ = self._shared_state
# How long should we look into the past for fast syncing items (in s) # How long should we look into the past for fast syncing items (in s)
self.syncPast = 60 self.syncPast = 30
self.clientInfo = clientinfo.ClientInfo() self.clientInfo = clientinfo.ClientInfo()
self.doUtils = downloadutils.DownloadUtils() self.doUtils = downloadutils.DownloadUtils()
@ -289,7 +289,7 @@ class LibrarySync(threading.Thread):
# Run through views and get latest changed elements using time diff # Run through views and get latest changed elements using time diff
self.updatelist = [] self.updatelist = []
self.allPlexElementsId = {} self.allPlexElementsId = {}
updateKodiVideoLib = False self.updateKodiVideoLib = False
for view in self.views: for view in self.views:
if self.threadStopped(): if self.threadStopped():
return True return True
@ -305,27 +305,27 @@ class LibrarySync(threading.Thread):
PlexFunctions.GetItemClassFromType(plexType), PlexFunctions.GetItemClassFromType(plexType),
PlexFunctions.GetMethodFromPlexType(plexType), PlexFunctions.GetMethodFromPlexType(plexType),
view['name'], view['name'],
view['id'], view['id'])
dontCheck=True)
# Process self.updatelist # Process self.updatelist
if self.updatelist: if self.updatelist:
if self.updatelist[0]['itemType'] in ['Movies', 'TVShows']: if self.updatelist[0]['itemType'] in ['Movies', 'TVShows']:
updateKodiVideoLib = True self.updateKodiVideoLib = True
self.GetAndProcessXMLs( self.GetAndProcessXMLs(
PlexFunctions.GetItemClassFromType(plexType)) PlexFunctions.GetItemClassFromType(plexType))
self.updatelist = [] self.updatelist = []
# Let Kodi grab the artwork now
if updateKodiVideoLib:
xbmc.executebuiltin('UpdateLibrary(video)')
# Update userdata # Update userdata
for view in self.views: for view in self.views:
self.PlexUpdateWatched( self.PlexUpdateWatched(
view['id'], view['id'],
PlexFunctions.GetItemClassFromType(view['itemtype']), PlexFunctions.GetItemClassFromType(view['itemtype']),
lastViewedAt=lastSync) lastViewedAt=lastSync)
# Let Kodi update the library now (artwork and userdata)
if self.updateKodiVideoLib:
xbmc.executebuiltin('UpdateLibrary(video)')
# Reset and return # Reset and return
self.allKodiElementsId = {} self.allKodiElementsId = {}
self.allPlexElementsId = {} self.allPlexElementsId = {}
xbmc.executebuiltin('UpdateLibrary(video)')
return True return True
def saveLastSync(self): def saveLastSync(self):
@ -787,10 +787,18 @@ class LibrarySync(threading.Thread):
xml = PlexFunctions.GetAllPlexLeaves(viewId, xml = PlexFunctions.GetAllPlexLeaves(viewId,
lastViewedAt=lastViewedAt, lastViewedAt=lastViewedAt,
updatedAt=updatedAt) updatedAt=updatedAt)
if xml: # Return if there are no items in PMS reply - it's faster
itemMth = getattr(itemtypes, itemType) try:
with itemMth() as method: xml[0].attrib
method.updateUserdata(xml) except (TypeError, AttributeError, IndexError):
return
if itemType in ['Movies', 'TVShows']:
self.updateKodiVideoLib = True
itemMth = getattr(itemtypes, itemType)
with itemMth() as method:
method.updateUserdata(xml)
def musicvideos(self, embycursor, kodicursor, pdialog): def musicvideos(self, embycursor, kodicursor, pdialog):
# Get musicvideos from emby # Get musicvideos from emby