diff options
author | zoidberg10 <zoidberg@mujmail.cz> | 2011-12-12 18:22:27 +0100 |
---|---|---|
committer | zoidberg10 <zoidberg@mujmail.cz> | 2011-12-12 18:22:27 +0100 |
commit | f999accf64045a348cf06ee4ffce74c80762c1e9 (patch) | |
tree | 252be3bbe3c173dd9f67709a8afd7c35c5384e5c | |
parent | closed #449 (diff) | |
download | pyload-f999accf64045a348cf06ee4ffce74c80762c1e9.tar.xz |
improve mediafire plugin
-rw-r--r-- | module/plugins/crypter/MediafireComFolder.py | 51 | ||||
-rw-r--r-- | module/plugins/hoster/LetitbitNet.py | 13 | ||||
-rw-r--r-- | module/plugins/hoster/MediafireCom.py | 81 |
3 files changed, 104 insertions, 41 deletions
diff --git a/module/plugins/crypter/MediafireComFolder.py b/module/plugins/crypter/MediafireComFolder.py index 49a72ca76..1056a3947 100644 --- a/module/plugins/crypter/MediafireComFolder.py +++ b/module/plugins/crypter/MediafireComFolder.py @@ -2,13 +2,14 @@ import re from module.plugins.Crypter import Crypter +from module.plugins.hoster.MediafireCom import checkHTMLHeader from module.common.json_layer import json_loads class MediafireComFolder(Crypter): __name__ = "MediafireComFolder" __type__ = "crypter" __pattern__ = r"http://(\w*\.)*mediafire\.com/(folder/|\?).*" - __version__ = "0.10" + __version__ = "0.12" __description__ = """Mediafire.com Folder Plugin""" __author_name__ = ("zoidberg") __author_mail__ = ("zoidberg@mujmail.cz") @@ -18,25 +19,39 @@ class MediafireComFolder(Crypter): def decrypt(self, pyfile): new_links = [] - - html = self.load(pyfile.url) - found = re.search(self.FILE_URL_PATTERN, html) - if found: - new_links.append("http://www.mediafire.com/download.php?" + found.group(1)) - else: - found = re.search(self.FOLDER_KEY_PATTERN, html) - if not found: self.fail('Parse error: Folder Key') - folder_key = found.group(1) - self.logDebug("FOLDER KEY: %s" % folder_key) + + url, result = checkHTMLHeader(pyfile.url) + self.logDebug('Location (%d): %s' % (result, url)) - json_resp = json_loads(self.load("http://www.mediafire.com/api/folder/get_info.php?folder_key=%s&response_format=json&version=1" % folder_key)) - #self.logInfo(json_resp) - if json_resp['response']['result'] == "Success": - for link in json_resp['response']['folder_info']['files']: - new_links.append("http://www.mediafire.com/download.php?%s" % link['quickkey']) + if result == 0: + # load and parse html + html = self.load(pyfile.url) + found = re.search(self.FILE_URL_PATTERN, html) + if found: + # file page + new_links.append("http://www.mediafire.com/file/%s" % found.group(1)) else: - self.fail(json_resp['response']['message']) - + # folder page + found = re.search(self.FOLDER_KEY_PATTERN, html) + if found: + folder_key = found.group(1) + self.logDebug("FOLDER KEY: %s" % folder_key) + + json_resp = json_loads(self.load("http://www.mediafire.com/api/folder/get_info.php?folder_key=%s&response_format=json&version=1" % folder_key)) + #self.logInfo(json_resp) + if json_resp['response']['result'] == "Success": + for link in json_resp['response']['folder_info']['files']: + new_links.append("http://www.mediafire.com/file/%s" % link['quickkey']) + else: + self.fail(json_resp['response']['message']) + else: + fileID = re.search(self.__pattern__, pyfile.url) + new_links.append("ttp://www.mediafire.com/file/%s" % fileID) + elif result == 1: + self.offline() + else: + new_links.append(url) + if new_links: self.core.files.addLinks(new_links, self.pyfile.package().id) else: diff --git a/module/plugins/hoster/LetitbitNet.py b/module/plugins/hoster/LetitbitNet.py index 01d796330..8ac4b8f7f 100644 --- a/module/plugins/hoster/LetitbitNet.py +++ b/module/plugins/hoster/LetitbitNet.py @@ -30,8 +30,9 @@ class LetitbitNet(SimpleHoster): FORM_PATTERN = r'<form%s action="([^"]+)" method="post"%s>(.*?)</form>' FORM_INPUT_PATTERN = r'<input[^>]* name="([^"]+)" value="([^"]+)" />' - JS_SCRIPT_PATTERN = r'<title>[^<]*</title>\s*<script language="JavaScript">(.*?)</script>' - JS_VARS_PATTERN = r"(\S+) = '?([^';]+)'?;" + CHECK_URL_PATTERN = r"ajax_check_url\s*=\s*'([^']+)';" + SECONDS_PATTERN = r"seconds\s*=\s*(\d+);" + FILE_INFO_PATTERN = r'<h1[^>]*>File: <a[^>]*><span>(?P<N>[^<]+)</span></a> [<span>(?P<S>[0-9.]+)\s*(?P<U>[kKMG])i?[Bb]</span>]</h1>' FILE_OFFLINE_PATTERN = r'<div id="download_content" class="hide-block">[^<]*<br>File not found<br /></div>' @@ -65,10 +66,10 @@ class LetitbitNet(SimpleHoster): self.html = self.load(action, post = inputs) try: - form = re.search(self.JS_SCRIPT_PATTERN, self.html, re.DOTALL).group(1) - js_vars = dict(re.findall(self.JS_VARS_PATTERN, form)) - ajax_check_url = js_vars['ajax_check_url'] - self.setWait(int(js_vars['seconds'])+1) + ajax_check_url = re.search(self.CHECK_URL_PATTERN, self.html).group(1) + found = re.search(self.SECONDS_PATTERN, self.html) + seconds = int(found.group(1)) if found else 60 + self.setWait(seconds+1) self.wait() except Exception, e: self.logError(e) diff --git a/module/plugins/hoster/MediafireCom.py b/module/plugins/hoster/MediafireCom.py index f014c58e8..a4c6b1d52 100644 --- a/module/plugins/hoster/MediafireCom.py +++ b/module/plugins/hoster/MediafireCom.py @@ -17,17 +17,48 @@ """ import re -from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo +from module.plugins.internal.SimpleHoster import SimpleHoster, parseFileInfo from module.plugins.ReCaptcha import ReCaptcha +from module.network.RequestFactory import getURL def replace_eval(js_expr): return js_expr.replace(r'eval("', '').replace(r"\'", r"'").replace(r'\"', r'"') +def checkHTMLHeader(url): + try: + for i in range(3): + header = getURL(url, just_header = True) + for line in header.splitlines(): + line = line.lower() + if 'location' in line: + url = line.split(':', 1)[1].strip() + if 'error.php?errno=320' in url: + return url, 1 + if not url.startswith('http://'): url = 'http://www.mediafire.com' + url + break + elif 'content-disposition' in line: + return url, 2 + else: + break + except: + return url, 3 + + return url, 0 + +def getInfo(urls): + for url in urls: + location, status = checkHTMLHeader(url) + if status: + file_info = (url, 0, status, url) + else: + file_info = parseFileInfo(MediafireCom, url, getURL(url, decode=True)) + yield file_info + class MediafireCom(SimpleHoster): __name__ = "MediafireCom" __type__ = "hoster" - __pattern__ = r"http://(?:\w*\.)*mediafire\.com/download.php\?.*" - __version__ = "0.66" + __pattern__ = r"http://(?:\w*\.)*mediafire\.com/[^?].*" + __version__ = "0.68" __description__ = """Mediafire.com plugin - free only""" __author_name__ = ("zoidberg") __author_mail__ = ("zoidberg@mujmail.cz") @@ -39,6 +70,7 @@ class MediafireCom(SimpleHoster): PAGE1_PKR_PATTERN = r"pKr='([^']+)';" RECAPTCHA_PATTERN = r'src="http://(?:api.recaptcha.net|www.google.com/recaptcha/api)/challenge\?k=([^"]+)">' PAGE1_ACTION_PATTERN = r'<link rel="canonical" href="([^"]+)"/>' + PASSWORD_PATTERN = r";break;}\s*dh\('" PAGE2_VARS_PATTERN = r'<script language="Javascript"><!--\s*(var.*?unescape.*?)eval\(' PAGE2_DZ_PATTERN = r'break;case 15:(.*)</script>' @@ -50,20 +82,37 @@ class MediafireCom(SimpleHoster): FILE_OFFLINE_PATTERN = r'class="error_msg_title"> Invalid or Deleted File. </div>' def process(self, pyfile): - self.html = self.load(pyfile.url, decode = True) - self.checkCaptcha() - self.getFileInfo() - if self.account: - self.handlePremium() - else: - self.handleFree() - + self.url, result = checkHTMLHeader(pyfile.url) + self.logDebug('Location (%d): %s' % (result, self.url)) + + if result == 0: + self.html = self.load(self.url, decode = True) + self.checkCaptcha() + self.getFileInfo() + if self.account: + self.handlePremium() + else: + self.handleFree() + elif result == 1: + self.offline() + else: + self.download(self.url, disposition = True) + def handleFree(self): + passwords = self.getPassword().split() + while re.search(self.PASSWORD_PATTERN, self.html): + if len(passwords): + password = passwords.pop(0) + self.logInfo("Password protected link, trying " + password) + self.html = self.load(self.url, post={"downloadp": password}) + else: + self.fail("No or incorrect password") + 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: + else: self.retry(3, 0, "Parse error (KEY)") try: @@ -114,7 +163,7 @@ class MediafireCom(SimpleHoster): self.logDebug("FINAL LINK: %s" % final_link) self.download(final_link) - + def checkCaptcha(self): for i in range(5): found = re.search(self.RECAPTCHA_PATTERN, self.html) @@ -126,10 +175,8 @@ class MediafireCom(SimpleHoster): self.html = self.load(captcha_action, post = { "recaptcha_challenge_field": captcha_challenge, "recaptcha_response_field": captcha_response - }) + }, decode = True) else: break else: - self.fail("No valid recaptcha solution received") - -getInfo = create_getInfo(MediafireCom)
\ No newline at end of file + self.fail("No valid recaptcha solution received")
\ No newline at end of file |