diff options
author | Stefano <l.stickell@yahoo.it> | 2013-07-22 20:50:34 +0200 |
---|---|---|
committer | Stefano <l.stickell@yahoo.it> | 2013-07-22 21:20:06 +0200 |
commit | aaaf5a4cddec894aacd7400c59a9f2f5e710362f (patch) | |
tree | 9d9e89aff86598b3ffcc86117abd554b193e28b5 /pyload/plugins/hoster/DlFreeFr.py | |
parent | implemented media type filter (diff) | |
download | pyload-aaaf5a4cddec894aacd7400c59a9f2f5e710362f.tar.xz |
Fixed PEP 8 violations in Hosters
(cherry picked from commit 2edeee0532ec6d6b4b26fd045a5971f67ca455da)
Conflicts:
pyload/plugins/hoster/BasePlugin.py
pyload/plugins/hoster/MultishareCz.py
pyload/plugins/hoster/NetloadIn.py
pyload/plugins/hoster/PremiumizeMe.py
pyload/plugins/hoster/RapidshareCom.py
Diffstat (limited to 'pyload/plugins/hoster/DlFreeFr.py')
-rw-r--r-- | pyload/plugins/hoster/DlFreeFr.py | 114 |
1 files changed, 66 insertions, 48 deletions
diff --git a/pyload/plugins/hoster/DlFreeFr.py b/pyload/plugins/hoster/DlFreeFr.py index 67c2d6c17..1f0e38acd 100644 --- a/pyload/plugins/hoster/DlFreeFr.py +++ b/pyload/plugins/hoster/DlFreeFr.py @@ -2,17 +2,18 @@ # -*- coding: utf-8 -*- import re +import pycurl + from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo, replace_patterns from module.common.json_layer import json_loads - -import pycurl from module.network.Browser import Browser from module.network.CookieJar import CookieJar + class CustomBrowser(Browser): def __init__(self, bucket=None, options={}): Browser.__init__(self, bucket, options) - + def load(self, *args, **kwargs): post = kwargs.get("post") if post is None: @@ -28,30 +29,36 @@ class CustomBrowser(Browser): self.http.c.setopt(pycurl.CUSTOMREQUEST, "GET") return Browser.load(self, *args, **kwargs) -""" -Class to support adyoulike captcha service -""" + class AdYouLike(): + """ + Class to support adyoulike captcha service + """ ADYOULIKE_INPUT_PATTERN = r'Adyoulike.create\((.*?)\);' ADYOULIKE_CALLBACK = r'Adyoulike.g._jsonp_5579316662423138' - ADYOULIKE_CHALLENGE_PATTERN = ADYOULIKE_CALLBACK + r'\((.*?)\)' - - def __init__(self, plugin, engine = "adyoulike"): + ADYOULIKE_CHALLENGE_PATTERN = ADYOULIKE_CALLBACK + r'\((.*?)\)' + + def __init__(self, plugin, engine="adyoulike"): self.plugin = plugin self.engine = engine - - def challenge(self, html): + + def challenge(self, html): adyoulike_data_string = None found = re.search(self.ADYOULIKE_INPUT_PATTERN, html) if found: adyoulike_data_string = found.group(1) else: self.plugin.fail("Can't read AdYouLike input data") - - ayl_data = json_loads(adyoulike_data_string) #{"adyoulike":{"key":"P~zQ~O0zV0WTiAzC-iw0navWQpCLoYEP"},"all":{"element_id":"ayl_private_cap_92300","lang":"fr","env":"prod"}} - res = self.plugin.load(r'http://api-ayl.appspot.com/challenge?key=%(ayl_key)s&env=%(ayl_env)s&callback=%(callback)s' % {"ayl_key": ayl_data[self.engine]["key"], "ayl_env": ayl_data["all"]["env"], "callback": self.ADYOULIKE_CALLBACK}) - + # {"adyoulike":{"key":"P~zQ~O0zV0WTiAzC-iw0navWQpCLoYEP"}, + # "all":{"element_id":"ayl_private_cap_92300","lang":"fr","env":"prod"}} + ayl_data = json_loads(adyoulike_data_string) + + res = self.plugin.load( + r'http://api-ayl.appspot.com/challenge?key=%(ayl_key)s&env=%(ayl_env)s&callback=%(callback)s' % { + "ayl_key": ayl_data[self.engine]["key"], "ayl_env": ayl_data["all"]["env"], + "callback": self.ADYOULIKE_CALLBACK}) + found = re.search(self.ADYOULIKE_CHALLENGE_PATTERN, res) challenge_string = None if found: @@ -59,12 +66,20 @@ class AdYouLike(): else: self.plugin.fail("Invalid AdYouLike challenge") challenge_data = json_loads(challenge_string) - + return ayl_data, challenge_data - + def result(self, ayl, challenge): """ - Adyoulike.g._jsonp_5579316662423138({"translations":{"fr":{"instructions_visual":"Recopiez « Soonnight » ci-dessous :"}},"site_under":true,"clickable":true,"pixels":{"VIDEO_050":[],"DISPLAY":[],"VIDEO_000":[],"VIDEO_100":[],"VIDEO_025":[],"VIDEO_075":[]},"medium_type":"image/adyoulike","iframes":{"big":"<iframe src=\"http://www.soonnight.com/campagn.html\" scrolling=\"no\" height=\"250\" width=\"300\" frameborder=\"0\"></iframe>"},"shares":{},"id":256,"token":"e6QuI4aRSnbIZJg02IsV6cp4JQ9~MjA1","formats":{"small":{"y":300,"x":0,"w":300,"h":60},"big":{"y":0,"x":0,"w":300,"h":250},"hover":{"y":440,"x":0,"w":300,"h":60}},"tid":"SqwuAdxT1EZoi4B5q0T63LN2AkiCJBg5"}) + Adyoulike.g._jsonp_5579316662423138 + ({"translations":{"fr":{"instructions_visual":"Recopiez « Soonnight » ci-dessous :"}}, + "site_under":true,"clickable":true,"pixels":{"VIDEO_050":[],"DISPLAY":[],"VIDEO_000":[],"VIDEO_100":[], + "VIDEO_025":[],"VIDEO_075":[]},"medium_type":"image/adyoulike", + "iframes":{"big":"<iframe src=\"http://www.soonnight.com/campagn.html\" scrolling=\"no\" + height=\"250\" width=\"300\" frameborder=\"0\"></iframe>"},"shares":{},"id":256, + "token":"e6QuI4aRSnbIZJg02IsV6cp4JQ9~MjA1","formats":{"small":{"y":300,"x":0,"w":300,"h":60}, + "big":{"y":0,"x":0,"w":300,"h":250},"hover":{"y":440,"x":0,"w":300,"h":60}}, + "tid":"SqwuAdxT1EZoi4B5q0T63LN2AkiCJBg5"}) """ response = None try: @@ -76,53 +91,54 @@ class AdYouLike(): self.plugin.fail("Can't parse instructions visual") except KeyError: self.plugin.fail("No instructions visual") - + #TODO: Supports captcha - + if not response: self.plugin.fail("AdYouLike result failed") - - return {"_ayl_captcha_engine" : self.engine, - "_ayl_env" : ayl["all"]["env"], - "_ayl_tid" : challenge["tid"], - "_ayl_token_challenge" : challenge["token"], - "_ayl_response": response } + + return {"_ayl_captcha_engine": self.engine, + "_ayl_env": ayl["all"]["env"], + "_ayl_tid": challenge["tid"], + "_ayl_token_challenge": challenge["token"], + "_ayl_response": response} + class DlFreeFr(SimpleHoster): __name__ = "DlFreeFr" __type__ = "hoster" __pattern__ = r"http://dl\.free\.fr/([a-zA-Z0-9]+|getfile\.pl\?file=/[a-zA-Z0-9]+)" - __version__ = "0.24" + __version__ = "0.25" __description__ = """dl.free.fr download hoster""" __author_name__ = ("the-razer", "zoidberg", "Toilal") __author_mail__ = ("daniel_ AT gmx DOT net", "zoidberg@mujmail.cz", "toilal.dev@gmail.com") - + FILE_NAME_PATTERN = r"Fichier:</td>\s*<td[^>]*>(?P<N>[^>]*)</td>" FILE_SIZE_PATTERN = r"Taille:</td>\s*<td[^>]*>(?P<S>[\d.]+[KMG])o" FILE_OFFLINE_PATTERN = r"Erreur 404 - Document non trouv|Fichier inexistant|Le fichier demandé n'a pas été trouvé" #FILE_URL_PATTERN = r'href="(?P<url>http://.*?)">Télécharger ce fichier' - + def setup(self): self.limitDL = 5 self.resumeDownload = True - self.chunkLimit = 1 + self.chunkLimit = 1 def init(self): factory = self.core.requestFactory self.req = CustomBrowser(factory.bucket, factory.getOptions()) - + def process(self, pyfile): self.req.setCookieJar(None) - + pyfile.url = replace_patterns(pyfile.url, self.FILE_URL_REPLACEMENTS) valid_url = pyfile.url - headers = self.load(valid_url, just_header = True) - + headers = self.load(valid_url, just_header=True) + self.html = None if headers.get('code') == 302: valid_url = headers.get('location') - headers = self.load(valid_url, just_header = True) - + headers = self.load(valid_url, just_header=True) + if headers.get('code') == 200: content_type = headers.get('content-type') if content_type and content_type.startswith("text/html"): @@ -131,23 +147,23 @@ class DlFreeFr(SimpleHoster): self.handleFree() else: # Direct access to requested file for users using free.fr as Internet Service Provider. - self.download(valid_url, disposition=True) + self.download(valid_url, disposition=True) elif headers.get('code') == 404: self.offline() else: self.fail("Invalid return code: " + str(headers.get('code'))) - - def handleFree(self): + + def handleFree(self): action, inputs = self.parseHtmlForm('action="getfile.pl"') - + adyoulike = AdYouLike(self) ayl, challenge = adyoulike.challenge(self.html) result = adyoulike.result(ayl, challenge) inputs.update(result) - - self.load("http://dl.free.fr/getfile.pl", post = inputs) - headers = self.getLastHeaders() - if headers.get("code") == 302 and headers.has_key("set-cookie") and headers.has_key("location"): + + self.load("http://dl.free.fr/getfile.pl", post=inputs) + headers = self.getLastHeaders() + if headers.get("code") == 302 and "set-cookie" in headers and "location" in headers: found = re.search("(.*?)=(.*?); path=(.*?); domain=(.*?)", headers.get("set-cookie")) cj = CookieJar(__name__) if found: @@ -156,16 +172,17 @@ class DlFreeFr(SimpleHoster): self.fail("Cookie error") location = headers.get("location") self.req.setCookieJar(cj) - self.download(location, disposition=True); + self.download(location, disposition=True) else: self.fail("Invalid response") - + def getLastHeaders(self): #parse header header = {"code": self.req.code} for line in self.req.http.header.splitlines(): line = line.strip() - if not line or ":" not in line: continue + if not line or ":" not in line: + continue key, none, value = line.partition(":") key = key.lower().strip() @@ -180,4 +197,5 @@ class DlFreeFr(SimpleHoster): header[key] = value return header -getInfo = create_getInfo(DlFreeFr) + +getInfo = create_getInfo(DlFreeFr) |