diff options
Diffstat (limited to 'module/plugins/hooks/RestartSlow.py')
-rw-r--r-- | module/plugins/hooks/RestartSlow.py | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/module/plugins/hooks/RestartSlow.py b/module/plugins/hooks/RestartSlow.py index 0e9e213de..587799235 100644 --- a/module/plugins/hooks/RestartSlow.py +++ b/module/plugins/hooks/RestartSlow.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from pycurl import LOW_SPEED_LIMIT, LOW_SPEED_TIME +import pycurl from module.plugins.Hook import Hook @@ -8,13 +8,13 @@ from module.plugins.Hook import Hook class RestartSlow(Hook): __name__ = "RestartSlow" __type__ = "hook" - __version__ = "0.01" + __version__ = "0.02" - __config__ = [("free_limit" , "int", "Transfer speed threshold in kilobytes" , 100 ), - ("free_time" , "int", "Sample interval in minutes" , 5 ), - ("premium_limit", "int", "Transfer speed threshold for premium download in kilobytes", 300 ), - ("premium_time" , "int", "Sample interval for premium download in minutes" , 2 ), - ("safe" , "bool", "Restart if download is resumable" , True)] + __config__ = [("free_limit" , "int" , "Transfer speed threshold in kilobytes" , 100 ), + ("free_time" , "int" , "Sample interval in minutes" , 5 ), + ("premium_limit", "int" , "Transfer speed threshold for premium download in kilobytes", 300 ), + ("premium_time" , "int" , "Sample interval for premium download in minutes" , 2 ), + ("safe_mode" , "bool", "Don't restart if download is not resumable" , True)] __description__ = """Restart slow downloads""" __license__ = "GPLv3" @@ -24,16 +24,38 @@ class RestartSlow(Hook): event_list = ["downloadStarts"] - def downloadStarts(self, pyfile, url, filename): - if self.getConfig("safe") and not pyfile.plugin.resumeDownload: + def setup(self): + self.info = {'chunk': {}} + + + def initPeriodical(self): + pass + + + def periodical(self): + if not self.pyfile.req.dl: return - type = "premium" if pyfile.plugin.premium else "free" + if self.getConfig("safe_mode") and not self.pyfile.plugin.resumeDownload: + time = 30 + limit = 5 + else: + type = "premium" if self.pyfile.plugin.premium else "free" + time = max(30, self.getConfig("%s_time" % type) * 60) + limit = max(5, self.getConfig("%s_limit" % type) * 1024) - pyfile.plugin.req.http.c.setopt(LOW_SPEED_TIME, max(30, self.getConfig("%s_time" % type) * 60)) - pyfile.plugin.req.http.c.setopt(LOW_SPEED_LIMIT, max(5, self.getConfig("%s_limit" % type) * 1024)) + chunks = [chunk for chunk in self.pyfile.req.dl.chunks \ + if chunk.id not in self.info['chunk'] or self.info['chunk'][chunk.id] not is (time, limit)] + for chunk in chunks: + chunk.c.setopt(pycurl.LOW_SPEED_TIME , time) + chunk.c.setopt(pycurl.LOW_SPEED_LIMIT, limit) + + self.info['chunk'][chunk.id] = (time, limit) + + + def downloadStarts(self, pyfile, url, filename): + if self.cb or (self.getConfig("safe_mode") and not pyfile.plugin.resumeDownload): + return - def downloadFailed(self, pyfile): - pyfile.plugin.req.http.c.setopt(LOW_SPEED_TIME, 30) - pyfile.plugin.req.http.c.setopt(LOW_SPEED_LIMIT, 5) + super(RestartSlow, self).initPeriodical() |