diff options
author | zoidberg10 <zoidberg@mujmail.cz> | 2011-10-05 18:28:47 +0200 |
---|---|---|
committer | zoidberg10 <zoidberg@mujmail.cz> | 2011-10-05 18:28:47 +0200 |
commit | c8e0fae8976fad733ae715870c9e322668133f92 (patch) | |
tree | 90c93aac8810b9c37eabd1d0229b8854968d45a8 /module/plugins | |
parent | updated simplejson (diff) | |
download | pyload-c8e0fae8976fad733ae715870c9e322668133f92.tar.xz |
mediafire.com plugin update (still not finished)
Diffstat (limited to 'module/plugins')
-rw-r--r-- | module/plugins/hoster/MediafireCom.py | 87 |
1 files changed, 59 insertions, 28 deletions
diff --git a/module/plugins/hoster/MediafireCom.py b/module/plugins/hoster/MediafireCom.py index ae1c13613..9e18527cf 100644 --- a/module/plugins/hoster/MediafireCom.py +++ b/module/plugins/hoster/MediafireCom.py @@ -19,6 +19,7 @@ import re from module.plugins.Hoster import Hoster from module.network.RequestFactory import getURL +from module.plugins.ReCaptcha import ReCaptcha def getInfo(urls): result = [] @@ -45,12 +46,14 @@ def getInfo(urls): result.append((name, size, 2, url)) yield result +def replace_eval(js_expr): + return js_expr.replace(r"\'", r"'").replace(r'eval("', '') class MediafireCom(Hoster): __name__ = "MediafireCom" __type__ = "hoster" __pattern__ = r"http://(?:\w*\.)*mediafire\.com/.*" - __version__ = "0.2" + __version__ = "0.3" __description__ = """Mediafire.com plugin - free only""" __author_name__ = ("zoidberg") @@ -59,68 +62,96 @@ class MediafireCom(Hoster): PAGE1_RESULT_PATTERN = r"(\w+)\('(?P<qk>[^']+)','(?P<pk1>[^']+)'\)" PAGE1_DIV_PATTERN = r'getElementById\("(\w{32})"\)' PAGE1_PKR_PATTERN = r"pKr='([^']+)';" + RECAPTCHA_PATTERN = r'src="http://api.recaptcha.net/challenge?k=([^"]+)">' + PAGE1_ACTION_PATTERN = r'<link rel="canonical" href="([^"]+)"/>' PAGE2_VARS_PATTERN = r'<script language="Javascript"><!--\s*(var.*?unescape.*?)eval\(' PAGE2_DZ_PATTERN = r'break;case 15:(.*)</script>' - PAGE2_LINK_PATTERN = r"(?:if.*</a>\')?(?:eval\(\")?(.*?)eval\(" - FINAL_LINK_PATTERN = r'parent.document.getElementById\(\'(\w{32})\'\)\).*?"(http://download[^"]+)" \+(\w+)\+ "([^"]+)">' + PAGE2_LINK_PATTERN = r"(\w+='';\w+=unescape.*?)eval\(\w+\);(\\\" href=[^\>]*>)?" + FINAL_LINK_PATTERN = r'parent.document.getElementById\(\'(\w{32})\'\).*(http://[^"]+)" \+(\w+)\+ "([^"]+)">' FILE_NAME_PATTERN = r'<META NAME="description" CONTENT="([^"]+)"/>' FILE_SIZE_PATTERN = r'<div style="font-size:14px;padding-top:12px;color:#777;">\(([0-9.]+) (kB|MB|GB)\)</div>' FILE_OFFLINE_PATTERN = r'class="error_msg_title"> Invalid or Deleted File. </div>' + def setup(self): + self.multiDL = False + def process(self, pyfile): - self.html = self.load(pyfile.url, decode=True) + self.html = self.load(pyfile.url) - try: - pyfile.name = re.search(self.FILE_NAME_PATTERN, self.html).group(1) - found = re.search(self.FILE_SIZE_PATTERN, self.html) + found = re.search(self.FILE_NAME_PATTERN, self.html) + if not found: self.fail("Parse error (file name)") + pyfile.name = found.group(1) + + found = re.search(self.FILE_SIZE_PATTERN, self.html) + if found: pyfile.size = float(found.group(1)) * 1024 ** {'kB': 1, 'MB': 2, 'GB': 3}[found.group(2)] - except Exception, e: - self.logError(e) - self.retry(3, 0, "Parse error - file info") self.handleFree() def handleFree(self): + found = re.search(self.RECAPTCHA_PATTERN, self.html) + if found: + captcha_action = re.search(self.PAGE1_ACTION_PATTERN, self.html).group(1) + captcha_key = found.group(1) + recaptcha = ReCaptcha(self) + captcha_challenge, captcha_response = recaptcha.challenge(captcha_key) + self.html = self.load(captcha_action, post = { + "recaptcha_challenge_field": captcha_challenge, + "recaptcha_response_field": captcha_response + }) + found = re.search(self.PAGE1_KEY_PATTERN, self.html) if found: result = self.js.eval(found.group(1)) found = re.search(self.PAGE1_RESULT_PATTERN, result) else: - self.fail("Parse error - javascript") + self.retry(3, 0, "Parse error (KEY)") - param_dict = found.groupdict() - param_dict['r'] = re.search(self.PAGE1_PKR_PATTERN, self.html).group(1) - self.logDebug(param_dict) - key_func = found.group(1) - self.logDebug("KEY_FUNC: %s" % key_func) + try: + param_dict = found.groupdict() + param_dict['r'] = re.search(self.PAGE1_PKR_PATTERN, self.html).group(1) + self.logDebug(param_dict) + key_func = found.group(1) + self.logDebug("KEY_FUNC: %s" % key_func) - found = re.search(self.PAGE1_FUNCTION_PATTERN % key_func, self.html) - result = self.js.eval(found.group(1)) - key_div = re.search(self.PAGE1_DIV_PATTERN, result).group(1) - self.logDebug("KEY_DIV: %s" % key_div) + found = re.search(self.PAGE1_FUNCTION_PATTERN % key_func, self.html) + result = self.js.eval(found.group(1)) + key_div = re.search(self.PAGE1_DIV_PATTERN, result).group(1) + self.logDebug("KEY_DIV: %s" % key_div) + except Exception, e: + self.logError(e) + self.retry(3, 0, "Parse error (KEY DIV)") self.html = self.load("http://www.mediafire.com/dynamic/download.php", get=param_dict) - result = self.js.eval(re.search(self.PAGE2_VARS_PATTERN, self.html).group(1)) + js_expr = replace_eval(re.search(self.PAGE2_VARS_PATTERN, self.html).group(1)) + result = self.js.eval(js_expr) var_list = dict(re.findall("([^=]+)='([^']+)';", result)) - page2_dz = re.search(self.PAGE2_DZ_PATTERN, self.html, re.DOTALL).group(1) + page2_dz = replace_eval(re.search(self.PAGE2_DZ_PATTERN, self.html, re.DOTALL).group(1)) final_link = None for link_enc in re.finditer(self.PAGE2_LINK_PATTERN, page2_dz): #self.logDebug("LINK_ENC: %s..." % link_enc.group(1)[:20]) try: - link_dec = self.js.eval(link_enc.group(1).replace(r"\'", r"'")) - except: + link_dec = self.js.eval(link_enc.group(1)) + except Exception, e: self.logError("Unable to decrypt link %s" % link_enc.group(1)[:20]) - self.logDebug(link_enc.group(1).replace(r"\'", r"'")) + self.logError(e) + self.logDebug(link_enc.group(1)) continue + #self.logDebug("LINK_DEC: %s" % link_dec) + if link_enc.group(2): link_dec = link_dec + replace_eval(link_enc.group(2)) + found = re.search(self.FINAL_LINK_PATTERN, link_dec) - if found and found.group(1) == key_div: - final_link = found.group(2) + var_list[found.group(3)] + found.group(4) - break + if found: + if found.group(1) == key_div: + final_link = found.group(2) + var_list[found.group(3)] + found.group(4) + break + else: + self.logDebug("Link not found in %s..." % link_dec) else: self.fail("Final link not found") |