From cf6531b2c87fea99fd03884636bac4c80d1b475d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 4 Oct 2015 20:09:55 +0200 Subject: Fixpack (3) --- module/plugins/hooks/Checksum.py | 4 +- module/plugins/hooks/ClickAndLoad.py | 122 --------------------------- module/plugins/hooks/ClickNLoad.py | 122 +++++++++++++++++++++++++++ module/plugins/hooks/ExternalScripts.py | 6 +- module/plugins/hooks/HotFolder.py | 5 +- module/plugins/hooks/IRCInterface.py | 4 +- module/plugins/hooks/LinkdecrypterComHook.py | 2 +- module/plugins/hooks/MultiHome.py | 71 +++++++++------- module/plugins/hooks/RestartFailed.py | 2 +- module/plugins/hooks/SkipRev.py | 2 +- module/plugins/hooks/XFileSharingPro.py | 4 +- 11 files changed, 175 insertions(+), 169 deletions(-) delete mode 100644 module/plugins/hooks/ClickAndLoad.py create mode 100644 module/plugins/hooks/ClickNLoad.py (limited to 'module/plugins/hooks') diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index 2a650768e..fe866563d 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -160,7 +160,8 @@ class Checksum(Addon): return elif check_action == "nothing": return - pyfile.plugin.fail(msg=msg) + + pyfile.plugin.fail(msg) def package_finished(self, pypack): @@ -187,6 +188,7 @@ class Checksum(Addon): local_file = fs_encode(fs_join(download_folder, data['NAME'])) algorithm = self.methods.get(file_type, file_type) checksum = compute_checksum(local_file, algorithm) + if checksum is data['HASH']: self.log_info(_('File integrity of "%s" verified by %s checksum (%s)') % (data['NAME'], algorithm, checksum)) diff --git a/module/plugins/hooks/ClickAndLoad.py b/module/plugins/hooks/ClickAndLoad.py deleted file mode 100644 index aef014d1a..000000000 --- a/module/plugins/hooks/ClickAndLoad.py +++ /dev/null @@ -1,122 +0,0 @@ -# -*- coding: utf-8 -*- - -import socket -import time - -try: - import ssl -except ImportError: - pass - -from threading import Lock - -from module.plugins.internal.Addon import Addon, threaded - - -def forward(source, destination): - try: - bufsize = 1024 - bufdata = source.recv(bufsize) - while bufdata: - destination.sendall(bufdata) - bufdata = source.recv(bufsize) - finally: - destination.shutdown(socket.SHUT_WR) - #: destination.close() - - -#@TODO: IPv6 support -class ClickAndLoad(Addon): - __name__ = "ClickAndLoad" - __type__ = "hook" - __version__ = "0.48" - __status__ = "testing" - - __config__ = [("activated", "bool" , "Activated" , True ), - ("port" , "int" , "Port" , 9666 ), - ("extern" , "bool" , "Listen for external connections", True ), - ("dest" , "queue;collector", "Add packages to" , "collector")] - - __description__ = """Click'n'Load hook plugin""" - __license__ = "GPLv3" - __authors__ = [("RaNaN" , "RaNaN@pyload.de" ), - ("Walter Purcaro", "vuolter@gmail.com")] - - - def activate(self): - if not self.pyload.config.get("webinterface", "activated"): - return - - ip = "" if self.get_config('extern') else "127.0.0.1" - webport = self.pyload.config.get("webinterface", "port") - cnlport = self.get_config('port') - - self.proxy(ip, webport, cnlport) - - - @threaded - def forward(self, source, destination, queue=False): - if queue: - old_ids = set(pack.id for pack in self.pyload.api.getCollector()) - - forward(source, destination) - - if queue: - new_ids = set(pack.id for pack in self.pyload.api.getCollector()) - for id in new_ids - old_ids: - self.pyload.api.pushToQueue(id) - - - @threaded - def proxy(self, ip, webport, cnlport): - time.sleep(10) #@TODO: Remove in 0.4.10 (implement addon delay on startup) - - self.log_info(_("Proxy listening on %s:%s") % (ip or "0.0.0.0", cnlport)) - - self._server(ip, webport, cnlport) - - lock = Lock() - lock.acquire() - lock.acquire() - - - @threaded - def _server(self, ip, webport, cnlport): - try: - dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - dock_socket.bind((ip, cnlport)) - dock_socket.listen(5) - - while True: - client_socket, client_addr = dock_socket.accept() - self.log_debug("Connection from %s:%s" % client_addr) - - server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - - if self.pyload.config.get("webinterface", "https"): - try: - server_socket = ssl.wrap_socket(server_socket) - - except NameError: - self.log_error(_("Missing SSL lib"), _("Please disable HTTPS in pyLoad settings")) - client_socket.close() - continue - - except Exception, e: - self.log_error(_("SSL error: %s") % e.message) - client_socket.close() - continue - - server_socket.connect(("127.0.0.1", webport)) - - self.forward(client_socket, server_socket, self.get_config('dest') is "queue") - self.forward(server_socket, client_socket) - - except socket.timeout: - self.log_debug("Connection timed out, retrying...") - return self._server(ip, webport, cnlport) - - except socket.error, e: - self.log_error(e) - time.sleep(240) - return self._server(ip, webport, cnlport) diff --git a/module/plugins/hooks/ClickNLoad.py b/module/plugins/hooks/ClickNLoad.py new file mode 100644 index 000000000..13975ecb5 --- /dev/null +++ b/module/plugins/hooks/ClickNLoad.py @@ -0,0 +1,122 @@ +# -*- coding: utf-8 -*- + +import socket +import time + +try: + import ssl +except ImportError: + pass + +from threading import Lock + +from module.plugins.internal.Addon import Addon, threaded + + +def forward(source, destination): + try: + bufsize = 1024 + bufdata = source.recv(bufsize) + while bufdata: + destination.sendall(bufdata) + bufdata = source.recv(bufsize) + finally: + destination.shutdown(socket.SHUT_WR) + #: destination.close() + + +#@TODO: IPv6 support +class ClickNLoad(Addon): + __name__ = "ClickNLoad" + __type__ = "hook" + __version__ = "0.48" + __status__ = "testing" + + __config__ = [("activated", "bool" , "Activated" , True ), + ("port" , "int" , "Port" , 9666 ), + ("extern" , "bool" , "Listen for external connections", True ), + ("dest" , "queue;collector", "Add packages to" , "collector")] + + __description__ = """Click'n'Load hook plugin""" + __license__ = "GPLv3" + __authors__ = [("RaNaN" , "RaNaN@pyload.de" ), + ("Walter Purcaro", "vuolter@gmail.com")] + + + def activate(self): + if not self.pyload.config.get("webinterface", "activated"): + return + + ip = "" if self.get_config('extern') else "127.0.0.1" + webport = self.pyload.config.get("webinterface", "port") + cnlport = self.get_config('port') + + self.proxy(ip, webport, cnlport) + + + @threaded + def forward(self, source, destination, queue=False): + if queue: + old_ids = set(pack.id for pack in self.pyload.api.getCollector()) + + forward(source, destination) + + if queue: + new_ids = set(pack.id for pack in self.pyload.api.getCollector()) + for id in new_ids - old_ids: + self.pyload.api.pushToQueue(id) + + + @threaded + def proxy(self, ip, webport, cnlport): + time.sleep(10) #@TODO: Remove in 0.4.10 (implement addon delay on startup) + + self.log_info(_("Proxy listening on %s:%s") % (ip or "0.0.0.0", cnlport)) + + self._server(ip, webport, cnlport) + + lock = Lock() + lock.acquire() + lock.acquire() + + + @threaded + def _server(self, ip, webport, cnlport): + try: + dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + dock_socket.bind((ip, cnlport)) + dock_socket.listen(5) + + while True: + client_socket, client_addr = dock_socket.accept() + self.log_debug("Connection from %s:%s" % client_addr) + + server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + if self.pyload.config.get("webinterface", "https"): + try: + server_socket = ssl.wrap_socket(server_socket) + + except NameError: + self.log_error(_("Missing SSL lib"), _("Please disable HTTPS in pyLoad settings")) + client_socket.close() + continue + + except Exception, e: + self.log_error(_("SSL error: %s") % e.message) + client_socket.close() + continue + + server_socket.connect(("127.0.0.1", webport)) + + self.forward(client_socket, server_socket, self.get_config('dest') is "queue") + self.forward(server_socket, client_socket) + + except socket.timeout: + self.log_debug("Connection timed out, retrying...") + return self._server(ip, webport, cnlport) + + except socket.error, e: + self.log_error(e) + time.sleep(240) + return self._server(ip, webport, cnlport) diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 32faebbed..09fe59d0a 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -11,7 +11,7 @@ from module.utils import fs_encode, save_join as fs_join class ExternalScripts(Addon): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.48" + __version__ = "0.49" __status__ = "testing" __config__ = [("activated", "bool", "Activated" , True ), @@ -26,7 +26,6 @@ class ExternalScripts(Addon): def init(self): - self.info['oldip'] = None self.scripts = {} self.event_list = ["archive_extract_failed", "archive_extracted" , @@ -115,13 +114,12 @@ class ExternalScripts(Addon): for script in self.scripts['before_reconnect']: args = [ip] self.call(script, args, lock) - self.info['oldip'] = ip def after_reconnect(self, ip, oldip): lock = self.get_config('lock') for script in self.scripts['after_reconnect']: - args = [ip, self.info['oldip']] #@TODO: Use built-in oldip in 0.4.10 + args = [ip, oldip] self.call(script, args, lock) diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index d556537aa..aeb432626 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -3,10 +3,9 @@ from __future__ import with_statement import os +import shutil import time -from shutil import move - from module.plugins.internal.Addon import Addon from module.utils import fs_encode, save_join as fs_join @@ -63,7 +62,7 @@ class HotFolder(Addon): continue newpath = os.path.join(folder, "finished", "tmp_" + f if self.get_config('delete') else f) - move(path, newpath) + shutil.move(path, newpath) self.log_info(_("Added %s from HotFolder") % f) self.pyload.api.addPackage(f, [newpath], 1) diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py index c84c0439d..6135b3244 100644 --- a/module/plugins/hooks/IRCInterface.py +++ b/module/plugins/hooks/IRCInterface.py @@ -2,12 +2,12 @@ import pycurl import re +import select import socket import ssl import time import traceback -from select import select from threading import Thread from module.Api import PackageDoesNotExists, FileDoesNotExists @@ -114,7 +114,7 @@ class IRCInterface(Thread, Addon): readbuffer = "" while True: time.sleep(1) - fdset = select([self.sock], [], [], 0) + fdset = select.select([self.sock], [], [], 0) if self.sock not in fdset[0]: continue diff --git a/module/plugins/hooks/LinkdecrypterComHook.py b/module/plugins/hooks/LinkdecrypterComHook.py index 7d39656d3..a318a78fa 100644 --- a/module/plugins/hooks/LinkdecrypterComHook.py +++ b/module/plugins/hooks/LinkdecrypterComHook.py @@ -23,7 +23,7 @@ class LinkdecrypterComHook(Addon): def get_hosters(self): - list = re.search(r'>Supported\(\d+\): (.[\w.-, ]+)', + list = re.search(r'>Supported\(\d+\): (.[\w\-., ]+)', self.load("http://linkdecrypter.com/").replace("(g)", "")).group(1).split(', ') try: list.remove("download.serienjunkies.org") diff --git a/module/plugins/hooks/MultiHome.py b/module/plugins/hooks/MultiHome.py index 929ab9a25..b1e3c8ada 100644 --- a/module/plugins/hooks/MultiHome.py +++ b/module/plugins/hooks/MultiHome.py @@ -5,6 +5,42 @@ 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 + self.history = {} + + + def last_plugin_access(self, pluginName, account): + if (pluginName, account) in self.history: + return self.history[(pluginName, account)] + else: + return 0 + + + def use_for(self, pluginName, account): + self.history[(pluginName, account)] = time.time() + + + def __repr__(self): + return "" % self.adress + + + class MultiHome(Addon): __name__ = "MultiHome" __type__ = "hook" @@ -42,44 +78,15 @@ class MultiHome(Addon): def activate(self): requestFactory = self.pyload.requestFactory - oldGetRequest = requestFactory.getRequest - - - def get_request(pluginName, account=None): - iface = self.best_interface(pluginName, account) - if iface: - iface.useFor(pluginName, account) - requestFactory.iface = lambda: iface.adress - self.log_debug("Using address", iface.adress) - return oldGetRequest(pluginName, account) - + oldGetRequest = requestFactory.getRequest requestFactory.getRequest = get_request def best_interface(self, pluginName, account): best = None + for interface in self.interfaces: if not best or interface.lastPluginAccess(pluginName, account) < best.lastPluginAccess(pluginName, account): best = interface - return best - - -class Interface(object): - - def __init__(self, adress): - self.adress = adress - self.history = {} - - def last_plugin_access(self, pluginName, account): - if (pluginName, account) in self.history: - return self.history[(pluginName, account)] - return 0 - - - def use_for(self, pluginName, account): - self.history[(pluginName, account)] = time.time() - - - def __repr__(self): - return "" % self.adress + return best diff --git a/module/plugins/hooks/RestartFailed.py b/module/plugins/hooks/RestartFailed.py index 812b68f76..e1498b0ae 100644 --- a/module/plugins/hooks/RestartFailed.py +++ b/module/plugins/hooks/RestartFailed.py @@ -20,7 +20,7 @@ class RestartFailed(Addon): def periodical(self): - self.log_debug("Restart failed downloads") + self.log_info(_("Restarting all failed downloads...")) self.pyload.api.restartFailed() diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index 5f9cfa452..1e0a495b4 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -74,7 +74,7 @@ class SkipRev(Addon): pyname = re.compile(r'%s\.part\d+\.rev$' % pyfile.name.rsplit('.', 2)[0].replace('.', '\.')) for link in self.pyload.api.getPackageData(pyfile.package().id).links: - if link.status == 4 and pyname.match(link.name): + if link.status is 4 and pyname.match(link.name): pylink = self._pyfile(link) if revtokeep > -1 or pyfile.name.endswith(".rev"): diff --git a/module/plugins/hooks/XFileSharingPro.py b/module/plugins/hooks/XFileSharingPro.py index 04438519b..70bafba67 100644 --- a/module/plugins/hooks/XFileSharingPro.py +++ b/module/plugins/hooks/XFileSharingPro.py @@ -23,9 +23,9 @@ class XFileSharingPro(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - regexp = {'hoster' : (r'https?://(?:www\.)?(?:\w+\.)*?(?P(?:[\d.]+|[\w-^_]{3,}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)/(?:embed-)?\w{12}(?:\W|$)', + regexp = {'hoster' : (r'https?://(?:www\.)?(?:\w+\.)*?(?P(?:[\d.]+|[\w\-^_]{3,}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)/(?:embed-)?\w{12}(?:\W|$)', r'https?://(?:[^/]+\.)?(?P%s)/(?:embed-)?\w+'), - 'crypter': (r'https?://(?:www\.)?(?:\w+\.)*?(?P(?:[\d.]+|[\w-^_]{3,}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)/(?:user|folder)s?/\w+', + 'crypter': (r'https?://(?:www\.)?(?:\w+\.)*?(?P(?:[\d.]+|[\w\-^_]{3,}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)/(?:user|folder)s?/\w+', r'https?://(?:[^/]+\.)?(?P%s)/(?:user|folder)s?/\w+')} BUILTIN_HOSTERS = [#WORKING HOSTERS: -- cgit v1.2.3