From 1b096b2eb2634e8dea80b06ab9ecde206b198b35 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 22 Oct 2014 19:47:00 +0200 Subject: Spare code cosmetics --- module/plugins/Plugin.py | 2 +- module/plugins/hoster/BezvadataCz.py | 2 +- module/plugins/hoster/CrockoCom.py | 4 ++-- module/plugins/hoster/DataHu.py | 6 ++++-- module/plugins/hoster/DataportCz.py | 2 +- module/plugins/hoster/DepositfilesCom.py | 2 -- module/plugins/hoster/FastshareCz.py | 19 +++++++------------ module/plugins/hoster/FilefactoryCom.py | 1 - module/plugins/hoster/FilerNet.py | 5 ++--- module/plugins/hoster/LomafileCom.py | 2 +- module/plugins/hoster/MegaRapidCz.py | 4 ++-- module/plugins/hoster/OneFichierCom.py | 1 - module/plugins/hoster/ShareonlineBiz.py | 25 +++++++++---------------- module/plugins/hoster/TurbobitNet.py | 5 ++--- module/plugins/hoster/UploadheroCom.py | 1 - module/plugins/internal/CaptchaService.py | 22 +++++++++++----------- module/plugins/internal/SimpleCrypter.py | 2 +- module/plugins/internal/SimpleHoster.py | 2 +- module/plugins/internal/XFSPHoster.py | 4 ++-- 19 files changed, 47 insertions(+), 64 deletions(-) (limited to 'module/plugins') diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index 83571345c..0a4b6d44d 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -286,7 +286,7 @@ class Plugin(Base): raise Fail(reason) def error(self, reason=None, type="parse"): - raise Fail("%s error%s | Plugin out of date" % (type.capitalize(), ':' + str(reason) if reason else "")) + raise Fail("%s error%s | Plugin out of date" % (type.capitalize(), ': ' + str(reason) if reason else "")) if self.core.debug: print_exc() diff --git a/module/plugins/hoster/BezvadataCz.py b/module/plugins/hoster/BezvadataCz.py index dcf9bf293..ffd586f74 100644 --- a/module/plugins/hoster/BezvadataCz.py +++ b/module/plugins/hoster/BezvadataCz.py @@ -77,7 +77,7 @@ class BezvadataCz(SimpleHoster): def checkErrors(self): if 'images/button-download-disable.png' in self.html: - self.longWait(5 * 60, 24) # parallel dl limit + self.longWait(5 * 60, 24) #: parallel dl limit elif '
(?P[^<]+)' OFFLINE_PATTERN = r'

Sorry,
the page you\'re looking for
isn\'t here.

