diff options
Diffstat (limited to 'module/plugins/hooks/UserAgentSwitcher.py')
-rw-r--r-- | module/plugins/hooks/UserAgentSwitcher.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 5f9fd5212..52f542268 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -2,31 +2,37 @@ import pycurl -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon +from module.plugins.internal.Plugin import encode -class UserAgentSwitcher(Hook): +class UserAgentSwitcher(Addon): __name__ = "UserAgentSwitcher" __type__ = "hook" - __version__ = "0.07" + __version__ = "0.11" + __status__ = "testing" - __config__ = [("activated", "bool", "Activated" , True ), - ("useragent", "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")] + __config__ = [("activated" , "bool", "Activated" , True ), + ("connecttimeout", "int" , "Connection timeout in seconds" , 60 ), + ("maxredirs" , "int" , "Maximum number of redirects to follow" , 10 ), + ("useragent" , "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")] __description__ = """Custom user-agent""" __license__ = "GPLv3" __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - interval = 0 #@TODO: Remove in 0.4.10 + def download_preparing(self, pyfile): + connecttimeout = self.get_config('connecttimeout') + maxredirs = self.get_config('maxredirs') + useragent = self.get_config('useragent') + if connecttimeout: + pyfile.plugin.req.http.c.setopt(pycurl.CONNECTTIMEOUT, connecttimeout) - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 + if maxredirs: + pyfile.plugin.req.http.c.setopt(pycurl.MAXREDIRS, maxredirs) - - def downloadPreparing(self, pyfile): - useragent = self.getConfig('useragent').encode("utf8", "replace") #@TODO: Remove `encode` in 0.4.10 if useragent: - self.logDebug("Use custom user-agent string: " + useragent) - pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, useragent) + self.log_debug("Use custom user-agent string: " + useragent) + pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, encode(useragent)) |