diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-02 12:36:47 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-02 12:36:47 +0100 |
commit | 2d77bbe784e5f107a3823f5b780e879478d1b37a (patch) | |
tree | f23f8e6e16426f5f4810eae031ddaa4249aa9a4c /module/plugins/hooks/RestartSlow.py | |
parent | [NetloadIn] Cleanup (diff) | |
download | pyload-2d77bbe784e5f107a3823f5b780e879478d1b37a.tar.xz |
New addon RestartSlow
Diffstat (limited to 'module/plugins/hooks/RestartSlow.py')
-rw-r--r-- | module/plugins/hooks/RestartSlow.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/module/plugins/hooks/RestartSlow.py b/module/plugins/hooks/RestartSlow.py new file mode 100644 index 000000000..0e9e213de --- /dev/null +++ b/module/plugins/hooks/RestartSlow.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +from pycurl import LOW_SPEED_LIMIT, LOW_SPEED_TIME + +from module.plugins.Hook import Hook + + +class RestartSlow(Hook): + __name__ = "RestartSlow" + __type__ = "hook" + __version__ = "0.01" + + __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)] + + __description__ = """Restart slow downloads""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + event_list = ["downloadStarts"] + + + def downloadStarts(self, pyfile, url, filename): + if self.getConfig("safe") and not pyfile.plugin.resumeDownload: + return + + type = "premium" if pyfile.plugin.premium else "free" + + 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)) + + + def downloadFailed(self, pyfile): + pyfile.plugin.req.http.c.setopt(LOW_SPEED_TIME, 30) + pyfile.plugin.req.http.c.setopt(LOW_SPEED_LIMIT, 5) |