Fix changed Plex metadata not synced repeatedly

This commit is contained in:
croneter 2017-09-06 19:24:26 +02:00
parent 81084ea479
commit da4be6d7e4

View file

@ -44,11 +44,6 @@ class LibrarySync(Thread):
def __init__(self, callback=None): def __init__(self, callback=None):
self.mgr = callback self.mgr = callback
# Dict of items we just processed in order to prevent a reprocessing
# caused by websocket
self.just_processed = {}
# How long do we wait until we start re-processing? (in seconds)
self.ignore_just_processed = 10*60
self.itemsToProcess = [] self.itemsToProcess = []
self.sessionKeys = [] self.sessionKeys = []
self.fanartqueue = Queue.Queue() self.fanartqueue = Queue.Queue()
@ -253,9 +248,6 @@ class LibrarySync(Thread):
# True: we're syncing only the delta, e.g. different checksum # True: we're syncing only the delta, e.g. different checksum
self.compare = not repair self.compare = not repair
# Empty our list of item's we've just processed in the past
self.just_processed = {}
self.new_items_only = True self.new_items_only = True
# This will also update playstates and userratings! # This will also update playstates and userratings!
log.info('Running fullsync for NEW PMS items with repair=%s' % repair) log.info('Running fullsync for NEW PMS items with repair=%s' % repair)
@ -619,7 +611,6 @@ class LibrarySync(Thread):
self.allPlexElementsId APPENDED(!!) dict self.allPlexElementsId APPENDED(!!) dict
= {itemid: checksum} = {itemid: checksum}
""" """
now = getUnixTimestamp()
if self.new_items_only is True: if self.new_items_only is True:
# Only process Plex items that Kodi does not already have in lib # Only process Plex items that Kodi does not already have in lib
for item in xml: for item in xml:
@ -627,8 +618,8 @@ class LibrarySync(Thread):
if not itemId: if not itemId:
# Skipping items 'title=All episodes' without a 'ratingKey' # Skipping items 'title=All episodes' without a 'ratingKey'
continue continue
self.allPlexElementsId[itemId] = ("K%s%s" % self.allPlexElementsId[itemId] = "K%s%s" % \
(itemId, item.attrib.get('updatedAt', ''))) (itemId, item.attrib.get('updatedAt', ''))
if itemId not in self.allKodiElementsId: if itemId not in self.allKodiElementsId:
self.updatelist.append({ self.updatelist.append({
'itemId': itemId, 'itemId': itemId,
@ -640,10 +631,8 @@ class LibrarySync(Thread):
'mediaType': item.attrib.get('type'), 'mediaType': item.attrib.get('type'),
'get_children': get_children 'get_children': get_children
}) })
self.just_processed[itemId] = now
return return
elif self.compare:
if self.compare:
# Only process the delta - new or changed items # Only process the delta - new or changed items
for item in xml: for item in xml:
itemId = item.attrib.get('ratingKey') itemId = item.attrib.get('ratingKey')
@ -667,7 +656,6 @@ class LibrarySync(Thread):
'mediaType': item.attrib.get('type'), 'mediaType': item.attrib.get('type'),
'get_children': get_children 'get_children': get_children
}) })
self.just_processed[itemId] = now
else: else:
# Initial or repair sync: get all Plex movies # Initial or repair sync: get all Plex movies
for item in xml: for item in xml:
@ -675,8 +663,8 @@ class LibrarySync(Thread):
if not itemId: if not itemId:
# Skipping items 'title=All episodes' without a 'ratingKey' # Skipping items 'title=All episodes' without a 'ratingKey'
continue continue
self.allPlexElementsId[itemId] = ("K%s%s" self.allPlexElementsId[itemId] = "K%s%s" \
% (itemId, item.attrib.get('updatedAt', ''))) % (itemId, item.attrib.get('updatedAt', ''))
self.updatelist.append({ self.updatelist.append({
'itemId': itemId, 'itemId': itemId,
'itemType': itemType, 'itemType': itemType,
@ -687,7 +675,6 @@ class LibrarySync(Thread):
'mediaType': item.attrib.get('type'), 'mediaType': item.attrib.get('type'),
'get_children': get_children 'get_children': get_children
}) })
self.just_processed[itemId] = now
def GetAndProcessXMLs(self, itemType): def GetAndProcessXMLs(self, itemType):
""" """
@ -1146,8 +1133,6 @@ class LibrarySync(Thread):
continue continue
else: else:
successful = self.process_newitems(item) successful = self.process_newitems(item)
if successful:
self.just_processed[str(item['ratingKey'])] = now
if successful and settings('FanartTV') == 'true': if successful and settings('FanartTV') == 'true':
plex_type = v.PLEX_TYPE_FROM_WEBSOCKET[item['type']] plex_type = v.PLEX_TYPE_FROM_WEBSOCKET[item['type']]
if plex_type in (v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_SHOW): if plex_type in (v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_SHOW):
@ -1247,14 +1232,6 @@ class LibrarySync(Thread):
if plex_id == '0': if plex_id == '0':
log.error('Received malformed PMS message: %s' % item) log.error('Received malformed PMS message: %s' % item)
continue continue
try:
if (now - self.just_processed[plex_id] <
self.ignore_just_processed and status != 9):
log.debug('We just processed %s: ignoring' % plex_id)
continue
except KeyError:
# Item has NOT just been processed
pass
# Have we already added this element? # Have we already added this element?
for existingItem in self.itemsToProcess: for existingItem in self.itemsToProcess:
if existingItem['ratingKey'] == plex_id: if existingItem['ratingKey'] == plex_id: