Merge pull request #305 from mcarlton00/incremental-sync

Only request updates for synced libraries
This commit is contained in:
Abby 2020-05-26 13:21:48 +01:00 committed by GitHub
commit 60e80254ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -372,17 +372,32 @@ class Library(threading.Thread):
''' Movie and userdata not provided by server yet.
'''
last_sync = settings('LastIncrementalSync')
include = []
filters = ["tvshows", "boxsets", "musicvideos", "music", "movies"]
sync = get_sync()
LOG.info("--[ retrieve changes ] %s", last_sync)
# Get the item type of each synced library and build list of types to request
for item_id in sync['Whitelist']:
library = self.server.jellyfin.get_item(item_id)
library_type = library.get('CollectionType')
if library_type in filters:
include.append(library_type)
# Include boxsets if movies are synced
if 'movies' in include:
include.append('boxsets')
# Filter down to the list of library types we want to exclude
query_filter = list(set(filters) - set(include))
try:
updated = []
userdata = []
removed = []
for media in filters:
result = self.server.jellyfin.get_sync_queue(last_sync, ",".join([x for x in filters if x != media]))
# Get list of updates from server for synced library types and populate work queues
result = self.server.jellyfin.get_sync_queue(last_sync, ",".join([ x for x in query_filter ]))
updated.extend(result['ItemsAdded'])
updated.extend(result['ItemsUpdated'])
userdata.extend(result['UserDataChanged'])
@ -403,22 +418,6 @@ class Library(threading.Thread):
self.userdata(userdata)
self.removed(removed)
"""
result = self.server.jellyfin.get_sync_queue(last_sync)
self.userdata(result['UserDataChanged'])
self.removed(result['ItemsRemoved'])
filters.extend(["tvshows", "boxsets", "musicvideos", "music"])
# Get only movies.
result = self.server.jellyfin.get_sync_queue(last_sync, ",".join(filters))
self.updated(result['ItemsAdded'])
self.updated(result['ItemsUpdated'])
self.userdata(result['UserDataChanged'])
self.removed(result['ItemsRemoved'])
"""
except Exception as error:
LOG.exception(error)
@ -715,10 +714,9 @@ class SortWorker(threading.Thread):
try:
media = database.get_media_by_id(item_id)
if media:
self.output[media].put({'Id': item_id, 'Type': media})
except Exception as error:
LOG.exception(error)
else:
items = database.get_media_by_parent_id(item_id)
if not items:
@ -726,6 +724,8 @@ class SortWorker(threading.Thread):
else:
for item in items:
self.output[item[1]].put({'Id': item[0], 'Type': item[1]})
except Exception as error:
LOG.exception(error)
self.queue.task_done()