Sync new PMS items first
This commit is contained in:
parent
b0cde71fe3
commit
666ea9bc31
2 changed files with 64 additions and 32 deletions
|
@ -49,7 +49,8 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
items = {
|
items = {
|
||||||
'logLevel': 'plex_logLevel',
|
'logLevel': 'plex_logLevel',
|
||||||
'enableContext': 'plex_context',
|
'enableContext': 'plex_context',
|
||||||
'plex_restricteduser': 'plex_restricteduser'
|
'plex_restricteduser': 'plex_restricteduser',
|
||||||
|
'dbSyncIndicator': 'dbSyncIndicator'
|
||||||
}
|
}
|
||||||
for settings_value, window_value in items.iteritems():
|
for settings_value, window_value in items.iteritems():
|
||||||
if window(window_value) != settings(settings_value):
|
if window(window_value) != settings(settings_value):
|
||||||
|
|
|
@ -386,7 +386,7 @@ class LibrarySync(Thread):
|
||||||
|
|
||||||
self.syncThreadNumber = int(settings('syncThreadNumber'))
|
self.syncThreadNumber = int(settings('syncThreadNumber'))
|
||||||
self.installSyncDone = settings('SyncInstallRunDone') == 'true'
|
self.installSyncDone = settings('SyncInstallRunDone') == 'true'
|
||||||
self.showDbSync = settings('dbSyncIndicator') == 'true'
|
window('dbSyncIndicator', value=settings('dbSyncIndicator'))
|
||||||
self.enableMusic = settings('enableMusic') == "true"
|
self.enableMusic = settings('enableMusic') == "true"
|
||||||
self.enableBackgroundSync = settings(
|
self.enableBackgroundSync = settings(
|
||||||
'enableBackgroundSync') == "true"
|
'enableBackgroundSync') == "true"
|
||||||
|
@ -560,18 +560,32 @@ 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
|
||||||
|
|
||||||
|
self.new_items_only = True
|
||||||
|
log.info('Running fullsync for NEW PMS items with rapair=%s' % repair)
|
||||||
|
if self._fullSync() is False:
|
||||||
|
return False
|
||||||
|
self.new_items_only = False
|
||||||
|
log.info('Running fullsync for CHANGED PMS items with repair=%s'
|
||||||
|
% repair)
|
||||||
|
if self._fullSync() is False:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _fullSync(self):
|
||||||
xbmc.executebuiltin('InhibitIdleShutdown(true)')
|
xbmc.executebuiltin('InhibitIdleShutdown(true)')
|
||||||
screensaver = getScreensaver()
|
screensaver = getScreensaver()
|
||||||
setScreensaver(value="")
|
setScreensaver(value="")
|
||||||
|
|
||||||
# Add sources
|
if self.new_items_only is True:
|
||||||
sourcesXML()
|
# Only do the following once for new items
|
||||||
|
# Add sources
|
||||||
|
sourcesXML()
|
||||||
|
|
||||||
# Set views. Abort if unsuccessful
|
# Set views. Abort if unsuccessful
|
||||||
if not self.maintainViews():
|
if not self.maintainViews():
|
||||||
xbmc.executebuiltin('InhibitIdleShutdown(false)')
|
xbmc.executebuiltin('InhibitIdleShutdown(false)')
|
||||||
setScreensaver(value=screensaver)
|
setScreensaver(value=screensaver)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
process = {
|
process = {
|
||||||
'movies': self.PlexMovies,
|
'movies': self.PlexMovies,
|
||||||
|
@ -864,14 +878,34 @@ class LibrarySync(Thread):
|
||||||
self.allPlexElementsId APPENDED(!!) dict
|
self.allPlexElementsId APPENDED(!!) dict
|
||||||
= {itemid: checksum}
|
= {itemid: checksum}
|
||||||
"""
|
"""
|
||||||
|
if self.new_items_only is True:
|
||||||
|
# Only process Plex items that Kodi does not already have in lib
|
||||||
|
for item in xml:
|
||||||
|
itemId = item.attrib.get('ratingKey')
|
||||||
|
if not itemId:
|
||||||
|
# Skipping items 'title=All episodes' without a 'ratingKey'
|
||||||
|
continue
|
||||||
|
self.allPlexElementsId[itemId] = ("K%s%s" %
|
||||||
|
(itemId, item.attrib.get('updatedAt', '')))
|
||||||
|
if itemId not in self.allKodiElementsId:
|
||||||
|
self.updatelist.append({
|
||||||
|
'itemId': itemId,
|
||||||
|
'itemType': itemType,
|
||||||
|
'method': method,
|
||||||
|
'viewName': viewName,
|
||||||
|
'viewId': viewId,
|
||||||
|
'title': item.attrib.get('title', 'Missing Title'),
|
||||||
|
'mediaType': item.attrib.get('type')
|
||||||
|
})
|
||||||
|
return
|
||||||
|
|
||||||
if 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')
|
||||||
# Skipping items 'title=All episodes' without a 'ratingKey'
|
|
||||||
if not itemId:
|
if not itemId:
|
||||||
|
# Skipping items 'title=All episodes' without a 'ratingKey'
|
||||||
continue
|
continue
|
||||||
title = item.attrib.get('title', 'Missing Title Name')
|
|
||||||
plex_checksum = ("K%s%s"
|
plex_checksum = ("K%s%s"
|
||||||
% (itemId, item.attrib.get('updatedAt', '')))
|
% (itemId, item.attrib.get('updatedAt', '')))
|
||||||
self.allPlexElementsId[itemId] = plex_checksum
|
self.allPlexElementsId[itemId] = plex_checksum
|
||||||
|
@ -885,31 +919,29 @@ class LibrarySync(Thread):
|
||||||
'method': method,
|
'method': method,
|
||||||
'viewName': viewName,
|
'viewName': viewName,
|
||||||
'viewId': viewId,
|
'viewId': viewId,
|
||||||
'title': title,
|
'title': item.attrib.get('title', 'Missing Title'),
|
||||||
'mediaType': item.attrib.get('type')
|
'mediaType': item.attrib.get('type')
|
||||||
})
|
})
|
||||||
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:
|
||||||
itemId = item.attrib.get('ratingKey')
|
itemId = item.attrib.get('ratingKey')
|
||||||
# Skipping items 'title=All episodes' without a 'ratingKey'
|
|
||||||
if not itemId:
|
if not itemId:
|
||||||
|
# Skipping items 'title=All episodes' without a 'ratingKey'
|
||||||
continue
|
continue
|
||||||
title = item.attrib.get('title', 'Missing Title Name')
|
self.allPlexElementsId[itemId] = ("K%s%s"
|
||||||
plex_checksum = ("K%s%s"
|
% (itemId, item.attrib.get('updatedAt', '')))
|
||||||
% (itemId, item.attrib.get('updatedAt', '')))
|
|
||||||
self.allPlexElementsId[itemId] = plex_checksum
|
|
||||||
self.updatelist.append({
|
self.updatelist.append({
|
||||||
'itemId': itemId,
|
'itemId': itemId,
|
||||||
'itemType': itemType,
|
'itemType': itemType,
|
||||||
'method': method,
|
'method': method,
|
||||||
'viewName': viewName,
|
'viewName': viewName,
|
||||||
'viewId': viewId,
|
'viewId': viewId,
|
||||||
'title': title,
|
'title': item.attrib.get('title', 'Missing Title'),
|
||||||
'mediaType': item.attrib.get('type')
|
'mediaType': item.attrib.get('type')
|
||||||
})
|
})
|
||||||
|
|
||||||
def GetAndProcessXMLs(self, itemType, showProgress=True):
|
def GetAndProcessXMLs(self, itemType):
|
||||||
"""
|
"""
|
||||||
Downloads all XMLs for itemType (e.g. Movies, TV-Shows). Processes them
|
Downloads all XMLs for itemType (e.g. Movies, TV-Shows). Processes them
|
||||||
by then calling itemtypes.<itemType>()
|
by then calling itemtypes.<itemType>()
|
||||||
|
@ -961,19 +993,18 @@ class LibrarySync(Thread):
|
||||||
thread.start()
|
thread.start()
|
||||||
threads.append(thread)
|
threads.append(thread)
|
||||||
log.info("Processing thread spawned")
|
log.info("Processing thread spawned")
|
||||||
# Start one thread to show sync progress
|
# Start one thread to show sync progress ONLY for new PMS items
|
||||||
if showProgress:
|
if self.new_items_only is True and window('dbSyncIndicator') == 'true':
|
||||||
if self.showDbSync:
|
dialog = xbmcgui.DialogProgressBG()
|
||||||
dialog = xbmcgui.DialogProgressBG()
|
thread = ThreadedShowSyncInfo(
|
||||||
thread = ThreadedShowSyncInfo(
|
dialog,
|
||||||
dialog,
|
[getMetadataLock, processMetadataLock],
|
||||||
[getMetadataLock, processMetadataLock],
|
itemNumber,
|
||||||
itemNumber,
|
itemType)
|
||||||
itemType)
|
thread.setDaemon(True)
|
||||||
thread.setDaemon(True)
|
thread.start()
|
||||||
thread.start()
|
threads.append(thread)
|
||||||
threads.append(thread)
|
log.info("Kodi Infobox thread spawned")
|
||||||
log.info("Kodi Infobox thread spawned")
|
|
||||||
|
|
||||||
# Wait until finished
|
# Wait until finished
|
||||||
getMetadataQueue.join()
|
getMetadataQueue.join()
|
||||||
|
|
Loading…
Reference in a new issue