Optimize notifications for library syncs

This commit is contained in:
tomkat83 2016-03-10 08:51:24 +01:00
parent 6d205b5804
commit 3ccc588945
3 changed files with 46 additions and 33 deletions

View file

@ -405,5 +405,6 @@
<string id="39404">Startup syncing process failed repeatedly. Try restarting Kodi. Stopping Sync for now.</string> <string id="39404">Startup syncing process failed repeatedly. Try restarting Kodi. Stopping Sync for now.</string>
<string id="39405">Plex playlists/nodes refreshed</string> <string id="39405">Plex playlists/nodes refreshed</string>
<string id="39406">Plex playlists/nodes refresh failed</string> <string id="39406">Plex playlists/nodes refresh failed</string>
<string id="39407">Full library sync finished</string>
</strings> </strings>

View file

@ -337,5 +337,6 @@
<string id="39404">Der Startup Synchronisations-Prozess der Plex Bibliotheken ist mehrmals fehlgeschlagen. Bitte Kodi neu starten. Synch wird jetzt gestoppt.</string> <string id="39404">Der Startup Synchronisations-Prozess der Plex Bibliotheken ist mehrmals fehlgeschlagen. Bitte Kodi neu starten. Synch wird jetzt gestoppt.</string>
<string id="39405">Plex Playlisten/Nodes aktualisiert</string> <string id="39405">Plex Playlisten/Nodes aktualisiert</string>
<string id="39406">Plex Playlisten/Nodes Aktualisierung fehlgeschlagen</string> <string id="39406">Plex Playlisten/Nodes Aktualisierung fehlgeschlagen</string>
<string id="39407">Plex Bibliotheken aktualisiert</string>
</strings> </strings>

View file

