diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-05 23:06:17 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-05 23:06:17 +0100 |
commit | 4a6a99d3fe5bcfcb7c3bb35b6cf001adb62d3bb5 (patch) | |
tree | 8c825f6867b2668cdb4b61ded41da8758e9dd368 /module/plugins | |
parent | [RapiduNet] Cleanup (diff) | |
download | pyload-4a6a99d3fe5bcfcb7c3bb35b6cf001adb62d3bb5.tar.xz |
[FileSharkPl] Cleanup
Diffstat (limited to 'module/plugins')
-rw-r--r-- | module/plugins/hoster/FileSharkPl.py | 101 |
1 files changed, 46 insertions, 55 deletions
diff --git a/module/plugins/hoster/FileSharkPl.py b/module/plugins/hoster/FileSharkPl.py index 5683d2a9e..ea2b56821 100644 --- a/module/plugins/hoster/FileSharkPl.py +++ b/module/plugins/hoster/FileSharkPl.py @@ -10,7 +10,7 @@ from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo class FileSharkPl(SimpleHoster): __name__ = "FileSharkPl" __type__ = "hoster" - __version__ = "0.02" + __version__ = "0.03" __pattern__ = r'http://(?:www\.)?fileshark\.pl/pobierz/\d{6}/\w{5}' @@ -20,22 +20,23 @@ class FileSharkPl(SimpleHoster): ("Walter Purcaro", "vuolter@gmail.com")] + CONTENT_DISPOSITION = True + NAME_PATTERN = r'<h2 class="name-file">(?P<N>.+)</h2>' SIZE_PATTERN = r'<p class="size-file">(.*?)<strong>(?P<S>\d+\.?\d*)\s(?P<U>\w+)</strong></p>' OFFLINE_PATTERN = '(P|p)lik zosta. (usuni.ty|przeniesiony)' - DOWNLOAD_ALERT = r'<p class="lead text-center alert alert-warning">(.*?)</p>' - IP_BLOCKED_PATTERN = 'Strona jest dost.pna wy..cznie dla u.ytkownik.w znajduj.cych si. na terenie Polski' - DOWNLOAD_SLOTS_ERROR_PATTERN = r'Osi.gni.to maksymaln. liczb. .ci.ganych jednocze.nie plik.w\.' - - DOWNLOAD_URL_FREE = r'<a href="(.*?)" class="btn-upload-free">' - DOWNLOAD_URL_PREMIUM = r'<a href="(.*?)" class="btn-upload-premium">' + LINK_FREE_PATTERN = r'<a href="(.*?)" class="btn-upload-free">' + LINK_PREMIUM_PATTERN = r'<a href="(.*?)" class="btn-upload-premium">' - SECONDS_PATTERN = r'var timeToDownload = (\d+);' + WAIT_PATTERN = r'var timeToDownload = (\d+);' + ERROR_PATTERN = r'<p class="lead text-center alert alert-warning">(.*?)</p>' + IP_ERROR_PATTERN = r'Strona jest dost.pna wy..cznie dla u.ytkownik.w znajduj.cych si. na terenie Polski' + SLOT_ERROR_PATTERN = r'Osi.gni.to maksymaln. liczb. .ci.ganych jednocze.nie plik.w\.' - CAPTCHA_IMG_PATTERN = '<img src="data:image/jpeg;base64,(.*?)" title="captcha"' - CAPTCHA_TOKEN_PATTERN = r'name="form\[_token\]" value="(.*?)" />' + CAPTCHA_PATTERN = '<img src="data:image/jpeg;base64,(.*?)" title="captcha"' + TOKEN_PATTERN = r'name="form\[_token\]" value="(.*?)" />' def setup(self): @@ -47,89 +48,79 @@ class FileSharkPl(SimpleHoster): self.multiDL = False - def prepare(self): - super(FileSharkPl, self).prepare() - + def checkErrors(self): # check if file is now available for download (-> file name can be found in html body) - try: - m = re.search(self.FILE_NAME_PATTERN, self.html) - pyfile.name = m.group('N') - except: - try: - m = re.match(self.__pattern__, pyfile.url) - pyfile.name = m.group(1) - except: - pyfile.name = "NoName" - - sec = re.search(self.SECONDS_PATTERN, self.html) - if sec: - self.retry(15,int(sec.group(1)),"Another download already run") - - m = re.search(self.DOWNLOAD_ALERT, self.html): + m = re.search(self.WAIT_PATTERN, self.html) + if m: + errmsg = self.info['error'] = _("Another download already run") + self.retry(15, int(m.group(1)), errmsg) + + m = re.search(self.ERROR_PATTERN, self.html): if m: alert = m.group(1) - if re.match(self.IP_BLOCKED_PATTERN, alert): + + if re.match(self.IP_ERROR_PATTERN, alert): self.fail(_("Only connections from Polish IP are allowed")) - elif re.match(self.DOWNLOAD_SLOTS_ERROR_PATTERN, alert): - self.logInfo(_("No free download slots available")) + + elif re.match(self.SLOT_ERROR_PATTERN, alert): + errmsg = self.info['error'] = _("No free download slots available") + self.logWarning(errmsg) self.retry(10, 30 * 60, _("Still no free download slots available")) + else: - self.logInfo(alert) + self.info['error'] = alert self.retry(10, 10 * 60, _("Try again later")) + self.info.pop('error', None) + #@NOTE: handlePremium method was never been tested def handlePremium(self): - self.logDebug("Premium accounts support in experimental modus!") - m = re.search(self.DOWNLOAD_URL_PREMIUM, self.html) - file_url = urljoin("http://fileshark.pl", m.group(1)) - - self.download(file_url, disposition=True) - self.checkDownload() + super(FilerNet, self).handlePremium() + if self.link: + self.link = urljoin("http://fileshark.pl/", self.link) def handleFree(self): - m = re.search(self.DOWNLOAD_URL_FREE, self.html) + m = re.search(self.LINK_FREE_PATTERN, self.html) if m is None: self.error(_("Download url not found")) - file_url = urljoin("http://fileshark.pl", m.group(1)) + link = urljoin("http://fileshark.pl", m.group(1)) - m = re.search(self.SECONDS_PATTERN, self.html) + m = re.search(self.WAIT_PATTERN, self.html) if m: seconds = int(m.group(1)) self.logDebug("Wait %s seconds" % seconds) - self.wait(seconds + 2) + self.wait(seconds) action, inputs = self.parseHtmlForm('action=""') - m = re.search(self.CAPTCHA_TOKEN_PATTERN, self.html) + + m = re.search(self.TOKEN_PATTERN, self.html) if m is None: self.retry(reason=_("Captcha form not found")) inputs['form[_token]'] = m.group(1) - m = re.search(self.CAPTCHA_IMG_PATTERN, self.html) + m = re.search(self.CAPTCHA_PATTERN, self.html) if m is None: self.retry(reason=_("Captcha image not found")) - tmp_load = self.load - self.load = self.decode64 #: injects decode64 inside decryptCaptcha + tmp_load = self.load + self.load = self._decode64 #: work-around: injects decode64 inside decryptCaptcha inputs['form[captcha]'] = self.decryptCaptcha(m.group(1), imgtype='jpeg') inputs['form[start]'] = "" self.load = tmp_load - self.download(file_url, post=inputs, cookies=True, disposition=True) - self.checkDownload() + self.download(link, post=inputs, cookies=True, disposition=True) - def checkDownload(self): - check = super(FileSharkPl, self).checkDownload({ - 'wrong_captcha': re.compile(r'<label for="form_captcha" generated="true" class="error">(.*?)</label>'), - 'wait_pattern': re.compile(self.SECONDS_PATTERN), - 'DL-found': re.compile('<a href="(.*)">') - }) + def checkFile(self): + check = self.checkDownload({'wrong_captcha': re.compile(r'<label for="form_captcha" generated="true" class="error">(.*?)</label>'), + 'wait_pattern' : re.compile(self.SECONDS_PATTERN), + 'DL-found' : re.compile('<a href="(.*)">')}) if check == "DL-found": self.correctCaptcha() @@ -142,7 +133,7 @@ class FileSharkPl(SimpleHoster): self.retry() - def decode64(self, data, *args, **kwargs): + def _decode64(self, data, *args, **kwargs): return data.decode("base64") |