|File not found' - CAPTCHA_URL_PATTERN = re.compile(r"u='(/file_contents/captcha/\w+)';\s*w='(\d+)';") + CAPTCHA_PATTERN = re.compile(r"u='(/file_contents/captcha/\w+)';\s*w='(\d+)';") FORM_PATTERN = r'
(.*?)
' FORM_INPUT_PATTERN = r']* name="?([^" ]+)"? value="?([^" ]+)"?[^>]*>' @@ -35,7 +35,7 @@ class CrockoCom(SimpleHoster): self.fail("You need Premium membership to download this file.") for _ in xrange(5): - m = re.search(self.CAPTCHA_URL_PATTERN, self.html) + m = re.search(self.CAPTCHA_PATTERN, self.html) if m: url, wait_time = 'http://crocko.com' + m.group(1), m.group(2) self.wait(wait_time) diff --git a/module/plugins/hoster/DataHu.py b/module/plugins/hoster/DataHu.py index d3a13c54b..d76444d32 100644 --- a/module/plugins/hoster/DataHu.py +++ b/module/plugins/hoster/DataHu.py @@ -26,10 +26,12 @@ class DataHu(SimpleHoster): LINK_PATTERN = r'
' - def handleFree(self): + def setup(self): self.resumeDownload = True - self.html = self.load(self.pyfile.url, decode=True) + self.multiDL = self.premium + + def handleFree(self): m = re.search(self.LINK_PATTERN, self.html) if m: url = m.group(1) diff --git a/module/plugins/hoster/DataportCz.py b/module/plugins/hoster/DataportCz.py index c79a21b8e..6fcbfc2ad 100644 --- a/module/plugins/hoster/DataportCz.py +++ b/module/plugins/hoster/DataportCz.py @@ -21,7 +21,7 @@ class DataportCz(SimpleHoster): FILE_URL_REPLACEMENTS = [(__pattern__, r'http://www.dataport.cz/file/\1')] - CAPTCHA_URL_PATTERN = r'
\s*\s*(\d+)
' diff --git a/module/plugins/hoster/DepositfilesCom.py b/module/plugins/hoster/DepositfilesCom.py index d49b3fc94..ade91e7d4 100644 --- a/module/plugins/hoster/DepositfilesCom.py +++ b/module/plugins/hoster/DepositfilesCom.py @@ -102,8 +102,6 @@ class DepositfilesCom(SimpleHoster): self.retry(wait_time=60) def handlePremium(self): - self.html = self.load(self.pyfile.url, cookies=self.COOKIES) - if '' in self.html: self.logWarning("Download limit reached") self.retry(25, 60 * 60, "Download limit reached") diff --git a/module/plugins/hoster/FastshareCz.py b/module/plugins/hoster/FastshareCz.py index 337977095..2a8d3af7d 100644 --- a/module/plugins/hoster/FastshareCz.py +++ b/module/plugins/hoster/FastshareCz.py @@ -64,20 +64,15 @@ class FastshareCz(SimpleHoster): header = self.load(self.pyfile.url, just_header=True) if "location" in header: url = header['location'] + elif self.CREDIT_PATTERN in self.html: + self.logWarning("Not enough traffic left") + self.resetAccount() else: - self.html = self.load(self.pyfile.url) - - self.getFileInfo() # - - if self.CREDIT_PATTERN in self.html: - self.logWarning("Not enough traffic left") - self.resetAccount() + m = re.search(self.PREMIUM_URL_PATTERN, self.html) + if m: + url = m.group(1) else: - m = re.search(self.PREMIUM_URL_PATTERN, self.html) - if m: - url = m.group(1) - else: - self.error("Premium URL") + self.error("Premium URL") self.logDebug("PREMIUM URL: " + url) self.download(url, disposition=True) diff --git a/module/plugins/hoster/FilefactoryCom.py b/module/plugins/hoster/FilefactoryCom.py index 0e422f108..a5942e261 100644 --- a/module/plugins/hoster/FilefactoryCom.py +++ b/module/plugins/hoster/FilefactoryCom.py @@ -38,7 +38,6 @@ class FilefactoryCom(SimpleHoster): def handleFree(self): - self.html = self.load(self.pyfile.url, decode=True) if "Currently only Premium Members can download files larger than" in self.html: self.fail("File too large for free download") elif "All free download slots on this server are currently in use" in self.html: diff --git a/module/plugins/hoster/FilerNet.py b/module/plugins/hoster/FilerNet.py index 6d62dfde8..7a8d49378 100644 --- a/module/plugins/hoster/FilerNet.py +++ b/module/plugins/hoster/FilerNet.py @@ -18,7 +18,7 @@ class FilerNet(SimpleHoster): __type__ = "hoster" __version__ = "0.07" - __pattern__ = r'https?://(?:www\.)?filer\.net/get/(\w+)' + __pattern__ = r'https?://(?:www\.)?filer\.net/get/\w+' __description__ = """Filer.net hoster plugin""" __license__ = "GPLv3" @@ -35,8 +35,7 @@ class FilerNet(SimpleHoster): # Wait between downloads m = re.search(r'musst du (\d+) Sekunden warten', self.html) if m: - waittime = int(m.group(1)) - self.retry(3, waittime, "Wait between free downloads") + self.retry(wait_time=int(m.group(1)), reason="Wait between free downloads") self.html = self.load(self.pyfile.url, decode=True) diff --git a/module/plugins/hoster/LomafileCom.py b/module/plugins/hoster/LomafileCom.py index 0c7e03484..1c86b16e8 100644 --- a/module/plugins/hoster/LomafileCom.py +++ b/module/plugins/hoster/LomafileCom.py @@ -24,7 +24,7 @@ class LomafileCom(XFSPHoster): OFFLINE_PATTERN = r'>(No such file|Software error:<)' TEMP_OFFLINE_PATTERN = r'The page may have been renamed, removed or be temporarily unavailable.<' - CAPTCHA_URL_PATTERN = r'(http://lomafile\.com/captchas/[^"\']+)' + CAPTCHA_PATTERN = r'(http://lomafile\.com/captchas/[^"\']+)' getInfo = create_getInfo(LomafileCom) diff --git a/module/plugins/hoster/MegaRapidCz.py b/module/plugins/hoster/MegaRapidCz.py index 06e6626c6..153f6ea8b 100644 --- a/module/plugins/hoster/MegaRapidCz.py +++ b/module/plugins/hoster/MegaRapidCz.py @@ -53,7 +53,7 @@ class MegaRapidCz(SimpleHoster): self.html = self.load(self.pyfile.url, decode=True) except BadHeader, e: self.account.relogin(self.user) - self.retry(max_tries=3, reason=str(e)) + self.retry(wait_time=60, reason=str(e)) m = re.search(self.LINK_PATTERN, self.html) if m: @@ -63,7 +63,7 @@ class MegaRapidCz(SimpleHoster): else: if re.search(self.ERR_LOGIN_PATTERN, self.html): self.relogin(self.user) - self.retry(max_tries=3, reason="User login failed") + self.retry(wait_time=60, reason="User login failed") elif re.search(self.ERR_CREDIT_PATTERN, self.html): self.fail("Not enough credit left") else: diff --git a/module/plugins/hoster/OneFichierCom.py b/module/plugins/hoster/OneFichierCom.py index e6e193b89..3f3d0a19a 100644 --- a/module/plugins/hoster/OneFichierCom.py +++ b/module/plugins/hoster/OneFichierCom.py @@ -37,7 +37,6 @@ class OneFichierCom(SimpleHoster): def handleFree(self): - self.html = self.load(self.pyfile.url, decode=True) m = re.search(self.WAIT_PATTERN, self.html) if m: wait_time = int(m.group(1)) + 1 #: One minute more than what the page displays to be safe diff --git a/module/plugins/hoster/ShareonlineBiz.py b/module/plugins/hoster/ShareonlineBiz.py index 7a73ab316..b7c112a45 100644 --- a/module/plugins/hoster/ShareonlineBiz.py +++ b/module/plugins/hoster/ShareonlineBiz.py @@ -55,38 +55,28 @@ class ShareonlineBiz(Hoster): def setup(self): - # range request not working? - # api supports resume, only one chunk - # website isn't supporting resuming in first place self.file_id = re.match(self.__pattern__, self.pyfile.url).group("ID") self.pyfile.url = "http://www.share-online.biz/dl/" + self.file_id self.resumeDownload = self.premium self.multiDL = False - #self.chunkLimit = 1 self.check_data = None + def process(self, pyfile): if self.premium: self.handlePremium() - #web-download fallback removed - didn't work anyway else: self.handleFree() - # check = self.checkDownload({"failure": re.compile(self.ERROR_INFO_PATTERN)}) - # if check == "failure": - # try: - # self.retry(reason=self.lastCheck.group(1).decode("utf8")) - # except: - # self.retry(reason="Unknown error") - if self.api_data: self.check_data = {"size": int(self.api_data['size']), "md5": self.api_data['md5']} + def loadAPIData(self): api_url_base = "http://api.share-online.biz/linkcheck.php?md5=1" - api_param_file = {"links": self.file_id} # api only supports old style links + api_param_file = {"links": self.file_id} #: api only supports old style links src = self.load(api_url_base, cookies=False, post=api_param_file, decode=True) fields = src.split(";") @@ -96,15 +86,16 @@ class ShareonlineBiz(Hoster): self.offline() else: self.api_data['filename'] = fields[2] - self.api_data['size'] = fields[3] # in bytes - self.api_data['md5'] = fields[4].strip().lower().replace("\n\n", "") # md5 + self.api_data['size'] = fields[3] #: in bytes + self.api_data['md5'] = fields[4].strip().lower().replace("\n\n", "") #: md5 + def handleFree(self): self.loadAPIData() self.pyfile.name = self.api_data['filename'] self.pyfile.size = int(self.api_data['size']) - self.html = self.load(self.pyfile.url, cookies=True) # refer, stuff + self.html = self.load(self.pyfile.url, cookies=True) #: refer, stuff self.setWait(3) self.wait() @@ -152,6 +143,7 @@ class ShareonlineBiz(Hoster): else: self.correctCaptcha() + def handlePremium(self): #: should be working better loading (account) api internally self.account.getAccountInfo(self.user, True) src = self.load("http://api.share-online.biz/account.php", @@ -177,6 +169,7 @@ class ShareonlineBiz(Hoster): self.multiDL = True self.download(dlLink) + def checkErrors(self): m = re.search(r"/failure/(.*?)/1", self.req.lastEffectiveURL) if m is None: diff --git a/module/plugins/hoster/TurbobitNet.py b/module/plugins/hoster/TurbobitNet.py index 8557e0ce7..ded926010 100644 --- a/module/plugins/hoster/TurbobitNet.py +++ b/module/plugins/hoster/TurbobitNet.py @@ -38,7 +38,7 @@ class TurbobitNet(SimpleHoster): LINK_PATTERN = r'(?P/download/redirect/[^"\']+)' LIMIT_WAIT_PATTERN = r'
(\d+)<' - CAPTCHA_URL_PATTERN = r'CaptchaDownload Link\s*]*>([^<]+)' LINK_PATTERN = None #: final download url pattern - CAPTCHA_URL_PATTERN = r'(http://[^"\']+?/captchas?/[^"\']+)' + CAPTCHA_PATTERN = r'(http://[^"\']+?/captchas?/[^"\']+)' CAPTCHA_DIV_PATTERN = r'>Enter code.*?(.+?)
' RECAPTCHA_PATTERN = None SOLVEMEDIA_PATTERN = None @@ -306,7 +306,7 @@ class XFSPHoster(SimpleHoster): def handleCaptcha(self, inputs): - m = re.search(self.CAPTCHA_URL_PATTERN, self.html) + m = re.search(self.CAPTCHA_PATTERN, self.html) if m: captcha_url = m.group(1) inputs['code'] = self.decryptCaptcha(captcha_url) -- cgit v1.2.3