From b12009f42256b103e2ee4b0e126f69b03b3f73c8 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Mon, 8 Feb 2016 02:36:09 -0600 Subject: [PATCH] New throttle - will require testing --- resources/lib/read_embyserver.py | 67 +++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/resources/lib/read_embyserver.py b/resources/lib/read_embyserver.py index 78e0bd91..774a9465 100644 --- a/resources/lib/read_embyserver.py +++ b/resources/lib/read_embyserver.py @@ -211,6 +211,8 @@ class Read_EmbyServer(): else: index = 0 jump = self.limitIndex + throttled = False + highestjump = 0 while index < total: # Get items by chunk to increase retrieval speed at scale @@ -239,13 +241,66 @@ class Read_EmbyServer(): "Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers," "MediaSources" ) - result = doUtils.downloadUrl(url, parameters=params) - items['Items'].extend(result['Items']) + result = doUtils(url, parameters=params) + + if result == "": + # Something happened to the connection. + if not throttled: + throttled = True + self.logMsg("Throttle activated.", 1) + elif jump == highestjump: + # We already adjusted to highestjump, but it failed. Reset value + self.logMsg("Reset highest value.", 1) + highestjump = 0 - index += jump - if dialog: - percentage = int((float(index) / float(total))*100) - dialog.update(percentage) + # Lower the number by half + if highestjump: + throttled = False + jump = highestjump + else: + jump = int(jump/2) + + self.logMsg("Set jump limit to recover: %s" % jump) + retry = 0 + while utils.window('emby_online') != "true": + # Wait server to come back online + if retry == 3: + self.logMsg("Server never came back online.") + return + + retry += 1 + if xbmc.Monitor().waitForAbort(1): + # Abort was requested while waiting. + return + else: + xbmc.Monitor().waitForAbort(3) + else: + items['Items'].extend(result['Items']) + index += jump + + if dialog: + percentage = int((float(index) / float(total))*100) + dialog.update(percentage) + + if jump > highestjump: + # Adjust with the latest number, if it's greater + highestjump = jump + + if throttled: + # We needed to adjust the number, keep increasing until. + if jump < highestjump: + # Found a number that already works, use it. + throttled = False + jump = highestjump + self.logMsg("Throttle deactivated with jump limit set to: %s" % jump, 1) + else: + # keep increasing until the connection times out again + increment = int(jump*0.33) + if not increment: # Incase the increment is 0 + increment += 10 + + jump += increment + self.logMsg("Increase jump limit to: %s" % jump, 1) return items def getViews(self, type, root=False):