@ -70,7 +70,7 @@ class ThreadedGetMetadata(Thread):
# Did not receive a valid XML - skip that item for now # Did not receive a valid XML - skip that item for now
self.logMsg("Could not get metadata for %s. " self.logMsg("Could not get metadata for %s. "
"Skipping that item for now" "Skipping that item for now"
% updateItem['itemId'], -1) % updateItem['itemId'], 0)
# Increase BOTH counters - since metadata won't be processed # Increase BOTH counters - since metadata won't be processed
with lock: with lock:
getMetadataCount += 1 getMetadataCount += 1
@ -223,8 +223,8 @@ class LibrarySync(Thread):
self.user = userclient.UserClient() self.user = userclient.UserClient()
self.emby = embyserver.Read_EmbyServer() self.emby = embyserver.Read_EmbyServer()
self.vnodes = videonodes.VideoNodes() self.vnodes = videonodes.VideoNodes()
self.syncThreadNumber = int(utils.settings('syncThreadNumber'))
self.syncThreadNumber = int(utils.settings('syncThreadNumber'))
self.installSyncDone = True if \ self.installSyncDone = True if \
utils.settings('SyncInstallRunDone') == 'true' else False utils.settings('SyncInstallRunDone') == 'true' else False
self.showDbSync = True if \ self.showDbSync = True if \
@ -236,18 +236,30 @@ class LibrarySync(Thread):
Thread.__init__(self) Thread.__init__(self)
def showKodiNote(self, message, forced=False): def showKodiNote(self, message, forced=False, icon="plex"):
""" """
Shows a Kodi popup, if user selected to do so. Pass message in unicode Shows a Kodi popup, if user selected to do so. Pass message in unicode
or string or string
icon: "plex": shows Plex icon
"error": shows Kodi error icon
""" """
if not (self.showDbSync or forced): if not (self.showDbSync or forced):
return return
if icon == "plex":
xbmcgui.Dialog().notification( xbmcgui.Dialog().notification(
heading=self.addonName, heading=self.addonName,
message=message, message=message,
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png", icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
time=5000,
sound=False) sound=False)
elif icon == "error":
xbmcgui.Dialog().notification(
heading=self.addonName,
message=message,
icon=xbmcgui.NOTIFICATION_ERROR,
time=7000,
sound=True)
def fastSync(self): def fastSync(self):
""" """
@ -307,7 +319,8 @@ class LibrarySync(Thread):
elif self.updatelist[0]['itemType'] == 'Music': elif self.updatelist[0]['itemType'] == 'Music':
self.updateKodiMusicLib = True self.updateKodiMusicLib = True
self.GetAndProcessXMLs( self.GetAndProcessXMLs(
PlexFunctions.GetItemClassFromType(plexType)) PlexFunctions.GetItemClassFromType(plexType),
showProgress=False)
self.updatelist = [] self.updatelist = []
# Update userdata # Update userdata
@ -698,7 +711,7 @@ class LibrarySync(Thread):
'viewId': viewId, 'viewId': viewId,
'title': title}) 'title': title})
def GetAndProcessXMLs(self, itemType): def GetAndProcessXMLs(self, itemType, showProgress=True):
""" """
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>()
@ -706,6 +719,7 @@ class LibrarySync(Thread):
Input: Input:
itemType: 'Movies', 'TVShows', ... itemType: 'Movies', 'TVShows', ...
self.updatelist self.updatelist
showProgress If False, NEVER shows sync progress
""" """
# Some logging, just in case. # Some logging, just in case.
self.logMsg("self.updatelist: %s" % self.updatelist, 2) self.logMsg("self.updatelist: %s" % self.updatelist, 2)
@ -750,6 +764,7 @@ class LibrarySync(Thread):
threads.append(thread) threads.append(thread)
self.logMsg("Processing thread spawned", 1) self.logMsg("Processing thread spawned", 1)
# Start one thread to show sync progress # Start one thread to show sync progress
if showProgress:
if self.showDbSync: if self.showDbSync:
dialog = xbmcgui.DialogProgressBG() dialog = xbmcgui.DialogProgressBG()
thread = ThreadedShowSyncInfo( thread = ThreadedShowSyncInfo(
@ -1229,6 +1244,8 @@ class LibrarySync(Thread):
fullSync(manualrun=True) fullSync(manualrun=True)
window('emby_dbScan', clear=True) window('emby_dbScan', clear=True)
count = 0 count = 0
# Full library sync finished
self.showKodiNote(string(39407), forced=True)
# Reset views was requested from somewhere else # Reset views was requested from somewhere else
elif window('plex_runLibScan') == "views": elif window('plex_runLibScan') == "views":
log('Refresh playlist and nodes requested, starting', 0) log('Refresh playlist and nodes requested, starting', 0)
@ -1244,22 +1261,14 @@ class LibrarySync(Thread):
# Ran successfully # Ran successfully
log("Refresh playlists/nodes completed", 0) log("Refresh playlists/nodes completed", 0)
# "Plex playlists/nodes refreshed" # "Plex playlists/nodes refreshed"
dialog.notification( self.showKodiNote(string(39405), forced=True)
heading=self.addonName,
message=string(39405),
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
time=3000,
sound=True)
else: else:
# Failed # Failed
log("Refresh playlists/nodes failed", -1) log("Refresh playlists/nodes failed", -1)
# "Plex playlists/nodes refresh failed" # "Plex playlists/nodes refresh failed"
dialog.notification( self.showKodiNote(string(39406),
heading=self.addonName, forced=True,
message=string(39406), icon="error")
icon=xbmcgui.NOTIFICATION_ERROR,
time=3000,
sound=True)
window('emby_dbScan', clear=True) window('emby_dbScan', clear=True)
elif enableBackgroundSync: elif enableBackgroundSync:
# Run full lib scan approx every 30min # Run full lib scan approx every 30min
@ -1269,6 +1278,8 @@ class LibrarySync(Thread):
log('Running background full lib scan', 0) log('Running background full lib scan', 0)
fullSync(manualrun=True) fullSync(manualrun=True)
window('emby_dbScan', clear=True) window('emby_dbScan', clear=True)
# Full library sync finished
self.showKodiNote(string(39407), forced=False)
# Run fast sync otherwise (ever second or so) # Run fast sync otherwise (ever second or so)
else: else:
window('emby_dbScan', value="true") window('emby_dbScan', value="true")