diff options
author | Nitzo <nitzo2001@yahoo.com> | 2016-04-05 00:48:04 +0200 |
---|---|---|
committer | Nitzo <nitzo2001@yahoo.com> | 2016-04-05 00:48:04 +0200 |
commit | 55e331cda19cb4ec3d9ef134de1f389f3c914e88 (patch) | |
tree | a0fa3b9ab08646c852680a2ba9f92f7e2d7d48ae | |
parent | Merge pull request #2404 from sodd/fix-ulozto-captcha (diff) | |
download | pyload-55e331cda19cb4ec3d9ef134de1f389f3c914e88.tar.xz |
[MultiHome] fix #2410
-rw-r--r-- | module/plugins/hooks/MultiHome.py | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/module/plugins/hooks/MultiHome.py b/module/plugins/hooks/MultiHome.py index a7c35c88f..ed00223d2 100644 --- a/module/plugins/hooks/MultiHome.py +++ b/module/plugins/hooks/MultiHome.py @@ -5,46 +5,33 @@ import time from module.plugins.internal.Addon import Addon -def get_request(pluginName, account=None): - iface = self.best_interface(pluginName, account) - - if not iface: - return - - iface.useFor(pluginName, account) - requestFactory.iface = lambda: iface.adress - self.log_debug("Using address", iface.adress) - - return oldGetRequest(pluginName, account) - - class Interface(object): - def __init__(self, adress): - self.adress = adress + def __init__(self, address): + self.address = address self.history = {} - def last_plugin_access(self, pluginName, account): - if (pluginName, account) in self.history: - return self.history[(pluginName, account)] + def last_plugin_access(self, plugin_name, account): + if (plugin_name, account) in self.history: + return self.history[(plugin_name, account)] else: return 0 - def use_for(self, pluginName, account): - self.history[(pluginName, account)] = time.time() + def use_for(self, plugin_name, account): + self.history[(plugin_name, account)] = time.time() def __repr__(self): - return "<Interface - %s>" % self.adress + return "<Interface - %s>" % self.address class MultiHome(Addon): __name__ = "MultiHome" __type__ = "hook" - __version__ = "0.16" + __version__ = "0.17" __status__ = "testing" __config__ = [("activated" , "bool", "Activated" , False ), @@ -52,12 +39,13 @@ class MultiHome(Addon): __description__ = """IP address changer""" __license__ = "GPLv3" - __authors__ = [("mkaay", "mkaay@mkaay.de")] + __authors__ = [("mkaay", "mkaay@mkaay.de" ), + (GammaC0de, "nitzo2001{AT]yahoo[DOT]com")] def init(self): - self.register = {} self.interfaces = [] + self.old_get_request = None self.parse_interfaces(self.config.get('interfaces').split(";")) @@ -67,7 +55,7 @@ class MultiHome(Addon): def to_config(self): - return ";".join(i.adress for i in self.interfaces) + return ";".join(i.address for i in self.interfaces) def parse_interfaces(self, interfaces): @@ -78,16 +66,37 @@ class MultiHome(Addon): def activate(self): - requestFactory = self.pyload.requestFactory - oldGetRequest = requestFactory.getRequest - requestFactory.getRequest = get_request + self.old_get_request = self.pyload.requestFactory.getRequest + + new_get_request = self.build_get_request() + self.pyload.requestFactory.getRequest = lambda *args: new_get_request(*args) - def best_interface(self, pluginName, account): + def best_interface(self, plugin_name, account): best = None for interface in self.interfaces: - if not best or interface.lastPluginAccess(pluginName, account) < best.lastPluginAccess(pluginName, account): + if not best or interface.last_plugin_access(plugin_name, account) < best.last_plugin_access(plugin_name, account): best = interface return best + + + def get_request(self, plugin_name, account=None): + iface = self.best_interface(plugin_name, account) + if iface is None: + self.log_warning(_("Best interface not found")) + return self.old_get_request(plugin_name, account) + + iface.use_for(plugin_name, account) + self.pyload.requestFactory.iface = lambda: iface.address + self.log_debug("Using address", iface.address) + + return self.old_get_request(plugin_name, account) + + + def build_get_request(self): + def resfunc(*args): + return self.get_request(*args) + + return resfunc
\ No newline at end of file |