diff options
author | Stefano <l.stickell@yahoo.it> | 2013-07-24 14:24:51 +0200 |
---|---|---|
committer | Stefano <l.stickell@yahoo.it> | 2013-07-24 14:24:51 +0200 |
commit | 669b1e0ec048e1ed8aeb842b2570376e9ad96863 (patch) | |
tree | 4703826f0c65f84ec5e9f1bac2d9dbd50e3376fa | |
parent | DebridItaliaCom: two more hosters supported (diff) | |
download | pyload-669b1e0ec048e1ed8aeb842b2570376e9ad96863.tar.xz |
Fixed PEP 8 violations in Hooks
33 files changed, 574 insertions, 573 deletions
diff --git a/module/plugins/hooks/AlldebridCom.py b/module/plugins/hooks/AlldebridCom.py index 6818b8c43..d0e9b1f77 100644 --- a/module/plugins/hooks/AlldebridCom.py +++ b/module/plugins/hooks/AlldebridCom.py @@ -5,6 +5,7 @@ from module.network.RequestFactory import getURL from module.plugins.internal.MultiHoster import MultiHoster + class AlldebridCom(MultiHoster): __name__ = "AlldebridCom" __version__ = "0.13" @@ -23,6 +24,6 @@ class AlldebridCom(MultiHoster): def getHoster(self): https = "https" if self.getConfig("https") else "http" - page = getURL(https + "://www.alldebrid.com/api.php?action=get_host").replace("\"","").strip() - + page = getURL(https + "://www.alldebrid.com/api.php?action=get_host").replace("\"", "").strip() + return [x.strip() for x in page.split(",") if x.strip()] diff --git a/module/plugins/hooks/BypassCaptcha.py b/module/plugins/hooks/BypassCaptcha.py index e24a439af..bd718ea7e 100644 --- a/module/plugins/hooks/BypassCaptcha.py +++ b/module/plugins/hooks/BypassCaptcha.py @@ -26,6 +26,7 @@ from module.plugins.Hook import Hook PYLOAD_KEY = "4f771155b640970d5607f919a615bdefc67e7d32" + class BypassCaptchaException(Exception): def __init__(self, err): self.err = err @@ -39,6 +40,7 @@ class BypassCaptchaException(Exception): def __repr__(self): return "<BypassCaptchaException %s>" % self.err + class BypassCaptcha(Hook): __name__ = "BypassCaptcha" __version__ = "0.04" @@ -57,13 +59,10 @@ class BypassCaptcha(Hook): self.info = {} def getCredits(self): - response = getURL(self.GETCREDITS_URL, - post = {"key": self.getConfig("passkey")} - ) - - data = dict([x.split(' ',1) for x in response.splitlines()]) + response = getURL(self.GETCREDITS_URL, post={"key": self.getConfig("passkey")}) + + data = dict([x.split(' ', 1) for x in response.splitlines()]) return int(data['Left']) - def submit(self, captcha, captchaType="file", match=None): req = getRequest() @@ -72,39 +71,36 @@ class BypassCaptcha(Hook): req.c.setopt(LOW_SPEED_TIME, 80) try: - response = req.load(self.SUBMIT_URL, - post={"vendor_key": PYLOAD_KEY, - "key": self.getConfig("passkey"), - "gen_task_id": "1", - "file": (FORM_FILE, captcha)}, - multipart=True) + response = req.load(self.SUBMIT_URL, + post={"vendor_key": PYLOAD_KEY, + "key": self.getConfig("passkey"), + "gen_task_id": "1", + "file": (FORM_FILE, captcha)}, + multipart=True) finally: req.close() - data = dict([x.split(' ',1) for x in response.splitlines()]) + data = dict([x.split(' ', 1) for x in response.splitlines()]) if not data or "Value" not in data: raise BypassCaptchaException(response) - + result = data['Value'] ticket = data['TaskId'] - self.logDebug("result %s : %s" % (ticket,result)) + self.logDebug("result %s : %s" % (ticket, result)) return ticket, result def respond(self, ticket, success): try: - response = getURL(self.RESPOND_URL, - post={"task_id": ticket, - "key": self.getConfig("passkey"), - "cv": 1 if success else 0} - ) + response = getURL(self.RESPOND_URL, post={"task_id": ticket, "key": self.getConfig("passkey"), + "cv": 1 if success else 0}) except BadHeader, e: self.logError("Could not send response.", str(e)) def newCaptchaTask(self, task): if "service" in task.data: return False - + if not task.isTextual(): return False @@ -140,4 +136,4 @@ class BypassCaptcha(Hook): return task.data["ticket"] = ticket - task.setResult(result)
\ No newline at end of file + task.setResult(result) diff --git a/module/plugins/hooks/Captcha9kw.py b/module/plugins/hooks/Captcha9kw.py index cd622b7cd..e13f93dec 100755 --- a/module/plugins/hooks/Captcha9kw.py +++ b/module/plugins/hooks/Captcha9kw.py @@ -28,6 +28,7 @@ from module.network.HTTPRequest import BadHeader from module.plugins.Hook import Hook + class Captcha9kw(Hook): __name__ = "Captcha9kw" __version__ = "0.07" @@ -38,19 +39,20 @@ class Captcha9kw(Hook): ("confirm", "bool", "Confirm Captcha (Cost +6)", "False"), ("captchaperhour", "int", "Captcha per hour (max. 9999)", "9999"), ("prio", "int", "Prio 1-10 (Cost +1-10)", "0"), - ("timeout", "int", "Timeout (max. 300)", "220"), - ("passkey", "password", "API key", ""),] + ("timeout", "int", "Timeout (max. 300)", "220"), + ("passkey", "password", "API key", ""), ] __author_name__ = ("RaNaN") __author_mail__ = ("RaNaN@pyload.org") API_URL = "://www.9kw.eu/index.cgi" def setup(self): - self.API_URL = "https"+self.API_URL if self.getConfig("https") else "http"+self.API_URL + self.API_URL = "https" + self.API_URL if self.getConfig("https") else "http" + self.API_URL self.info = {} def getCredits(self): - response = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "pyload": "1", "source": "pyload", "action": "usercaptchaguthaben" }) + response = getURL(self.API_URL, get={"apikey": self.getConfig("passkey"), "pyload": "1", "source": "pyload", + "action": "usercaptchaguthaben"}) if response.isdigit(): self.logInfo(_("%s credits left") % response) @@ -72,27 +74,29 @@ class Captcha9kw(Hook): else: mouse = 0 - response = getURL(self.API_URL, post = { - "apikey": self.getConfig("passkey"), - "prio": self.getConfig("prio"), - "confirm": self.getConfig("confirm"), - "captchaperhour": self.getConfig("captchaperhour"), - "maxtimeout": self.getConfig("timeout"), - "pyload": "1", - "source": "pyload", - "base64": "1", - "mouse": mouse, - "file-upload-01": data, - "action": "usercaptchaupload" }) + response = getURL(self.API_URL, post={ + "apikey": self.getConfig("passkey"), + "prio": self.getConfig("prio"), + "confirm": self.getConfig("confirm"), + "captchaperhour": self.getConfig("captchaperhour"), + "maxtimeout": self.getConfig("timeout"), + "pyload": "1", + "source": "pyload", + "base64": "1", + "mouse": mouse, + "file-upload-01": data, + "action": "usercaptchaupload"}) if response.isdigit(): - self.logInfo(_("New CaptchaID from upload: %s : %s") % (response,task.captchaFile)) + self.logInfo(_("New CaptchaID from upload: %s : %s") % (response, task.captchaFile)) - for i in range(1, 100, 1): - response2 = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "id": response,"pyload": "1","source": "pyload", "action": "usercaptchacorrectdata" }) + for i in range(1, 100, 1): + response2 = getURL(self.API_URL, get={"apikey": self.getConfig("passkey"), "id": response, + "pyload": "1", "source": "pyload", + "action": "usercaptchacorrectdata"}) - if(response2 != ""): - break; + if response2 != "": + break time.sleep(3) @@ -126,35 +130,33 @@ class Captcha9kw(Hook): if "ticket" in task.data: try: - response = getURL(self.API_URL, - post={ "action": "usercaptchacorrectback", - "apikey": self.getConfig("passkey"), - "api_key": self.getConfig("passkey"), - "correct": "1", - "pyload": "1", - "source": "pyload", - "id": task.data["ticket"] } - ) + response = getURL(self.API_URL, + post={"action": "usercaptchacorrectback", + "apikey": self.getConfig("passkey"), + "api_key": self.getConfig("passkey"), + "correct": "1", + "pyload": "1", + "source": "pyload", + "id": task.data["ticket"]}) self.logInfo("Request correct: %s" % response) except BadHeader, e: self.logError("Could not send correct request.", str(e)) else: - self.logError("No CaptchaID for correct request (task %s) found." % task) + self.logError("No CaptchaID for correct request (task %s) found." % task) def captchaInvalid(self, task): if "ticket" in task.data: - + try: - response = getURL(self.API_URL, - post={ "action": "usercaptchacorrectback", - "apikey": self.getConfig("passkey"), - "api_key": self.getConfig("passkey"), - "correct": "2", - "pyload": "1", - "source": "pyload", - "id": task.data["ticket"] } - ) + response = getURL(self.API_URL, + post={"action": "usercaptchacorrectback", + "apikey": self.getConfig("passkey"), + "api_key": self.getConfig("passkey"), + "correct": "2", + "pyload": "1", + "source": "pyload", + "id": task.data["ticket"]}) self.logInfo("Request refund: %s" % response) except BadHeader, e: diff --git a/module/plugins/hooks/CaptchaBrotherhood.py b/module/plugins/hooks/CaptchaBrotherhood.py index bdf547827..69af96705 100644 --- a/module/plugins/hooks/CaptchaBrotherhood.py +++ b/module/plugins/hooks/CaptchaBrotherhood.py @@ -26,9 +26,9 @@ from time import sleep import Image from module.network.RequestFactory import getURL, getRequest -from module.network.HTTPRequest import BadHeader from module.plugins.Hook import Hook + class CaptchaBrotherhoodException(Exception): def __init__(self, err): self.err = err @@ -42,6 +42,7 @@ class CaptchaBrotherhoodException(Exception): def __repr__(self): return "<CaptchaBrotherhoodException %s>" % self.err + class CaptchaBrotherhood(Hook): __name__ = "CaptchaBrotherhood" __version__ = "0.04" @@ -49,10 +50,10 @@ class CaptchaBrotherhood(Hook): __config__ = [("activated", "bool", "Activated", False), ("username", "str", "Username", ""), ("force", "bool", "Force CT even if client is connected", False), - ("passkey", "password", "Password", ""),] + ("passkey", "password", "Password", "")] __author_name__ = ("RaNaN", "zoidberg") __author_mail__ = ("RaNaN@pyload.org", "zoidberg@mujmail.cz") - + API_URL = "http://www.captchabrotherhood.com/" def setup(self): @@ -60,8 +61,7 @@ class CaptchaBrotherhood(Hook): def getCredits(self): response = getURL(self.API_URL + "askCredits.aspx", - get = {"username": self.getConfig("username"), - "password": self.getConfig("passkey")}) + get={"username": self.getConfig("username"), "password": self.getConfig("passkey")}) if not response.startswith("OK"): raise CaptchaBrotherhoodException(response) else: @@ -70,14 +70,14 @@ class CaptchaBrotherhood(Hook): self.info["credits"] = credits return credits - def submit(self, captcha, captchaType="file", match=None): + def submit(self, captcha, captchaType="file", match=None): try: img = Image.open(captcha) output = StringIO.StringIO() self.logDebug("CAPTCHA IMAGE", img, img.format, img.mode) if img.format in ("GIF", "JPEG"): img.save(output, img.format) - else: + else: if img.mode != "RGB": img = img.convert("RGB") img.save(output, "JPEG") @@ -85,57 +85,55 @@ class CaptchaBrotherhood(Hook): output.close() except Exception, e: raise CaptchaBrotherhoodException("Reading or converting captcha image failed: %s" % e) - + req = getRequest() - url = "%ssendNewCaptcha.aspx?%s" % (self.API_URL, - urlencode({"username": self.getConfig("username"), - "password": self.getConfig("passkey"), - "captchaSource": "pyLoad", - "timeout": "80"}) - ) + url = "%ssendNewCaptcha.aspx?%s" % (self.API_URL, + urlencode({"username": self.getConfig("username"), + "password": self.getConfig("passkey"), + "captchaSource": "pyLoad", + "timeout": "80"})) req.c.setopt(pycurl.URL, url) req.c.setopt(pycurl.POST, 1) req.c.setopt(pycurl.POSTFIELDS, data) - req.c.setopt(pycurl.HTTPHEADER, [ "Content-Type: text/html" ]) + req.c.setopt(pycurl.HTTPHEADER, ["Content-Type: text/html"]) try: req.c.perform() response = req.getResponse() except Exception, e: raise CaptchaBrotherhoodException("Submit captcha image failed") - + req.close() if not response.startswith("OK"): raise CaptchaBrotherhoodException(response[1]) - + ticket = response[3:] - + for i in range(15): sleep(5) response = self.get_api("askCaptchaResult", ticket) if response.startswith("OK-answered"): - return ticket, response[12:] + return ticket, response[12:] raise CaptchaBrotherhoodException("No solution received in time") def get_api(self, api, ticket): - response = getURL("%s%s.aspx" % (self.API_URL, api), + response = getURL("%s%s.aspx" % (self.API_URL, api), get={"username": self.getConfig("username"), "password": self.getConfig("passkey"), - "captchaID": ticket} - ) + "captchaID": ticket}) if not response.startswith("OK"): raise CaptchaBrotherhoodException("Unknown response: %s" % response) - + return response def newCaptchaTask(self, task): if "service" in task.data: return False - + if not task.isTextual(): return False @@ -166,4 +164,4 @@ class CaptchaBrotherhood(Hook): return task.data["ticket"] = ticket - task.setResult(result)
\ No newline at end of file + task.setResult(result) diff --git a/module/plugins/hooks/CaptchaTrader.py b/module/plugins/hooks/CaptchaTrader.py index c648c0bd8..51bb75a17 100644 --- a/module/plugins/hooks/CaptchaTrader.py +++ b/module/plugins/hooks/CaptchaTrader.py @@ -16,21 +16,17 @@ @author: mkaay, RaNaN """ -try: - from json import loads -except ImportError: - from simplejson import loads - from thread import start_new_thread from pycurl import FORM_FILE, LOW_SPEED_TIME +from module.common.json_layer import json_loads from module.network.RequestFactory import getURL, getRequest from module.network.HTTPRequest import BadHeader - from module.plugins.Hook import Hook PYLOAD_KEY = "9f65e7f381c3af2b076ea680ae96b0b7" + class CaptchaTraderException(Exception): def __init__(self, err): self.err = err @@ -44,14 +40,15 @@ class CaptchaTraderException(Exception): def __repr__(self): return "<CaptchaTraderException %s>" % self.err + class CaptchaTrader(Hook): __name__ = "CaptchaTrader" - __version__ = "0.15" + __version__ = "0.16" __description__ = """send captchas to captchatrader.com""" __config__ = [("activated", "bool", "Activated", False), ("username", "str", "Username", ""), ("force", "bool", "Force CT even if client is connected", False), - ("passkey", "password", "Password", ""),] + ("passkey", "password", "Password", ""), ] __author_name__ = ("RaNaN") __author_mail__ = ("RaNaN@pyload.org") @@ -64,8 +61,8 @@ class CaptchaTrader(Hook): def getCredits(self): json = getURL(CaptchaTrader.GETCREDITS_URL % {"user": self.getConfig("username"), - "password": self.getConfig("passkey")}) - response = loads(json) + "password": self.getConfig("passkey")}) + response = json_loads(json) if response[0] < 0: raise CaptchaTraderException(response[1]) else: @@ -88,31 +85,31 @@ class CaptchaTrader(Hook): try: json = req.load(CaptchaTrader.SUBMIT_URL, post={"api_key": PYLOAD_KEY, - "username": self.getConfig("username"), - "password": self.getConfig("passkey"), - "value": (FORM_FILE, captcha), - "type": captchaType}, multipart=True) + "username": self.getConfig("username"), + "password": self.getConfig("passkey"), + "value": (FORM_FILE, captcha), + "type": captchaType}, multipart=True) finally: req.close() - response = loads(json) + response = json_loads(json) if response[0] < 0: raise CaptchaTraderException(response[1]) ticket = response[0] result = response[1] - self.logDebug("result %s : %s" % (ticket,result)) + self.logDebug("result %s : %s" % (ticket, result)) return ticket, result def respond(self, ticket, success): try: json = getURL(CaptchaTrader.RESPOND_URL, post={"is_correct": 1 if success else 0, - "username": self.getConfig("username"), - "password": self.getConfig("passkey"), - "ticket": ticket}) + "username": self.getConfig("username"), + "password": self.getConfig("passkey"), + "ticket": ticket}) - response = loads(json) + response = json_loads(json) if response[0] < 0: raise CaptchaTraderException(response[1]) diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index b290838bb..fa95d1065 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -17,7 +17,8 @@ @author: zoidberg """ from __future__ import with_statement -import hashlib, zlib +import hashlib +import zlib from os import remove from os.path import getsize, isfile, splitext import re @@ -25,29 +26,31 @@ import re from module.utils import save_join, fs_encode from module.plugins.Hook import Hook -def computeChecksum(local_file, algorithm): + +def computeChecksum(local_file, algorithm): if algorithm in getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")): h = getattr(hashlib, algorithm)() chunk_size = 128 * h.block_size - - with open(local_file, 'rb') as f: - for chunk in iter(lambda: f.read(chunk_size), ''): - h.update(chunk) - + + with open(local_file, 'rb') as f: + for chunk in iter(lambda: f.read(chunk_size), ''): + h.update(chunk) + return h.hexdigest() - + elif algorithm in ("adler32", "crc32"): hf = getattr(zlib, algorithm) last = 0 - - with open(local_file, 'rb') as f: - for chunk in iter(lambda: f.read(8192), ''): + + with open(local_file, 'rb') as f: + for chunk in iter(lambda: f.read(8192), ''): last = hf(chunk, last) - + return "%x" % last - + else: - return None + return None + class Checksum(Hook): __name__ = "Checksum" @@ -58,48 +61,49 @@ class Checksum(Hook): ("max_tries", "int", "Number of retries", 2)] __author_name__ = ("zoidberg") __author_mail__ = ("zoidberg@mujmail.cz") - - methods = { 'sfv':'crc32', 'crc': 'crc32', 'hash': 'md5'} - regexps = { 'sfv': r'^(?P<name>[^;].+)\s+(?P<hash>[0-9A-Fa-f]{8})$', - 'md5': r'^(?P<name>[0-9A-Fa-f]{32}) (?P<file>.+)$', - 'crc': r'filename=(?P<name>.+)\nsize=(?P<size>\d+)\ncrc32=(?P<hash>[0-9A-Fa-f]{8})$', - 'default': r'^(?P<hash>[0-9A-Fa-f]+)\s+\*?(?P<name>.+)$' } - - def setup(self): + + methods = {'sfv': 'crc32', 'crc': 'crc32', 'hash': 'md5'} + regexps = {'sfv': r'^(?P<name>[^;].+)\s+(?P<hash>[0-9A-Fa-f]{8})$', + 'md5': r'^(?P<name>[0-9A-Fa-f]{32}) (?P<file>.+)$', + 'crc': r'filename=(?P<name>.+)\nsize=(?P<size>\d+)\ncrc32=(?P<hash>[0-9A-Fa-f]{8})$', + 'default': r'^(?P<hash>[0-9A-Fa-f]+)\s+\*?(?P<name>.+)$'} + + def setup(self): if not self.config['general']['checksum']: self.logInfo("Checksum validation is disabled in general configuration") - self.algorithms = sorted(getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")), reverse = True) - self.algorithms.extend(["crc32", "adler32"]) - self.formats = self.algorithms + ['sfv', 'crc', 'hash'] - + self.algorithms = sorted( + getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")), reverse=True) + self.algorithms.extend(["crc32", "adler32"]) + self.formats = self.algorithms + ['sfv', 'crc', 'hash'] + def downloadFinished(self, pyfile): """ Compute checksum for the downloaded file and compare it with the hash provided by the hoster. pyfile.plugin.check_data should be a dictionary which can contain: a) if known, the exact filesize in bytes (e.g. "size": 123456789) b) hexadecimal hash string with algorithm name as key (e.g. "md5": "d76505d0869f9f928a17d42d66326307") - """ + """ if hasattr(pyfile.plugin, "check_data") and (isinstance(pyfile.plugin.check_data, dict)): - data = pyfile.plugin.check_data.copy() + data = pyfile.plugin.check_data.copy() elif hasattr(pyfile.plugin, "api_data") and (isinstance(pyfile.plugin.api_data, dict)): - data = pyfile.plugin.api_data.copy() + data = pyfile.plugin.api_data.copy() else: - return - - self.logDebug(data) - + return + + self.logDebug(data) + if not pyfile.plugin.lastDownload: - self.checkFailed(pyfile, None, "No file downloaded") - + self.checkFailed(pyfile, None, "No file downloaded") + local_file = fs_encode(pyfile.plugin.lastDownload) #download_folder = self.config['general']['download_folder'] #local_file = fs_encode(save_join(download_folder, pyfile.package().folder, pyfile.name)) - + if not isfile(local_file): - self.checkFailed(pyfile, None, "File does not exist") - - # validate file size + self.checkFailed(pyfile, None, "File does not exist") + + # validate file size if "size" in data: api_size = int(data['size']) file_size = getsize(local_file) @@ -107,63 +111,72 @@ class Checksum(Hook): self.logWarning("File %s has incorrect size: %d B (%d expected)" % (pyfile.name, file_size, api_size)) self.checkFailed(pyfile, local_file, "Incorrect file size") del data['size'] - + # validate checksum - if data and self.config['general']['checksum']: + if data and self.config['general']['checksum']: if "checksum" in data: data['md5'] = data['checksum'] - + for key in self.algorithms: - if key in data: - checksum = computeChecksum(local_file, key.replace("-","").lower()) + if key in data: + checksum = computeChecksum(local_file, key.replace("-", "").lower()) if checksum: if checksum == data[key]: - self.logInfo('File integrity of "%s" verified by %s checksum (%s).' % (pyfile.name, key.upper(), checksum)) + self.logInfo('File integrity of "%s" verified by %s checksum (%s).' % (pyfile.name, + key.upper(), + checksum)) return else: - self.logWarning("%s checksum for file %s does not match (%s != %s)" % (key.upper(), pyfile.name, checksum, data[key])) + self.logWarning("%s checksum for file %s does not match (%s != %s)" % (key.upper(), + pyfile.name, + checksum, + data[key])) self.checkFailed(pyfile, local_file, "Checksums do not match") else: - self.logWarning("Unsupported hashing algorithm: %s" % key.upper()) + self.logWarning("Unsupported hashing algorithm: %s" % key.upper()) else: - self.logWarning("Unable to validate checksum for file %s" % (pyfile.name)) - + self.logWarning("Unable to validate checksum for file %s" % pyfile.name) + def checkFailed(self, pyfile, local_file, msg): action = self.getConfig("action") if action == "fail": - pyfile.plugin.fail(reason = msg) + pyfile.plugin.fail(reason=msg) elif action == "retry": if local_file: remove(local_file) - pyfile.plugin.retry(reason = msg, max_tries = self.getConfig("max_tries")) + pyfile.plugin.retry(reason=msg, max_tries=self.getConfig("max_tries")) - def packageFinished(self, pypack): download_folder = save_join(self.config['general']['download_folder'], pypack.folder, "") - + for link in pypack.getChildren().itervalues(): file_type = splitext(link["name"])[1][1:].lower() #self.logDebug(link, file_type) - + if file_type not in self.formats: continue - - hash_file = fs_encode(save_join(download_folder, link["name"])) + + hash_file = fs_encode(save_join(download_folder, link["name"])) if not isfile(hash_file): self.logWarning("File not found: %s" % link["name"]) continue - + with open(hash_file) as f: text = f.read() - + for m in re.finditer(self.regexps.get(file_type, self.regexps['default']), text): - data = m.groupdict() + data = m.groupdict() self.logDebug(link["name"], data) - + local_file = fs_encode(save_join(download_folder, data["name"])) algorithm = self.methods.get(file_type, file_type) checksum = computeChecksum(local_file, algorithm) if checksum == data["hash"]: - self.logInfo('File integrity of "%s" verified by %s checksum (%s).' % (data["name"], algorithm, checksum)) + self.logInfo('File integrity of "%s" verified by %s checksum (%s).' % (data["name"], + algorithm, + checksum)) else: - self.logWarning("%s checksum for file %s does not match (%s != %s)" % (algorithm, data["name"], checksum, data["hash"]))
\ No newline at end of file + self.logWarning("%s checksum for file %s does not match (%s != %s)" % (algorithm, + data["name"], + checksum, + data["hash"])) diff --git a/module/plugins/hooks/ClickAndLoad.py b/module/plugins/hooks/ClickAndLoad.py index 230143cef..94185251f 100644 --- a/module/plugins/hooks/ClickAndLoad.py +++ b/module/plugins/hooks/ClickAndLoad.py @@ -23,6 +23,7 @@ import thread from module.plugins.Hook import Hook + class ClickAndLoad(Hook): __name__ = "ClickAndLoad" __version__ = "0.21" diff --git a/module/plugins/hooks/DeathByCaptcha.py b/module/plugins/hooks/DeathByCaptcha.py index 59ff40ded..7de4f4f2c 100644 --- a/module/plugins/hooks/DeathByCaptcha.py +++ b/module/plugins/hooks/DeathByCaptcha.py @@ -18,16 +18,17 @@ from __future__ import with_statement from thread import start_new_thread -from pycurl import FORM_FILE, HTTPHEADER, RESPONSE_CODE +from pycurl import FORM_FILE, HTTPHEADER from time import sleep from base64 import b64encode import re -from module.network.RequestFactory import getURL, getRequest +from module.network.RequestFactory import getRequest from module.network.HTTPRequest import BadHeader from module.plugins.Hook import Hook from module.common.json_layer import json_loads + class DeathByCaptchaException(Exception): DBC_ERRORS = {'not-logged-in': 'Access denied, check your credentials', 'invalid-credentials': 'Access denied, check your credentials', @@ -36,14 +37,14 @@ class DeathByCaptchaException(Exception): 'invalid-captcha': 'CAPTCHA is not a valid image', 'service-overload': 'CAPTCHA was rejected due to service overload, try again later', 'invalid-request': 'Invalid request', - 'timed-out': 'No CAPTCHA solution received in time' } - + 'timed-out': 'No CAPTCHA solution received in time'} + def __init__(self, err): self.err = err def getCode(self): return self.err - + def getDesc(self): if self.err in self.DBC_ERRORS.keys(): return self.DBC_ERRORS[self.err] @@ -56,6 +57,7 @@ class DeathByCaptchaException(Exception): def __repr__(self): return "<DeathByCaptchaException %s>" % self.err + class DeathByCaptcha(Hook): __name__ = "DeathByCaptcha" __version__ = "0.03" @@ -74,31 +76,30 @@ class DeathByCaptcha(Hook): def call_api(self, api="captcha", post=False, multipart=False): req = getRequest() - req.c.setopt(HTTPHEADER, ["Accept: application/json", - "User-Agent: pyLoad %s" % self.core.version]) - + req.c.setopt(HTTPHEADER, ["Accept: application/json", "User-Agent: pyLoad %s" % self.core.version]) + if post: if not isinstance(post, dict): post = {} post.update({"username": self.getConfig("username"), - "password": self.getConfig("passkey")}) - + "password": self.getConfig("passkey")}) + response = None try: - json = req.load("%s%s" % (self.API_URL, api), - post = post, + json = req.load("%s%s" % (self.API_URL, api), + post=post, multipart=multipart) - self.logDebug(json) + self.logDebug(json) response = json_loads(json) - + if "error" in response: raise DeathByCaptchaException(response['error']) elif "status" not in response: raise DeathByCaptchaException(str(response)) - + except BadHeader, e: if 403 == e.code: - raise DeathByCaptchaException('not-logged-in') + raise DeathByCaptchaException('not-logged-in') elif 413 == e.code: raise DeathByCaptchaException('invalid-captcha') elif 503 == e.code: @@ -107,12 +108,12 @@ class DeathByCaptcha(Hook): raise DeathByCaptchaException('invalid-request') else: raise - + finally: req.close() - + return response - + def getCredits(self): response = self.call_api("user", True) @@ -122,7 +123,7 @@ class DeathByCaptcha(Hook): self.info.update(response) else: raise DeathByCaptchaException(response) - + def getStatus(self): response = self.call_api("status", False) @@ -138,31 +139,31 @@ class DeathByCaptcha(Hook): multipart = False with open(captcha, 'rb') as f: data = f.read() - data = "base64:" + b64encode(data) - + data = "base64:" + b64encode(data) + response = self.call_api("captcha", {"captchafile": data}, multipart) - + if "captcha" not in response: raise DeathByCaptchaException(response) ticket = response['captcha'] - + for i in range(24): sleep(5) - response = self.call_api("captcha/%d" % ticket, False) + response = self.call_api("captcha/%d" % ticket, False) if response['text'] and response['is_correct']: break else: - raise DeathByCaptchaException('timed-out') - + raise DeathByCaptchaException('timed-out') + result = response['text'] - self.logDebug("result %s : %s" % (ticket,result)) + self.logDebug("result %s : %s" % (ticket, result)) return ticket, result def newCaptchaTask(self, task): if "service" in task.data: return False - + if not task.isTextual(): return False @@ -171,22 +172,23 @@ class DeathByCaptcha(Hook): if self.core.isClientConnected() and not self.getConfig("force"): return False - + try: self.getStatus() - self.getCredits() + self.getCredits() except DeathByCaptchaException, e: self.logError(e.getDesc()) return False - + balance, rate = self.info["balance"], self.info["rate"] - self.logInfo("Account balance: US$%.3f (%d captchas left at %.2f cents each)" % (balance / 100, balance // rate, rate)) - - if balance > rate: + self.logInfo("Account balance: US$%.3f (%d captchas left at %.2f cents each)" % (balance / 100, + balance // rate, rate)) + + if balance > rate: task.handler.append(self) task.data['service'] = self.__name__ task.setWaiting(180) - start_new_thread(self.processCaptcha, (task,)) + start_new_thread(self.processCaptcha, (task,)) def captchaInvalid(self, task): if task.data['service'] == self.__name__ and "ticket" in task.data: @@ -207,4 +209,4 @@ class DeathByCaptcha(Hook): return task.data["ticket"] = ticket - task.setResult(result)
\ No newline at end of file + task.setResult(result) diff --git a/module/plugins/hooks/DeleteFinished.py b/module/plugins/hooks/DeleteFinished.py index 155158701..3bc98a7b3 100644 --- a/module/plugins/hooks/DeleteFinished.py +++ b/module/plugins/hooks/DeleteFinished.py @@ -1,6 +1,6 @@ - # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -''' +""" This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, @@ -15,7 +15,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. @author: Walter Purcaro -''' +""" from module.database import style from module.plugins.Hook import Hook @@ -70,7 +70,7 @@ class DeleteFinished(Hook): ## event managing ## def addEvent(self, event, func): - '''Adds an event listener for event name''' + """Adds an event listener for event name""" if event in self.m.events: if func in self.m.events[event]: self.logDebug('Function already registered %s' % func) diff --git a/module/plugins/hooks/EasybytezCom.py b/module/plugins/hooks/EasybytezCom.py index 6a4ded85b..cc55da9c0 100644 --- a/module/plugins/hooks/EasybytezCom.py +++ b/module/plugins/hooks/EasybytezCom.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -from module.network.RequestFactory import getURL -from module.plugins.internal.MultiHoster import MultiHoster import re +from module.plugins.internal.MultiHoster import MultiHoster + + class EasybytezCom(MultiHoster): __name__ = "EasybytezCom" __version__ = "0.03" @@ -18,14 +19,16 @@ class EasybytezCom(MultiHoster): def getHoster(self): self.account = self.core.accountManager.getAccountPlugin(self.__name__) user = self.account.selectAccount()[0] - + try: req = self.account.getAccountRequest(user) page = req.load("http://www.easybytez.com") - + found = re.search(r'</textarea>\s*Supported sites:(.*)', page) return found.group(1).split(',') except Exception, e: self.logDebug(e) self.logWarning("Unable to load supported hoster list, using last known") - return ['bitshare.com', 'crocko.com', 'ddlstorage.com', 'depositfiles.com', 'extabit.com', 'hotfile.com', 'mediafire.com', 'netload.in', 'rapidgator.net', 'rapidshare.com', 'uploading.com', 'uload.to', 'uploaded.to']
\ No newline at end of file + return ['bitshare.com', 'crocko.com', 'ddlstorage.com', 'depositfiles.com', 'extabit.com', 'hotfile.com', + 'mediafire.com', 'netload.in', 'rapidgator.net', 'rapidshare.com', 'uploading.com', 'uload.to', + 'uploaded.to'] diff --git a/module/plugins/hooks/Ev0InFetcher.py b/module/plugins/hooks/Ev0InFetcher.py index d29f89c2f..912cb5964 100644 --- a/module/plugins/hooks/Ev0InFetcher.py +++ b/module/plugins/hooks/Ev0InFetcher.py @@ -15,11 +15,12 @@ @author: mkaay """ -from module.lib import feedparser from time import mktime, time +from module.lib import feedparser from module.plugins.Hook import Hook + class Ev0InFetcher(Hook): __name__ = "Ev0InFetcher" __version__ = "0.21" @@ -29,7 +30,8 @@ class Ev0InFetcher(Hook): ("queue", "bool", "Move new shows directly to Queue", False), ("shows", "str", "Shows to check for (comma seperated)", ""), ("quality", "xvid;x264;rmvb", "Video Format", "xvid"), - ("hoster", "str", "Hoster to use (comma seperated)", "NetloadIn,RapidshareCom,MegauploadCom,HotfileCom")] + ("hoster", "str", "Hoster to use (comma seperated)", + "NetloadIn,RapidshareCom,MegauploadCom,HotfileCom")] __author_name__ = ("mkaay") __author_mail__ = ("mkaay@mkaay.de") @@ -39,34 +41,34 @@ class Ev0InFetcher(Hook): def filterLinks(self, links): results = self.core.pluginManager.parseUrls(links) sortedLinks = {} - + for url, hoster in results: if hoster not in sortedLinks: sortedLinks[hoster] = [] sortedLinks[hoster].append(url) - + for h in self.getConfig("hoster").split(","): try: return sortedLinks[h.strip()] except: continue return [] - + def periodical(self): def normalizefiletitle(filename): filename = filename.replace('.', ' ') filename = filename.replace('_', ' ') filename = filename.lower() return filename - + shows = [s.strip() for s in self.getConfig("shows").split(",")] - + feed = feedparser.parse("http://feeds.feedburner.com/ev0in/%s?format=xml" % self.getConfig("quality")) showStorage = {} for show in shows: showStorage[show] = int(self.getStorage("show_%s_lastfound" % show, 0)) - + found = False for item in feed['items']: for show, lastfound in showStorage.iteritems(): @@ -82,6 +84,6 @@ class Ev0InFetcher(Hook): pass for show, lastfound in self.getStorage().iteritems(): - if int(lastfound) > 0 and int(lastfound) + (3600*24*30) < int(time()): + if int(lastfound) > 0 and int(lastfound) + (3600 * 24 * 30) < int(time()): self.delStorage("show_%s_lastfound" % show) self.logDebug("Ev0InFetcher: cleaned '%s' record" % show) diff --git a/module/plugins/hooks/ExpertDecoders.py b/module/plugins/hooks/ExpertDecoders.py index 2e66e49ca..f1b7ea352 100644 --- a/module/plugins/hooks/ExpertDecoders.py +++ b/module/plugins/hooks/ExpertDecoders.py @@ -18,7 +18,7 @@ from __future__ import with_statement from thread import start_new_thread -from pycurl import FORM_FILE, LOW_SPEED_TIME +from pycurl import LOW_SPEED_TIME from uuid import uuid4 from base64 import b64encode @@ -27,13 +27,14 @@ from module.network.HTTPRequest import BadHeader from module.plugins.Hook import Hook + class ExpertDecoders(Hook): __name__ = "ExpertDecoders" __version__ = "0.01" __description__ = """send captchas to expertdecoders.com""" __config__ = [("activated", "bool", "Activated", False), ("force", "bool", "Force CT even if client is connected", False), - ("passkey", "password", "Access key", ""),] + ("passkey", "password", "Access key", ""), ] __author_name__ = ("RaNaN", "zoidberg") __author_mail__ = ("RaNaN@pyload.org", "zoidberg@mujmail.cz") @@ -42,37 +43,33 @@ class ExpertDecoders(Hook): def setup(self): self.info = {} - def getCredits(self): - response = getURL(self.API_URL, post = { "key": self.getConfig("passkey"), "action": "balance" }) - - if response.isdigit(): + def getCredits(self): + response = getURL(self.API_URL, post={"key": self.getConfig("passkey"), "action": "balance"}) + + if response.isdigit(): self.logInfo(_("%s credits left") % response) self.info["credits"] = credits = int(response) - return credits + return credits else: self.logError(response) return 0 - - def processCaptcha(self, task): + + def processCaptcha(self, task): task.data["ticket"] = ticket = uuid4() result = None - + with open(task.captchaFile, 'rb') as f: - data = f.read() - data = b64encode(data) + data = f.read() + data = b64encode(data) #self.logDebug("%s: %s : %s" % (ticket, task.captchaFile, data)) req = getRequest() #raise timeout threshold req.c.setopt(LOW_SPEED_TIME, 80) - + try: - result = req.load(self.API_URL, - post={ "action": "upload", - "key": self.getConfig("passkey"), - "file": data, - "gen_task_id": ticket } - ) + result = req.load(self.API_URL, post={"action": "upload", "key": self.getConfig("passkey"), + "file": data, "gen_task_id": ticket}) finally: req.close() @@ -99,14 +96,11 @@ class ExpertDecoders(Hook): def captchaInvalid(self, task): if "ticket" in task.data: - + try: - response = getURL(self.API_URL, - post={ "action": "refund", - "key": self.getConfig("passkey"), - "gen_task_id": task.data["ticket"] } - ) + response = getURL(self.API_URL, post={"action": "refund", "key": self.getConfig("passkey"), + "gen_task_id": task.data["ticket"]}) self.logInfo("Request refund: %s" % response) except BadHeader, e: - self.logError("Could not send refund request.", str(e))
\ No newline at end of file + self.logError("Could not send refund request.", str(e)) diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index f46f290c0..5b7aade94 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -25,6 +25,7 @@ from os.path import join, exists, basename from module.plugins.Hook import Hook from module.utils import save_join + class ExternalScripts(Hook): __name__ = "ExternalScripts" __version__ = "0.22" @@ -43,7 +44,6 @@ class ExternalScripts(Hook): 'all_dls_finished', 'all_dls_processed'] for folder in folders: - self.scripts[folder] = [] self.initPluginType(folder, join(pypath, 'scripts', folder)) @@ -53,12 +53,11 @@ class ExternalScripts(Hook): if names: self.logInfo((_("Installed scripts for %s: ") % script_type ) + ", ".join([basename(x) for x in names])) - def initPluginType(self, folder, path): if not exists(path): try: makedirs(path) - except : + except: self.logDebug("Script folder %s not created" % folder) return @@ -66,7 +65,7 @@ class ExternalScripts(Hook): if f.startswith("#") or f.startswith(".") or f.startswith("_") or f.endswith("~") or f.endswith(".swp"): continue - if not access(join(path,f), X_OK): + if not access(join(path, f), X_OK): self.logWarning(_("Script not executable:") + " %s/%s" % (folder, f)) self.scripts[folder].append(join(path, f)) @@ -77,7 +76,7 @@ class ExternalScripts(Hook): #output goes to pyload subprocess.Popen(cmd, bufsize=-1) except Exception, e: - self.logError(_("Error in %(script)s: %(error)s") % { "script" :basename(script), "error": str(e)}) + self.logError(_("Error in %(script)s: %(error)s") % {"script": basename(script), "error": str(e)}) def downloadPreparing(self, pyfile): for script in self.scripts['download_preparing']: @@ -86,9 +85,8 @@ class ExternalScripts(Hook): def downloadFinished(self, pyfile): for script in self.scripts['download_finished']: self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.name, - save_join(self.core.config['general']['download_folder'], pyfile.package().folder, pyfile.name), - pyfile.id) - + save_join(self.core.config['general']['download_folder'], + pyfile.package().folder, pyfile.name), pyfile.id) def packageFinished(self, pypack): for script in self.scripts['package_finished']: @@ -116,4 +114,3 @@ class ExternalScripts(Hook): def allDownloadsProcessed(self): for script in self.scripts["all_dls_processed"]: self.callScript(script) - diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index bc5aa0f49..346c37021 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -53,6 +53,7 @@ from module.utils import save_join, fs_encode from module.plugins.Hook import Hook, threaded, Expose from module.plugins.internal.AbstractExtractor import ArchiveError, CRCError, WrongPassword + class ExtractArchive(Hook): """ Provides: unrarFinished (folder, filename) @@ -61,15 +62,15 @@ class ExtractArchive(Hook): __version__ = "0.14" __description__ = "Extract different kind of archives" __config__ = [("activated", "bool", "Activated", True), - ("fullpath", "bool", "Extract full path", True), - ("overwrite", "bool", "Overwrite files", True), - ("passwordfile", "file", "password file", "unrar_passwords.txt"), - ("deletearchive", "bool", "Delete archives when done", False), - ("subfolder", "bool", "Create subfolder for each package", False), - ("destination", "folder", "Extract files to", ""), - ("recursive", "bool", "Extract archives in archvies", True), - ("queue", "bool", "Wait for all downloads to be finished", True), - ("renice", "int", "CPU Priority", 0), ] + ("fullpath", "bool", "Extract full path", True), + ("overwrite", "bool", "Overwrite files", True), + ("passwordfile", "file", "password file", "unrar_passwords.txt"), + ("deletearchive", "bool", "Delete archives when done", False), + ("subfolder", "bool", "Create subfolder for each package", False), + ("destination", "folder", "Extract files to", ""), + ("recursive", "bool", "Extract archives in archvies", True), + ("queue", "bool", "Wait for all downloads to be finished", True), + ("renice", "int", "CPU Priority", 0)] __author_name__ = ("pyload Team") __author_mail__ = ("admin<at>pyload.org") @@ -121,14 +122,12 @@ class ExtractArchive(Hook): else: self.manager.startThread(self.extract, [pypack.id]) - @threaded def allDownloadsProcessed(self, thread): local = copy(self.queue) del self.queue[:] self.extract(local, thread) - def extract(self, ids, thread=None): # reload from txt file self.reloadPasswords() @@ -142,7 +141,8 @@ class ExtractArchive(Hook): for pid in ids: p = self.core.files.getPackage(pid) self.logInfo(_("Check package %s") % p.name) - if not p: continue + if not p: + continue # determine output folder out = save_join(dl, p.folder, "") @@ -175,10 +175,10 @@ class ExtractArchive(Hook): if target in extracted: self.logDebug(basename(target), "skipped") continue - extracted.append(target) #prevent extracting same file twice + extracted.append(target) # prevent extracting same file twice klass = plugin(self, target, out, self.getConfig("fullpath"), self.getConfig("overwrite"), - self.getConfig("renice")) + self.getConfig("renice")) klass.init() self.logInfo(basename(target), _("Extract to %s") % out) @@ -191,18 +191,20 @@ class ExtractArchive(Hook): self.logDebug("new file %s does not exists" % file) continue if self.getConfig("recursive") and isfile(file): - new_files_ids.append((file, fid)) #append as new target + new_files_ids.append((file, fid)) # append as new target - files_ids = new_files_ids # also check extracted files + files_ids = new_files_ids # also check extracted files - if not matched: self.logInfo(_("No files found to extract")) + if not matched: + self.logInfo(_("No files found to extract")) def startExtracting(self, plugin, fid, passwords, thread): pyfile = self.core.files.getFile(fid) - if not pyfile: return [] + if not pyfile: + return [] pyfile.setCustomStatus(_("extracting")) - thread.addActive(pyfile) #keep this file until everything is done + thread.addActive(pyfile) # keep this file until everything is done try: progress = lambda x: pyfile.setProgress(x) @@ -218,7 +220,8 @@ class ExtractArchive(Hook): pwlist = copy(self.getPasswords()) #remove already supplied pws from list (only local) for pw in passwords: - if pw in pwlist: pwlist.remove(pw) + if pw in pwlist: + pwlist.remove(pw) for pw in passwords + pwlist: try: @@ -242,15 +245,16 @@ class ExtractArchive(Hook): files = plugin.getDeleteFiles() self.logInfo(_("Deleting %s files") % len(files)) for f in files: - if exists(f): remove(f) - else: self.logDebug("%s does not exists" % f) + if exists(f): + remove(f) + else: + self.logDebug("%s does not exists" % f) self.logInfo(basename(plugin.file), _("Extracting finished")) self.manager.dispatchEvent("unrarFinished", plugin.out, plugin.file) return plugin.getExtractedFiles() - except ArchiveError, e: self.logError(basename(plugin.file), _("Archive Error"), str(e)) except CRCError: @@ -267,7 +271,6 @@ class ExtractArchive(Hook): """ List of saved passwords """ return self.passwords - def reloadPasswords(self): pwfile = self.getConfig("passwordfile") if not exists(pwfile): @@ -281,13 +284,13 @@ class ExtractArchive(Hook): self.passwords = passwords - @Expose def addPassword(self, pw): """ Adds a password to saved list""" pwfile = self.getConfig("passwordfile") - if pw in self.passwords: self.passwords.remove(pw) + if pw in self.passwords: + self.passwords.remove(pw) self.passwords.insert(0, pw) f = open(pwfile, "wb") @@ -297,7 +300,8 @@ class ExtractArchive(Hook): def setPermissions(self, files): for f in files: - if not exists(f): continue + if not exists(f): + continue try: if self.core.config["permission"]["change_file"]: if isfile(f): diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index fd889fa22..e44c1e172 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -28,58 +28,56 @@ import time from module.plugins.Hook import Hook + class HotFolder(Hook): __name__ = "HotFolder" __version__ = "0.11" __description__ = """observe folder and file for changes and add container and links""" - __config__ = [ ("activated", "bool", "Activated" , "False"), - ("folder", "str", "Folder to observe", "container"), - ("watch_file", "bool", "Observe link file", "False"), - ("keep", "bool", "Keep added containers", "True"), - ("file", "str", "Link file", "links.txt")] + __config__ = [("activated", "bool", "Activated", "False"), + ("folder", "str", "Folder to observe", "container"), + ("watch_file", "bool", "Observe link file", "False"), + ("keep", "bool", "Keep added containers", "True"), + ("file", "str", "Link file", "links.txt")] __threaded__ = [] __author_name__ = ("RaNaN") __author_mail__ = ("RaNaN@pyload.de") - + def setup(self): self.interval = 10 - + def periodical(self): - + if not exists(join(self.getConfig("folder"), "finished")): makedirs(join(self.getConfig("folder"), "finished")) - + if self.getConfig("watch_file"): if not exists(self.getConfig("file")): f = open(self.getConfig("file"), "wb") f.close() - - + f = open(self.getConfig("file"), "rb") content = f.read().strip() f.close() f = open(self.getConfig("file"), "wb") f.close() if content: - name = "%s_%s.txt" % (self.getConfig("file"), time.strftime("%H-%M-%S_%d%b%Y") ) + name = "%s_%s.txt" % (self.getConfig("file"), time.strftime("%H-%M-%S_%d%b%Y")) f = open(join(self.getConfig("folder"), "finished", name), "wb") f.write(content) f.close() self.core.api.addPackage(f.name, [f.name], 1) - + for f in listdir(self.getConfig("folder")): path = join(self.getConfig("folder"), f) - + if not isfile(path) or f.endswith("~") or f.startswith("#") or f.startswith("."): continue - - newpath = join(self.getConfig("folder"), "finished", f if self.getConfig("keep") else "tmp_"+f) + + newpath = join(self.getConfig("folder"), "finished", f if self.getConfig("keep") else "tmp_" + f) move(path, newpath) - + self.logInfo(_("Added %s from HotFolder") % f) self.core.api.addPackage(f, [newpath], 1) - -
\ No newline at end of file diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py index b9f3c1ba6..8dadf08ed 100644 --- a/module/plugins/hooks/IRCInterface.py +++ b/module/plugins/hooks/IRCInterface.py @@ -26,60 +26,60 @@ import time from time import sleep from traceback import print_exc import re +from pycurl import FORM_FILE from module.plugins.Hook import Hook from module.network.RequestFactory import getURL from module.utils import formatSize from module.Api import PackageDoesNotExists, FileDoesNotExists -from pycurl import FORM_FILE class IRCInterface(Thread, Hook): __name__ = "IRCInterface" __version__ = "0.11" __description__ = """connect to irc and let owner perform different tasks""" __config__ = [("activated", "bool", "Activated", "False"), - ("host", "str", "IRC-Server Address", "Enter your server here!"), - ("port", "int", "IRC-Server Port", "6667"), - ("ident", "str", "Clients ident", "pyload-irc"), - ("realname", "str", "Realname", "pyload-irc"), - ("nick", "str", "Nickname the Client will take", "pyLoad-IRC"), - ("owner", "str", "Nickname the Client will accept commands from", "Enter your nick here!"), - ("info_file", "bool", "Inform about every file finished", "False"), - ("info_pack", "bool", "Inform about every package finished", "True"), - ("captcha", "bool", "Send captcha requests", "True")] + ("host", "str", "IRC-Server Address", "Enter your server here!"), + ("port", "int", "IRC-Server Port", "6667"), + ("ident", "str", "Clients ident", "pyload-irc"), + ("realname", "str", "Realname", "pyload-irc"), + ("nick", "str", "Nickname the Client will take", "pyLoad-IRC"), + ("owner", "str", "Nickname the Client will accept commands from", "Enter your nick here!"), + ("info_file", "bool", "Inform about every file finished", "False"), + ("info_pack", "bool", "Inform about every package finished", "True"), + ("captcha", "bool", "Send captcha requests", "True")] __author_name__ = ("Jeix") __author_mail__ = ("Jeix@hasnomail.com") - + def __init__(self, core, manager): Thread.__init__(self) Hook.__init__(self, core, manager) self.setDaemon(True) # self.sm = core.server_methods - self.api = core.api #todo, only use api - + self.api = core.api # todo, only use api + def coreReady(self): self.new_package = {} - + self.abort = False - + self.links_added = 0 self.more = [] self.start() - - + def packageFinished(self, pypack): try: if self.getConfig("info_pack"): self.response(_("Package finished: %s") % pypack.name) except: pass - + def downloadFinished(self, pyfile): try: if self.getConfig("info_file"): - self.response(_("Download finished: %(name)s @ %(plugin)s ") % { "name" : pyfile.name, "plugin": pyfile.pluginname} ) + self.response( + _("Download finished: %(name)s @ %(plugin)s ") % {"name": pyfile.name, "plugin": pyfile.pluginname}) except: pass @@ -88,7 +88,8 @@ class IRCInterface(Thread, Hook): task.handler.append(self) task.setWaiting(60) - page = getURL("http://www.freeimagehosting.net/upload.php", post={"attached" : (FORM_FILE, task.captchaFile)}, multipart=True) + page = getURL("http://www.freeimagehosting.net/upload.php", + post={"attached": (FORM_FILE, task.captchaFile)}, multipart=True) url = re.search(r"\[img\]([^\[]+)\[/img\]\[/url\]", page).group(1) self.response(_("New Captcha Request: %s") % url) @@ -107,15 +108,14 @@ class IRCInterface(Thread, Hook): self.sock.send("JOIN %s\r\n" % t.strip()) self.logInfo("pyLoad IRC: Connected to %s!" % host) self.logInfo("pyLoad IRC: Switching to listening mode!") - try: + try: self.main_loop() - + except IRCError, ex: self.sock.send("QUIT :byebye\r\n") print_exc() self.sock.close() - def main_loop(self): readbuffer = "" while True: @@ -123,48 +123,47 @@ class IRCInterface(Thread, Hook): fdset = select([self.sock], [], [], 0) if self.sock not in fdset[0]: continue - + if self.abort: raise IRCError("quit") - + readbuffer += self.sock.recv(1024) temp = readbuffer.split("\n") readbuffer = temp.pop() for line in temp: - line = line.rstrip() + line = line.rstrip() first = line.split() if first[0] == "PING": self.sock.send("PONG %s\r\n" % first[1]) - + if first[0] == "ERROR": raise IRCError(line) - + msg = line.split(None, 3) if len(msg) < 4: continue - + msg = { - "origin":msg[0][1:], - "action":msg[1], - "target":msg[2], - "text":msg[3][1:] + "origin": msg[0][1:], + "action": msg[1], + "target": msg[2], + "text": msg[3][1:] } - + self.handle_events(msg) - - + def handle_events(self, msg): if not msg["origin"].split("!", 1)[0] in self.getConfig("owner").split(): return - + if msg["target"].split("!", 1)[0] != self.getConfig("nick"): return - + if msg["action"] != "PRIVMSG": return - + # HANDLE CTCP ANTI FLOOD/BOT PROTECTION if msg["text"] == "\x01VERSION\x01": self.logDebug("Sending CTCP VERSION.") @@ -175,9 +174,9 @@ class IRCInterface(Thread, Hook): self.sock.send("NOTICE %s :%d\r\n" % (msg['origin'], time.time())) return elif msg["text"] == "\x01LAG\x01": - self.logDebug("Received CTCP LAG.") # don't know how to answer + self.logDebug("Received CTCP LAG.") # don't know how to answer return - + trigger = "pass" args = None @@ -195,26 +194,25 @@ class IRCInterface(Thread, Hook): for line in res: self.response(line, msg["origin"]) except Exception, e: - self.logError("pyLoad IRC: "+ repr(e)) - - + self.logError("pyLoad IRC: " + repr(e)) + def response(self, msg, origin=""): if origin == "": for t in self.getConfig("owner").split(): self.sock.send("PRIVMSG %s :%s\r\n" % (t.strip(), msg)) else: self.sock.send("PRIVMSG %s :%s\r\n" % (origin.split("!", 1)[0], msg)) - - -#### Events + + #### Events + def event_pass(self, args): return [] - + def event_status(self, args): downloads = self.api.statusDownloads() if not downloads: return ["INFO: There are no active downloads currently."] - + temp_progress = "" lines = ["ID - Name - Status - Speed - ETA - Progress"] for data in downloads: @@ -225,71 +223,69 @@ class IRCInterface(Thread, Hook): temp_progress = "%d%% (%s)" % (data.percent, data.format_size) lines.append("#%d - %s - %s - %s - %s - %s" % - ( - data.fid, - data.name, - data.statusmsg, - "%s/s" % formatSize(data.speed), - "%s" % data.format_eta, - temp_progress - ) - ) + ( + data.fid, + data.name, + data.statusmsg, + "%s/s" % formatSize(data.speed), + "%s" % data.format_eta, + temp_progress + )) return lines - + def event_queue(self, args): ps = self.api.getQueueData() - + if not ps: return ["INFO: There are no packages in queue."] - + lines = [] for pack in ps: - lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.links) )) - + lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.links))) + return lines - + def event_collector(self, args): ps = self.api.getCollectorData() if not ps: return ["INFO: No packages in collector!"] - + lines = [] for pack in ps: - lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.links) )) - + lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.links))) + return lines - + def event_info(self, args): if not args: return ['ERROR: Use info like this: info <id>'] - + info = None try: info = self.api.getFileData(int(args[0])) - + except FileDoesNotExists: return ["ERROR: Link doesn't exists."] - return ['LINK #%s: %s (%s) [%s][%s]' % (info.fid, info.name, info.format_size, info.statusmsg, - info.plugin)] - + return ['LINK #%s: %s (%s) [%s][%s]' % (info.fid, info.name, info.format_size, info.statusmsg, info.plugin)] + def event_packinfo(self, args): if not args: return ['ERROR: Use packinfo like this: packinfo <id>'] - + lines = [] pack = None try: pack = self.api.getPackageData(int(args[0])) - + except PackageDoesNotExists: return ["ERROR: Package doesn't exists."] - + id = args[0] self.more = [] - - lines.append('PACKAGE #%s: "%s" with %d links' % (id, pack.name, len(pack.links)) ) + + lines.append('PACKAGE #%s: "%s" with %d links' % (id, pack.name, len(pack.links))) for pyfile in pack.links: self.more.append('LINK #%s: %s (%s) [%s][%s]' % (pyfile.fid, pyfile.name, pyfile.format_size, pyfile.statusmsg, pyfile.plugin)) @@ -301,74 +297,69 @@ class IRCInterface(Thread, Hook): lines.extend(self.more[:6]) self.more = self.more[6:] lines.append("%d more links do display." % len(self.more)) - - + return lines - + def event_more(self, args): if not self.more: return ["No more information to display."] - + lines = self.more[:6] self.more = self.more[6:] lines.append("%d more links do display." % len(self.more)) - + return lines - + def event_start(self, args): - + self.api.unpauseServer() return ["INFO: Starting downloads."] - + def event_stop(self, args): - + self.api.pauseServer() return ["INFO: No new downloads will be started."] - - + def event_add(self, args): if len(args) < 2: return ['ERROR: Add links like this: "add <packagename|id> links". ', - 'This will add the link <link> to to the package <package> / the package with id <id>!'] - + 'This will add the link <link> to to the package <package> / the package with id <id>!'] - pack = args[0].strip() links = [x.strip() for x in args[1:]] - + count_added = 0 count_failed = 0 try: - id = int(pack) + id = int(pack) pack = self.api.getPackageData(id) if not pack: return ["ERROR: Package doesn't exists."] - + #TODO add links - + return ["INFO: Added %d links to Package %s [#%d]" % (len(links), pack["name"], id)] - + except: # create new package id = self.api.addPackage(pack, links, 1) return ["INFO: Created new Package %s [#%d] with %d links." % (pack, id, len(links))] - - + def event_del(self, args): if len(args) < 2: return ["ERROR: Use del command like this: del -p|-l <id> [...] (-p indicates that the ids are from packages, -l indicates that the ids are from links)"] - + if args[0] == "-p": ret = self.api.deletePackages(map(int, args[1:])) return ["INFO: Deleted %d packages!" % len(args[1:])] - + elif args[0] == "-l": ret = self.api.delLinks(map(int, args[1:])) return ["INFO: Deleted %d links!" % len(args[1:])] else: return ["ERROR: Use del command like this: del <-p|-l> <id> [...] (-p indicates that the ids are from packages, -l indicates that the ids are from links)"] - + def event_push(self, args): if not args: return ["ERROR: Push package to queue like this: push <package id>"] @@ -401,11 +392,10 @@ class IRCInterface(Thread, Hook): task = self.core.captchaManager.getTaskByID(args[0]) if not task: return ["ERROR: Captcha Task with ID %s does not exists." % args[0]] - + task.setResult(" ".join(args[1:])) return ["INFO: Result %s saved." % " ".join(args[1:])] - def event_help(self, args): lines = ["The following commands are available:", "add <package|packid> <links> [...] Adds link to package. (creates new package if it does not exist)", @@ -422,10 +412,11 @@ class IRCInterface(Thread, Hook): "status Show general download status", "help Shows this help message"] return lines - - + + class IRCError(Exception): def __init__(self, value): self.value = value + def __str__(self): return repr(self.value) diff --git a/module/plugins/hooks/ImageTyperz.py b/module/plugins/hooks/ImageTyperz.py index f8f515113..c9e43b8ae 100644 --- a/module/plugins/hooks/ImageTyperz.py +++ b/module/plugins/hooks/ImageTyperz.py @@ -16,16 +16,14 @@ @author: mkaay, RaNaN, zoidberg """ from __future__ import with_statement - from thread import start_new_thread from pycurl import FORM_FILE, LOW_SPEED_TIME +import re +from base64 import b64encode from module.network.RequestFactory import getURL, getRequest -from module.network.HTTPRequest import BadHeader - from module.plugins.Hook import Hook -import re -from base64 import b64encode + class ImageTyperzException(Exception): def __init__(self, err): @@ -40,6 +38,7 @@ class ImageTyperzException(Exception): def __repr__(self): return "<ImageTyperzException %s>" % self.err + class ImageTyperz(Hook): __name__ = "ImageTyperz" __version__ = "0.04" @@ -59,28 +58,25 @@ class ImageTyperz(Hook): self.info = {} def getCredits(self): - response = getURL(self.GETCREDITS_URL, - post = {"action": "REQUESTBALANCE", - "username": self.getConfig("username"), - "password": self.getConfig("passkey")} - ) - + response = getURL(self.GETCREDITS_URL, post={"action": "REQUESTBALANCE", "username": self.getConfig("username"), + "password": self.getConfig("passkey")}) + if response.startswith('ERROR'): raise ImageTyperzException(response) - + try: balance = float(response) except: raise ImageTyperzException("invalid response") - + self.logInfo("Account balance: $%s left" % response) - return balance + return balance def submit(self, captcha, captchaType="file", match=None): req = getRequest() #raise timeout threshold req.c.setopt(LOW_SPEED_TIME, 80) - + try: #workaround multipart-post bug in HTTPRequest.py if re.match("^[A-Za-z0-9]*$", self.getConfig("passkey")): @@ -91,13 +87,11 @@ class ImageTyperz(Hook): with open(captcha, 'rb') as f: data = f.read() data = b64encode(data) - - response = req.load(self.SUBMIT_URL, - post={ "action": "UPLOADCAPTCHA", - "username": self.getConfig("username"), - "password": self.getConfig("passkey"), - "file": data}, - multipart = multipart) + + response = req.load(self.SUBMIT_URL, post={"action": "UPLOADCAPTCHA", + "username": self.getConfig("username"), + "password": self.getConfig("passkey"), "file": data}, + multipart=multipart) finally: req.close() @@ -108,14 +102,14 @@ class ImageTyperz(Hook): if len(data) == 2: ticket, result = data else: - raise ImageTyperzException("Unknown response %s" % response) - + raise ImageTyperzException("Unknown response %s" % response) + return ticket, result def newCaptchaTask(self, task): if "service" in task.data: return False - + if not task.isTextual(): return False @@ -136,17 +130,14 @@ class ImageTyperz(Hook): def captchaInvalid(self, task): if task.data['service'] == self.__name__ and "ticket" in task.data: - response = getURL(self.RESPOND_URL, - post={"action": "SETBADIMAGE", - "username": self.getConfig("username"), - "password": self.getConfig("passkey"), - "imageid": task.data["ticket"]} - ) - + response = getURL(self.RESPOND_URL, post={"action": "SETBADIMAGE", "username": self.getConfig("username"), + "password": self.getConfig("passkey"), + "imageid": task.data["ticket"]}) + if response == "SUCCESS": self.logInfo("Bad captcha solution received, requested refund") else: - self.logError("Bad captcha solution received, refund request failed", response) + self.logError("Bad captcha solution received, refund request failed", response) def processCaptcha(self, task): c = task.captchaFile @@ -157,4 +148,4 @@ class ImageTyperz(Hook): return task.data["ticket"] = ticket - task.setResult(result)
\ No newline at end of file + task.setResult(result) diff --git a/module/plugins/hooks/LinkdecrypterCom.py b/module/plugins/hooks/LinkdecrypterCom.py index c117cafb9..f2176e799 100644 --- a/module/plugins/hooks/LinkdecrypterCom.py +++ b/module/plugins/hooks/LinkdecrypterCom.py @@ -22,11 +22,12 @@ from module.plugins.Hook import Hook from module.network.RequestFactory import getURL from module.utils import remove_chars + class LinkdecrypterCom(Hook): __name__ = "LinkdecrypterCom" __version__ = "0.18" __description__ = """linkdecrypter.com - regexp loader""" - __config__ = [ ("activated", "bool", "Activated" , "False") ] + __config__ = [("activated", "bool", "Activated", "False")] __author_name__ = ("zoidberg") def coreReady(self): @@ -36,8 +37,8 @@ class LinkdecrypterCom(Hook): self.logError(_("Crypter list not found")) return - builtin = [ name.lower() for name in self.core.pluginManager.crypterPlugins.keys() ] - builtin.extend([ "downloadserienjunkiesorg" ]) + builtin = [name.lower() for name in self.core.pluginManager.crypterPlugins.keys()] + builtin.extend(["downloadserienjunkiesorg"]) crypter_pattern = re.compile("(\w[\w.-]+)") online = [] @@ -49,11 +50,11 @@ class LinkdecrypterCom(Hook): if not online: self.logError(_("Crypter list is empty")) return - + regexp = r"https?://([^.]+\.)*?(%s)/.*" % "|".join(online) dict = self.core.pluginManager.crypterPlugins[self.__name__] dict["pattern"] = regexp dict["re"] = re.compile(regexp) - + self.logDebug("REGEXP: " + regexp) diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 613e6575a..060dae7a2 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -19,7 +19,6 @@ import os import re -import sys import traceback from os.path import join @@ -28,13 +27,12 @@ from module.plugins.Hook import Hook BUFFER_SIZE = 4096 + class MergeFiles(Hook): __name__ = "MergeFiles" __version__ = "0.11" __description__ = "Merges parts splitted with hjsplit" - __config__ = [ - ("activated" , "bool" , "Activated" , "False"), - ] + __config__ = [("activated", "bool", "Activated", "False")] __threaded__ = ["packageFinished"] __author_name__ = ("and9000") __author_mail__ = ("me@has-no-mail.com") @@ -42,7 +40,7 @@ class MergeFiles(Hook): def setup(self): # nothing to do pass - + def packageFinished(self, pack): files = {} fid_dict = {} @@ -53,9 +51,9 @@ class MergeFiles(Hook): files[data["name"][:-4]].append(data["name"]) files[data["name"][:-4]].sort() fid_dict[data["name"]] = fid - + download_folder = self.core.config['general']['download_folder'] - + if self.core.config['general']['folder_per_package']: download_folder = save_join(download_folder, pack.folder) @@ -76,7 +74,7 @@ class MergeFiles(Hook): if f_buffer: final_file.write(f_buffer) size_written += BUFFER_SIZE - pyfile.setProgress((size_written*100)/s_file_size) + pyfile.setProgress((size_written * 100) / s_file_size) else: break s_file.close() @@ -87,8 +85,6 @@ class MergeFiles(Hook): pyfile.setProgress(100) pyfile.setStatus("finished") pyfile.release() - + final_file.close() self.logInfo("Finished merging of %s" % name) - - diff --git a/module/plugins/hooks/MultiHome.py b/module/plugins/hooks/MultiHome.py index ddf8db69f..473e6dcb1 100644 --- a/module/plugins/hooks/MultiHome.py +++ b/module/plugins/hooks/MultiHome.py @@ -17,18 +17,20 @@ @author: mkaay """ -from module.plugins.Hook import Hook from time import time +from module.plugins.Hook import Hook + + class MultiHome(Hook): __name__ = "MultiHome" __version__ = "0.11" __description__ = """ip address changer""" - __config__ = [ ("activated", "bool", "Activated" , "False"), - ("interfaces", "str", "Interfaces" , "None") ] + __config__ = [("activated", "bool", "Activated", "False"), + ("interfaces", "str", "Interfaces", "None")] __author_name__ = ("mkaay") __author_mail__ = ("mkaay@mkaay.de") - + def setup(self): self.register = {} self.interfaces = [] @@ -36,28 +38,30 @@ class MultiHome(Hook): if not self.interfaces: self.parseInterfaces([self.config["download"]["interface"]]) self.setConfig("interfaces", self.toConfig()) - + def toConfig(self): return ";".join([i.adress for i in self.interfaces]) - + def parseInterfaces(self, interfaces): for interface in interfaces: if not interface or str(interface).lower() == "none": continue self.interfaces.append(Interface(interface)) - + def coreReady(self): requestFactory = self.core.requestFactory oldGetRequest = requestFactory.getRequest + def getRequest(pluginName, account=None): iface = self.bestInterface(pluginName, account) if iface: iface.useFor(pluginName, account) requestFactory.iface = lambda: iface.adress - self.logDebug("Multihome: using address: "+iface.adress) + self.logDebug("Multihome: using address: " + iface.adress) return oldGetRequest(pluginName, account) + requestFactory.getRequest = getRequest - + def bestInterface(self, pluginName, account): best = None for interface in self.interfaces: @@ -65,18 +69,19 @@ class MultiHome(Hook): best = interface return best + class Interface(object): def __init__(self, adress): self.adress = adress self.history = {} - + def lastPluginAccess(self, pluginName, account): if (pluginName, account) in self.history: return self.history[(pluginName, account)] return 0 - + def useFor(self, pluginName, account): self.history[(pluginName, account)] = time() - + def __repr__(self): return "<Interface - %s>" % self.adress diff --git a/module/plugins/hooks/MultishareCz.py b/module/plugins/hooks/MultishareCz.py index 7e5a3e007..fc35bb785 100644 --- a/module/plugins/hooks/MultishareCz.py +++ b/module/plugins/hooks/MultishareCz.py @@ -1,16 +1,18 @@ # -*- coding: utf-8 -*- +import re + from module.network.RequestFactory import getURL from module.plugins.internal.MultiHoster import MultiHoster -import re + class MultishareCz(MultiHoster): __name__ = "MultishareCz" __version__ = "0.04" __type__ = "hook" __config__ = [("activated", "bool", "Activated", "False"), - ("hosterListMode", "all;listed;unlisted", "Use for hosters (if supported)", "all"), - ("hosterList", "str", "Hoster list (comma separated)", "uloz.to")] + ("hosterListMode", "all;listed;unlisted", "Use for hosters (if supported)", "all"), + ("hosterList", "str", "Hoster list (comma separated)", "uloz.to")] __description__ = """MultiShare.cz hook plugin""" __author_name__ = ("zoidberg") __author_mail__ = ("zoidberg@mujmail.cz") @@ -18,6 +20,5 @@ class MultishareCz(MultiHoster): HOSTER_PATTERN = r'<img class="logo-shareserveru"[^>]*?alt="([^"]+)"></td>\s*<td class="stav">[^>]*?alt="OK"' def getHoster(self): - page = getURL("http://www.multishare.cz/monitoring/") - return re.findall(self.HOSTER_PATTERN, page)
\ No newline at end of file + return re.findall(self.HOSTER_PATTERN, page) diff --git a/module/plugins/hooks/Premium4Me.py b/module/plugins/hooks/Premium4Me.py index edbdfbdb9..4bcc79b25 100644 --- a/module/plugins/hooks/Premium4Me.py +++ b/module/plugins/hooks/Premium4Me.py @@ -3,25 +3,24 @@ from module.network.RequestFactory import getURL from module.plugins.internal.MultiHoster import MultiHoster + class Premium4Me(MultiHoster): __name__ = "Premium4Me" __version__ = "0.03" __type__ = "hook" __config__ = [("activated", "bool", "Activated", "False"), - ("hosterListMode", "all;listed;unlisted", "Use for downloads from supported hosters:", "all"), - ("hosterList", "str", "Hoster list (comma separated)", "")] + ("hosterListMode", "all;listed;unlisted", "Use for downloads from supported hosters:", "all"), + ("hosterList", "str", "Hoster list (comma separated)", "")] __description__ = """Premium.to hook plugin""" __author_name__ = ("RaNaN", "zoidberg", "stickell") __author_mail__ = ("RaNaN@pyload.org", "zoidberg@mujmail.cz", "l.stickell@yahoo.it") def getHoster(self): - page = getURL("http://premium.to/api/hosters.php?authcode=%s" % self.account.authcode) return [x.strip() for x in page.replace("\"", "").split(";")] def coreReady(self): - self.account = self.core.accountManager.getAccountPlugin("Premium4Me") user = self.account.selectAccount()[0] @@ -30,4 +29,4 @@ class Premium4Me(MultiHoster): self.logError(_("Please add your premium.to account first and restart pyLoad")) return - return MultiHoster.coreReady(self)
\ No newline at end of file + return MultiHoster.coreReady(self) diff --git a/module/plugins/hooks/PremiumizeMe.py b/module/plugins/hooks/PremiumizeMe.py index a10c24f85..07630420c 100644 --- a/module/plugins/hooks/PremiumizeMe.py +++ b/module/plugins/hooks/PremiumizeMe.py @@ -1,8 +1,9 @@ from module.plugins.internal.MultiHoster import MultiHoster -from module.common.json_layer import json_loads +from module.common.json_layer import json_loads from module.network.RequestFactory import getURL + class PremiumizeMe(MultiHoster): __name__ = "PremiumizeMe" __version__ = "0.12" @@ -10,41 +11,42 @@ class PremiumizeMe(MultiHoster): __description__ = """Premiumize.Me hook plugin""" __config__ = [("activated", "bool", "Activated", "False"), - ("hosterListMode", "all;listed;unlisted", "Use for hosters (if supported):", "all"), + ("hosterListMode", "all;listed;unlisted", "Use for hosters (if supported):", "all"), ("hosterList", "str", "Hoster list (comma separated)", ""), ("unloadFailing", "bool", "Revert to stanard download if download fails", "False"), ("interval", "int", "Reload interval in hours (0 to disable)", "24")] __author_name__ = ("Florian Franzen") __author_mail__ = ("FlorianFranzen@gmail.com") - - def getHoster(self): + + def getHoster(self): # If no accounts are available there will be no hosters available if not self.account or not self.account.canUse(): return [] - + # Get account data (user, data) = self.account.selectAccount() - - # Get supported hosters list from premiumize.me using the json API v1 (see https://secure.premiumize.me/?show=api) - answer = getURL("https://api.premiumize.me/pm-api/v1.php?method=hosterlist¶ms[login]=%s¶ms[pass]=%s" % (user, data['password'])) + + # Get supported hosters list from premiumize.me using the + # json API v1 (see https://secure.premiumize.me/?show=api) + answer = getURL("https://api.premiumize.me/pm-api/v1.php?method=hosterlist¶ms[login]=%s¶ms[pass]=%s" % ( + user, data['password'])) data = json_loads(answer) - - + # If account is not valid thera are no hosters available if data['status'] != 200: return [] - + # Extract hosters from json file - return data['result']['hosterlist'] - + return data['result']['hosterlist'] + def coreReady(self): # Get account plugin and check if there is a valid account available - self.account = self.core.accountManager.getAccountPlugin("PremiumizeMe") + self.account = self.core.accountManager.getAccountPlugin("PremiumizeMe") if not self.account.canUse(): self.account = None self.logError(_("Please add a valid premiumize.me account first and restart pyLoad.")) return - + # Run the overwriten core ready which actually enables the multihoster hook - return MultiHoster.coreReady(self)
\ No newline at end of file + return MultiHoster.coreReady(self) diff --git a/module/plugins/hooks/RealdebridCom.py b/module/plugins/hooks/RealdebridCom.py index be74b47c3..41e988495 100644 --- a/module/plugins/hooks/RealdebridCom.py +++ b/module/plugins/hooks/RealdebridCom.py @@ -3,6 +3,7 @@ from module.network.RequestFactory import getURL from module.plugins.internal.MultiHoster import MultiHoster + class RealdebridCom(MultiHoster): __name__ = "RealdebridCom" __version__ = "0.43" @@ -20,6 +21,6 @@ class RealdebridCom(MultiHoster): def getHoster(self): https = "https" if self.getConfig("https") else "http" - page = getURL(https + "://real-debrid.com/api/hosters.php").replace("\"","").strip() + page = getURL(https + "://real-debrid.com/api/hosters.php").replace("\"", "").strip() return [x.strip() for x in page.split(",") if x.strip()] diff --git a/module/plugins/hooks/RehostTo.py b/module/plugins/hooks/RehostTo.py index cd9f7ccef..6e24988c8 100644 --- a/module/plugins/hooks/RehostTo.py +++ b/module/plugins/hooks/RehostTo.py @@ -3,6 +3,7 @@ from module.network.RequestFactory import getURL from module.plugins.internal.MultiHoster import MultiHoster + class RehostTo(MultiHoster): __name__ = "RehostTo" __version__ = "0.43" @@ -19,23 +20,20 @@ class RehostTo(MultiHoster): __author_mail__ = ("RaNaN@pyload.org") def getHoster(self): - page = getURL("http://rehost.to/api.php?cmd=get_supported_och_dl&long_ses=%s" % self.long_ses) return [x.strip() for x in page.replace("\"", "").split(",")] - def coreReady(self): - self.account = self.core.accountManager.getAccountPlugin("RehostTo") user = self.account.selectAccount()[0] if not user: - self.logError("Rehost.to: "+ _("Please add your rehost.to account first and restart pyLoad")) + self.logError("Rehost.to: " + _("Please add your rehost.to account first and restart pyLoad")) return data = self.account.getAccountInfo(user) self.ses = data["ses"] self.long_ses = data["long_ses"] - return MultiHoster.coreReady(self)
\ No newline at end of file + return MultiHoster.coreReady(self) diff --git a/module/plugins/hooks/ReloadCc.py b/module/plugins/hooks/ReloadCc.py index dbd9d659b..d07923624 100644 --- a/module/plugins/hooks/ReloadCc.py +++ b/module/plugins/hooks/ReloadCc.py @@ -1,8 +1,9 @@ from module.plugins.internal.MultiHoster import MultiHoster -from module.common.json_layer import json_loads +from module.common.json_layer import json_loads from module.network.RequestFactory import getURL + class ReloadCc(MultiHoster): __name__ = "ReloadCc" __version__ = "0.3" @@ -16,7 +17,7 @@ class ReloadCc(MultiHoster): __author_name__ = ("Reload Team") __author_mail__ = ("hello@reload.cc") - interval = 0 # Disable periodic calls + interval = 0 # Disable periodic calls def getHoster(self): # If no accounts are available there will be no hosters available @@ -44,7 +45,6 @@ class ReloadCc(MultiHoster): answer = getURL("http://api.reload.cc/login", get=query_params) data = json_loads(answer) - # If account is not valid thera are no hosters available if data['status'] != "ok": print "ReloadCc: Status is not ok: %s" % data['status'] diff --git a/module/plugins/hooks/RestartFailed.py b/module/plugins/hooks/RestartFailed.py index c78ccf96c..3bf6fe365 100644 --- a/module/plugins/hooks/RestartFailed.py +++ b/module/plugins/hooks/RestartFailed.py @@ -2,13 +2,14 @@ from module.plugins.Hook import Hook + class RestartFailed(Hook): __name__ = "RestartFailed" __version__ = "1.52" __description__ = "restartedFailed Packages after defined time" - __config__ = [("activated", "bool", "Activated" , "False"), - ("interval", "int", "Interval in Minutes", "15") ] - + __config__ = [("activated", "bool", "Activated", "False"), + ("interval", "int", "Interval in Minutes", "15")] + __author_name__ = ("bambie") __author_mail__ = ("bambie@gulli.com") diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index 561329122..ddf19117d 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -1,4 +1,4 @@ - # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- """ This program is free software; you can redistribute it and/or modify @@ -17,10 +17,11 @@ @author: Walter Purcaro """ -from module.plugins.Hook import Hook from os.path import basename from re import search +from module.plugins.Hook import Hook + class SkipRev(Hook): __name__ = "SkipRev" diff --git a/module/plugins/hooks/UnSkipOnFail.py b/module/plugins/hooks/UnSkipOnFail.py index 4b7a58be8..455832b09 100644 --- a/module/plugins/hooks/UnSkipOnFail.py +++ b/module/plugins/hooks/UnSkipOnFail.py @@ -22,11 +22,12 @@ from module.utils import fs_encode from module.plugins.Hook import Hook from module.PyFile import PyFile + class UnSkipOnFail(Hook): __name__ = 'UnSkipOnFail' __version__ = '0.01' __description__ = 'When a download fails, restart "skipped" duplicates.' - __config__ = [('activated', 'bool', 'Activated', True),] + __config__ = [('activated', 'bool', 'Activated', True), ] __author_name__ = ('hagg',) __author_mail__ = ('') @@ -94,4 +95,3 @@ class UnSkipOnFail(Hook): pyfile.setStatus(new_status) self.core.files.save() pyfile.release() - diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index b30289287..62031e6a4 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -27,18 +27,19 @@ from module.ConfigParser import IGNORE from module.network.RequestFactory import getURL from module.plugins.Hook import threaded, Expose, Hook + class UpdateManager(Hook): __name__ = "UpdateManager" __version__ = "0.15" __description__ = """checks for updates""" __config__ = [("activated", "bool", "Activated", "True"), - ("interval", "int", "Check interval in minutes", "480"), - ("debug", "bool", "Check for plugin changes when in debug mode", False)] + ("interval", "int", "Check interval in minutes", "480"), + ("debug", "bool", "Check for plugin changes when in debug mode", False)] __author_name__ = ("RaNaN") __author_mail__ = ("ranan@pyload.org") URL = "http://get.pyload.org/check2/%s/" - MIN_TIME = 3 * 60 * 60 # 3h minimum check interval + MIN_TIME = 3 * 60 * 60 # 3h minimum check interval @property def debug(self): @@ -48,10 +49,10 @@ class UpdateManager(Hook): if self.debug: self.logDebug("Monitoring file changes") self.interval = 4 - self.last_check = 0 #timestamp of updatecheck + self.last_check = 0 # timestamp of updatecheck self.old_periodical = self.periodical self.periodical = self.checkChanges - self.mtimes = {} #recordes times + self.mtimes = {} # recordes times else: self.interval = max(self.getConfig("interval") * 60, self.MIN_TIME) @@ -86,7 +87,7 @@ class UpdateManager(Hook): """checks if an update is available, return result""" try: - if self.version == "None": # No updated known + if self.version == "None": # No updated known version_check = getURL(self.URL % self.core.api.getServerVersion()).splitlines() self.version = version_check[0] @@ -95,7 +96,6 @@ class UpdateManager(Hook): self.logInfo(_("No Updates for pyLoad")) return version_check[1:] - self.info["pyload"] = True self.logInfo(_("*** New pyLoad Version %s available ***") % self.version) self.logInfo(_("*** Get it here: http://pyload.org/download ***")) @@ -103,14 +103,14 @@ class UpdateManager(Hook): except: self.logWarning(_("Not able to connect server for updates")) - return None # Nothing will be done - + return None # Nothing will be done def checkPlugins(self, updates): """ checks for plugins updates""" # plugins were already updated - if self.info["plugins"]: return + if self.info["plugins"]: + return reloads = [] @@ -178,8 +178,8 @@ class UpdateManager(Hook): self.last_check = time() modules = filter( - lambda m: m and (m.__name__.startswith("module.plugins.") or m.__name__.startswith("userplugins.")) and m.__name__.count(".") >= 2, - sys.modules.itervalues()) + lambda m: m and (m.__name__.startswith("module.plugins.") or m.__name__.startswith( + "userplugins.")) and m.__name__.count(".") >= 2, sys.modules.itervalues()) reloads = [] @@ -188,7 +188,8 @@ class UpdateManager(Hook): id = (type, name) if type in self.core.pluginManager.plugins: f = m.__file__.replace(".pyc", ".py") - if not exists(f): continue + if not exists(f): + continue mtime = stat(f).st_mtime diff --git a/module/plugins/hooks/XFileSharingPro.py b/module/plugins/hooks/XFileSharingPro.py index f14ba7eb7..fe2df840d 100644 --- a/module/plugins/hooks/XFileSharingPro.py +++ b/module/plugins/hooks/XFileSharingPro.py @@ -1,16 +1,18 @@ # -*- coding: utf-8 -*- -from module.plugins.Hook import Hook import re +from module.plugins.Hook import Hook + + class XFileSharingPro(Hook): __name__ = "XFileSharingPro" - __version__ = "0.05" + __version__ = "0.06" __type__ = "hook" - __config__ = [ ("activated" , "bool" , "Activated" , "True"), - ("loadDefault", "bool", "Include default (built-in) hoster list" , "True"), - ("includeList", "str", "Include hosters (comma separated)", ""), - ("excludeList", "str", "Exclude hosters (comma separated)", "") ] + __config__ = [("activated", "bool", "Activated", "True"), + ("loadDefault", "bool", "Include default (built-in) hoster list", "True"), + ("includeList", "str", "Include hosters (comma separated)", ""), + ("excludeList", "str", "Exclude hosters (comma separated)", "")] __description__ = """Hoster URL pattern loader for the generic XFileSharingPro plugin""" __author_name__ = ("zoidberg") __author_mail__ = ("zoidberg@mujmail.cz") @@ -24,25 +26,27 @@ class XFileSharingPro(Hook): if self.getConfig('loadDefault'): hosterList |= set(( - #WORKING HOSTERS: - "aieshare.com", "asixfiles.com", "banashare.com", "cyberlocker.ch", "eyesfile.co", "eyesfile.com", - "fileband.com", "filedwon.com", "filedownloads.org", "hipfile.com", "kingsupload.com", "mlfat4arab.com", - "netuploaded.com", "odsiebie.pl", "q4share.com", "ravishare.com", "uptobox.com", "verzend.be", "xvidstage.com", - #NOT TESTED: - "bebasupload.com", "boosterking.com", "divxme.com", "filevelocity.com", "glumbouploads.com", "grupload.com", "heftyfile.com", - "host4desi.com", "laoupload.com", "linkzhost.com", "movreel.com", "rockdizfile.com", "limfile.com" - "share76.com", "sharebeast.com", "sharehut.com", "sharerun.com", "shareswift.com", "sharingonline.com", "6ybh-upload.com", - "skipfile.com", "spaadyshare.com", "space4file.com", "uploadbaz.com", "uploadc.com", - "uploaddot.com", "uploadfloor.com", "uploadic.com", "uploadville.com", "vidbull.com", "zalaa.com", - "zomgupload.com", "kupload.org", "movbay.org", "multishare.org", "omegave.org", "toucansharing.org", "uflinq.org", - "banicrazy.info", "flowhot.info", "upbrasil.info", "shareyourfilez.biz", "bzlink.us", "cloudcache.cc", "fileserver.cc" - "farshare.to", "filemaze.ws", "filehost.ws", "filestock.ru", "moidisk.ru", "4up.im", "100shared.com", - #WRONG FILE NAME: - "sendmyway.com", "upchi.co.il", - #NOT WORKING: - "amonshare.com", "imageporter.com", "file4safe.com", - #DOWN OR BROKEN: - "ddlanime.com", "fileforth.com", "loombo.com", "goldfile.eu", "putshare.com" + #WORKING HOSTERS: + "aieshare.com", "asixfiles.com", "banashare.com", "cyberlocker.ch", "eyesfile.co", "eyesfile.com", + "fileband.com", "filedwon.com", "filedownloads.org", "hipfile.com", "kingsupload.com", "mlfat4arab.com", + "netuploaded.com", "odsiebie.pl", "q4share.com", "ravishare.com", "uptobox.com", "verzend.be", + "xvidstage.com", + #NOT TESTED: + "bebasupload.com", "boosterking.com", "divxme.com", "filevelocity.com", "glumbouploads.com", + "grupload.com", "heftyfile.com", "host4desi.com", "laoupload.com", "linkzhost.com", "movreel.com", + "rockdizfile.com", "limfile.com", "share76.com", "sharebeast.com", "sharehut.com", "sharerun.com", + "shareswift.com", "sharingonline.com", "6ybh-upload.com", "skipfile.com", "spaadyshare.com", + "space4file.com", "uploadbaz.com", "uploadc.com", "uploaddot.com", "uploadfloor.com", "uploadic.com", + "uploadville.com", "vidbull.com", "zalaa.com", "zomgupload.com", "kupload.org", "movbay.org", + "multishare.org", "omegave.org", "toucansharing.org", "uflinq.org", "banicrazy.info", "flowhot.info", + "upbrasil.info", "shareyourfilez.biz", "bzlink.us", "cloudcache.cc", "fileserver.cc", "farshare.to", + "filemaze.ws", "filehost.ws", "filestock.ru", "moidisk.ru", "4up.im", "100shared.com", + #WRONG FILE NAME: + "sendmyway.com", "upchi.co.il", + #NOT WORKING: + "amonshare.com", "imageporter.com", "file4safe.com", + #DOWN OR BROKEN: + "ddlanime.com", "fileforth.com", "loombo.com", "goldfile.eu", "putshare.com" )) hosterList -= (excludeList) @@ -52,7 +56,7 @@ class XFileSharingPro(Hook): self.unload() return - regexp = r"http://(?:[^/]*\.)?(%s)/\w{12}" % ("|".join(sorted(hosterList)).replace('.','\.')) + regexp = r"http://(?:[^/]*\.)?(%s)/\w{12}" % ("|".join(sorted(hosterList)).replace('.', '\.')) #self.logDebug(regexp) dict = self.core.pluginManager.hosterPlugins['XFileSharingPro'] @@ -61,7 +65,7 @@ class XFileSharingPro(Hook): self.logDebug("Pattern loaded - handling %d hosters" % len(hosterList)) def getConfigSet(self, option): - s = self.getConfig(option).lower().replace('|',',').replace(';',',') + s = self.getConfig(option).lower().replace('|', ',').replace(';', ',') return set([x.strip() for x in s.split(',')]) def unload(self): diff --git a/module/plugins/hooks/XMPPInterface.py b/module/plugins/hooks/XMPPInterface.py index 13a5aaadd..73f13e71c 100644 --- a/module/plugins/hooks/XMPPInterface.py +++ b/module/plugins/hooks/XMPPInterface.py @@ -26,18 +26,19 @@ from pyxmpp.interfaces import * from module.plugins.hooks.IRCInterface import IRCInterface + class XMPPInterface(IRCInterface, JabberClient): __name__ = "XMPPInterface" __version__ = "0.11" __description__ = """connect to jabber and let owner perform different tasks""" __config__ = [("activated", "bool", "Activated", "False"), - ("jid", "str", "Jabber ID", "user@exmaple-jabber-server.org"), - ("pw", "str", "Password", ""), - ("tls", "bool", "Use TLS", False), - ("owners", "str", "List of JIDs accepting commands from", "me@icq-gateway.org;some@msn-gateway.org"), - ("info_file", "bool", "Inform about every file finished", "False"), - ("info_pack", "bool", "Inform about every package finished", "True"), - ("captcha", "bool", "Send captcha requests", "True")] + ("jid", "str", "Jabber ID", "user@exmaple-jabber-server.org"), + ("pw", "str", "Password", ""), + ("tls", "bool", "Use TLS", False), + ("owners", "str", "List of JIDs accepting commands from", "me@icq-gateway.org;some@msn-gateway.org"), + ("info_file", "bool", "Inform about every file finished", "False"), + ("info_pack", "bool", "Inform about every package finished", "True"), + ("captcha", "bool", "Send captcha requests", "True")] __author_name__ = ("RaNaN") __author_mail__ = ("RaNaN@pyload.org") @@ -69,7 +70,7 @@ class XMPPInterface(IRCInterface, JabberClient): self.interface_providers = [ VersionHandler(self), self, - ] + ] def coreReady(self): self.new_package = {} @@ -120,8 +121,8 @@ class XMPPInterface(IRCInterface, JabberClient): The handlers returned will be called when matching message is received in a client session.""" return [ - ("normal", self.message), - ] + ("normal", self.message), + ] def message(self, stanza): """Message handler for the component.""" @@ -230,8 +231,8 @@ class VersionHandler(object): """Return list of tuples (element_name, namespace, handler) describing handlers of <iq type='get'/> stanzas""" return [ - ("query", "jabber:iq:version", self.get_version), - ] + ("query", "jabber:iq:version", self.get_version), + ] def get_iq_set_handlers(self): """Return empty list, as this class provides no <iq type='set'/> stanza handler.""" @@ -248,4 +249,3 @@ class VersionHandler(object): q.newTextChild(q.ns(), "name", "Echo component") q.newTextChild(q.ns(), "version", "1.0") return iq -
\ No newline at end of file diff --git a/module/plugins/hooks/ZeveraCom.py b/module/plugins/hooks/ZeveraCom.py index cadf60069..fb84886d1 100644 --- a/module/plugins/hooks/ZeveraCom.py +++ b/module/plugins/hooks/ZeveraCom.py @@ -3,6 +3,7 @@ from module.network.RequestFactory import getURL from module.plugins.internal.MultiHoster import MultiHoster + class ZeveraCom(MultiHoster): __name__ = "ZeveraCom" __version__ = "0.02" @@ -15,5 +16,5 @@ class ZeveraCom(MultiHoster): __author_mail__ = ("zoidberg@mujmail.cz") def getHoster(self): - page = getURL("http://www.zevera.com/jDownloader.ashx?cmd=gethosters") - return [x.strip() for x in page.replace("\"", "").split(",")]
\ No newline at end of file + page = getURL("http://www.zevera.com/jDownloader.ashx?cmd=gethosters") + return [x.strip() for x in page.replace("\"", "").split(",")] |