diff options
Diffstat (limited to 'module/plugins/hoster/FilerNet.py')
-rw-r--r-- | module/plugins/hoster/FilerNet.py | 132 |
1 files changed, 43 insertions, 89 deletions
diff --git a/module/plugins/hoster/FilerNet.py b/module/plugins/hoster/FilerNet.py index 91805ca40..c5007e945 100644 --- a/module/plugins/hoster/FilerNet.py +++ b/module/plugins/hoster/FilerNet.py @@ -1,120 +1,74 @@ # -*- coding: utf-8 -*- -############################################################################ -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU Affero General Public License as # -# published by the Free Software Foundation, either version 3 of the # -# License, or (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU Affero General Public License for more details. # -# # -# You should have received a copy of the GNU Affero General Public License # -# along with this program. If not, see <http://www.gnu.org/licenses/>. # -############################################################################ - -# Test links (random.bin): +# +# Test links: # http://filer.net/get/ivgf5ztw53et3ogd # http://filer.net/get/hgo14gzcng3scbvv import pycurl import re + from urlparse import urljoin -from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo from module.plugins.internal.CaptchaService import ReCaptcha +from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo class FilerNet(SimpleHoster): - __name__ = "FilerNet" - __type__ = "hoster" - __pattern__ = r'https?://(?:www\.)?filer\.net/get/(\w+)' - __version__ = "0.03" + __name__ = "FilerNet" + __type__ = "hoster" + __version__ = "0.16" + + __pattern__ = r'https?://(?:www\.)?filer\.net/get/\w+' + __description__ = """Filer.net hoster plugin""" - __author_name__ = "stickell" - __author_mail__ = "l.stickell@yahoo.it" + __license__ = "GPLv3" + __authors__ = [("stickell", "l.stickell@yahoo.it"), + ("Walter Purcaro", "vuolter@gmail.com")] - FILE_INFO_PATTERN = r'<h1 class="page-header">Free Download (?P<N>\S+) <small>(?P<S>[\w.]+) (?P<U>\w+)</small></h1>' - OFFLINE_PATTERN = r'Nicht gefunden' - RECAPTCHA_KEY = "6LcFctISAAAAAAgaeHgyqhNecGJJRnxV1m_vAz3V" - LINK_PATTERN = r'href="([^"]+)">Get download</a>' + INFO_PATTERN = r'<h1 class="page-header">Free Download (?P<N>\S+) <small>(?P<S>[\w.]+) (?P<U>[\w^_]+)</small></h1>' + OFFLINE_PATTERN = r'Nicht gefunden' - def process(self, pyfile): - if self.premium and (not self.SH_CHECK_TRAFFIC or self.checkTrafficLeft()): - self.handlePremium() - else: - self.handleFree() + LINK_FREE_PATTERN = LINK_PREMIUM_PATTERN = r'href="([^"]+)">Get download</a>' - def handleFree(self): - self.req.setOption("timeout", 120) - self.html = self.load(self.pyfile.url, decode=not self.SH_BROKEN_ENCODING, cookies=self.SH_COOKIES) + def checkErrors(self): # Wait between downloads m = re.search(r'musst du <span id="time">(\d+)</span> Sekunden warten', self.html) if m: - waittime = int(m.group(1)) - self.retry(3, waittime, "Wait between free downloads") + errmsg = self.info['error'] = _("Wait between free downloads") + self.retry(wait_time=int(m.group(1)), reason=errmsg) - self.getFileInfo() + self.info.pop('error', None) - self.html = self.load(self.pyfile.url, decode=True) - inputs = self.parseHtmlForm(input_names='token')[1] + def handleFree(self, pyfile): + inputs = self.parseHtmlForm(input_names={'token': re.compile(r'.+')})[1] if 'token' not in inputs: - self.parseError('Unable to detect token') - token = inputs['token'] - self.logDebug('Token: ' + token) + self.error(_("Unable to detect token")) - self.html = self.load(self.pyfile.url, post={'token': token}, decode=True) + self.html = self.load(pyfile.url, post={'token': inputs['token']}, decode=True) - inputs = self.parseHtmlForm(input_names='hash')[1] + inputs = self.parseHtmlForm(input_names={'hash': re.compile(r'.+')})[1] if 'hash' not in inputs: - self.parseError('Unable to detect hash') - hash_data = inputs['hash'] - self.logDebug('Hash: ' + hash_data) - - downloadURL = r'' - recaptcha = ReCaptcha(self) - for _ in xrange(5): - challenge, response = recaptcha.challenge(self.RECAPTCHA_KEY) - post_data = {'recaptcha_challenge_field': challenge, - 'recaptcha_response_field': response, - 'hash': hash_data} - - # Workaround for 0.4.9 just_header issue. In 0.5 clean the code using just_header - self.req.http.c.setopt(pycurl.FOLLOWLOCATION, 0) - self.load(self.pyfile.url, post=post_data) - self.req.http.c.setopt(pycurl.FOLLOWLOCATION, 1) - - if 'location' in self.req.http.header.lower(): - location = re.search(r'location: (\S+)', self.req.http.header, re.I).group(1) - downloadURL = urljoin('http://filer.net', location) - self.correctCaptcha() - break - else: - self.logInfo('Wrong captcha') - self.invalidCaptcha() - - if not downloadURL: - self.fail("No Download url retrieved/all captcha attempts failed") - - self.download(downloadURL, disposition=True) - - def handlePremium(self): - header = self.load(self.pyfile.url, just_header=True) - if 'location' in header: # Direct Download ON - dl = self.pyfile.url - else: # Direct Download OFF - html = self.load(self.pyfile.url) - m = re.search(self.LINK_PATTERN, html) - if m is None: - self.parseError("Unable to detect direct link, try to enable 'Direct download' in your user settings") - dl = 'http://filer.net' + m.group(1) - - self.logDebug('Direct link: ' + dl) - self.download(dl, disposition=True) + self.error(_("Unable to detect hash")) + + recaptcha = ReCaptcha(self) + response, challenge = recaptcha.challenge() + + #@NOTE: Work-around for v0.4.9 just_header issue + #@TODO: Check for v0.4.10 + self.req.http.c.setopt(pycurl.FOLLOWLOCATION, 0) + self.load(pyfile.url, post={'recaptcha_challenge_field': challenge, + 'recaptcha_response_field' : response, + 'hash' : inputs['hash']}) + self.req.http.c.setopt(pycurl.FOLLOWLOCATION, 1) + + if 'location' in self.req.http.header.lower(): + self.link = re.search(r'location: (\S+)', self.req.http.header, re.I).group(1) + self.correctCaptcha() + else: + self.invalidCaptcha() getInfo = create_getInfo(FilerNet) |