diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/hooks/UpdateManager.py | 4 | ||||
-rw-r--r-- | module/plugins/hooks/UserAgentSwitcher.py | 27 |
2 files changed, 23 insertions, 8 deletions
diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 643b5c2d1..d66810d6d 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -117,7 +117,7 @@ class UpdateManager(Hook): return getURL(self.SERVER_URL, get={'v': self.core.api.getServerVersion()}).splitlines() except Exception: - self.logWarning(_("Unable to contact server to get updates")) + self.logWarning(_("Unable to retrieve server to get updates")) @Expose @@ -258,7 +258,7 @@ class UpdateManager(Hook): if self.core.pluginManager.reloadPlugins(updated): exitcode = 1 else: - self.logWarning(_("pyLoad restart required to reload the updated plugins")) + self.logWarning(_("Restart pyLoad to reload the updated plugins")) self.info['plugins'] = True exitcode = 2 diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index b0cf66709..912c2ef09 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -1,17 +1,24 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + +import os import pycurl +import random from module.plugins.Hook import Hook +from module.utils import fs_encode class UserAgentSwitcher(Hook): __name__ = "UserAgentSwitcher" __type__ = "hook" - __version__ = "0.03" + __version__ = "0.04" __config__ = [("activated", "bool", "Activated" , True ), - ("ua" , "str" , "Custom user-agent string", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] + ("uaf" , "file", "Random user-agents file" , "" ), + ("uar" , "bool", "Random user-agent" , False ), + ("uas" , "str" , "Custom user-agent string", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] __description__ = """Custom user-agent""" __license__ = "GPLv3" @@ -26,7 +33,15 @@ class UserAgentSwitcher(Hook): def downloadPreparing(self, pyfile): - ua = self.getConfig('ua') - if ua: - self.logDebug("Use custom user-agent string: " + ua) - pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, ua.encode('utf-8')) + uar = self.getConfig('uar') + uaf = fs_encode(self.getConfig('uaf')) + + if uar and os.path.isfile(uaf): + with open(uaf) as f: + uas = random.choice([ua for ua in f.read().splitlines()]) + else: + uas = self.getConfig('uas') + + if uas: + self.logDebug("Use custom user-agent string: " + uas) + pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, uas.encode('utf-8')) |