diff options
Diffstat (limited to 'pyload/plugins/hoster/NetloadIn.py')
-rw-r--r-- | pyload/plugins/hoster/NetloadIn.py | 147 |
1 files changed, 87 insertions, 60 deletions
diff --git a/pyload/plugins/hoster/NetloadIn.py b/pyload/plugins/hoster/NetloadIn.py index 07aeb48ca..0aabc8f57 100644 --- a/pyload/plugins/hoster/NetloadIn.py +++ b/pyload/plugins/hoster/NetloadIn.py @@ -2,17 +2,19 @@ import re +from urlparse import urljoin from time import sleep, time from pyload.network.RequestFactory import getURL from pyload.plugins.internal.Hoster import Hoster from pyload.plugins.Plugin import chunks +from pyload.plugins.captcha import ReCaptcha def getInfo(urls): ## returns list of tupels (name, size (in bytes), status (see FileDatabase), url) - apiurl = "http://api.netload.in/info.php?auth=Zf9SnQh9WiReEsb18akjvQGqT0I830e8&bz=1&md5=1&file_id=" + apiurl = "http://api.netload.in/info.php" id_regex = re.compile(NetloadIn.__pattern__) urls_per_query = 80 @@ -23,13 +25,18 @@ def getInfo(urls): if match: ids = ids + match.group(1) + ";" - api = getURL(apiurl + ids, decode=True) + api = getURL(apiurl, + get={'auth' : "Zf9SnQh9WiReEsb18akjvQGqT0I830e8", + 'bz' : 1, + 'md5' : 1, + 'file_id': ids}, + decode=True) if api is None or len(api) < 10: self.logDebug("Prefetch failed") return + if api.find("unknown_auth") >= 0: - print self.logDebug("Outdated auth code") return @@ -38,11 +45,14 @@ def getInfo(urls): for i, r in enumerate(api.splitlines()): try: tmp = r.split(";") + try: size = int(tmp[2]) except Exception: size = 0 - result.append((tmp[1], size, 2 if tmp[3] == "online" else 1, chunk[i])) + + result.append((tmp[1], size, 2 if tmp[3] == "online" else 1, chunk[i] )) + except Exception: self.logDebug("Error while processing response: %s" % r) @@ -52,7 +62,7 @@ def getInfo(urls): class NetloadIn(Hoster): __name__ = "NetloadIn" __type__ = "hoster" - __version__ = "0.45" + __version__ = "0.47" __pattern__ = r'https?://(?:[^/]*\.)?netload\.in/(?:datei(.*?)(?:\.htm|/)|index\.php?id=10&file_id=)' @@ -69,8 +79,11 @@ class NetloadIn(Hoster): def process(self, pyfile): self.url = pyfile.url + self.prepare() + pyfile.setStatus("downloading") + self.proceed(self.url) @@ -82,7 +95,9 @@ class NetloadIn(Hoster): if self.premium: self.logDebug("Use Premium Account") - settings = self.load("http://www.netload.in/index.php?id=2&lang=en") + + settings = self.load("http://www.netload.in/index.php", get={'id': 2, 'lang': "en"}) + if '<option value="2" selected="selected">Direkter Download' in settings: self.logDebug("Using direct download") return True @@ -97,9 +112,9 @@ class NetloadIn(Hoster): def download_api_data(self, n=0): - url = self.url + url = self.url id_regex = re.compile(self.__pattern__) - match = id_regex.search(url) + match = id_regex.search(url) if match: #normalize url @@ -119,14 +134,17 @@ class NetloadIn(Hoster): return self.logDebug("APIDATA: " + html) + self.api_data = {} + if html and ";" in html and html not in ("unknown file_data", "unknown_server_data", "No input file specified."): lines = html.split(";") - self.api_data['exists'] = True - self.api_data['fileid'] = lines[0] + self.api_data['exists'] = True + self.api_data['fileid'] = lines[0] self.api_data['filename'] = lines[1] - self.api_data['size'] = lines[2] - self.api_data['status'] = lines[3] + self.api_data['size'] = lines[2] + self.api_data['status'] = lines[3] + if self.api_data['status'] == "online": self.api_data['checksum'] = lines[4].strip() else: @@ -140,16 +158,28 @@ class NetloadIn(Hoster): def final_wait(self, page): wait_time = self.get_wait_time(page) + self.setWait(wait_time) + self.logDebug("Final wait %d seconds" % wait_time) + self.wait() + self.url = self.get_file_url(page) + def check_free_wait(self,page): + if ">An access request has been made from IP address <" in page: + self.wantReconnect = True + self.setWait(self.get_wait_time(page) or 30) + self.wait() + return True + else: + return False + + def download_html(self): - self.logDebug("Entering download_html") page = self.load(self.url, decode=True) - t = time() + 30 if "/share/templates/download_hddcrash.tpl" in page: self.logError(_("Netload HDD Crash")) @@ -169,8 +199,8 @@ class NetloadIn(Hoster): self.pyfile.name = name captchawaited = False - for i in xrange(10): + for i in xrange(5): if not page: page = self.load(self.url) t = time() + 30 @@ -185,51 +215,49 @@ class NetloadIn(Hoster): self.logDebug("We will prepare your download") self.final_wait(page) return True - if ">An access request has been made from IP address <" in page: - wait = self.get_wait_time(page) - if not wait: - self.logDebug("Wait was 0 setting 30") - wait = 30 * 60 - self.logInfo(_("Waiting between downloads %d seconds") % wait) - self.setWait(wait, True) - self.wait() - - return self.download_html() self.logDebug("Trying to find captcha") try: - url_captcha_html = "http://netload.in/" + re.search('(index.php\?id=10&.*&captcha=1)', - page).group(1).replace("amp;", "") - except Exception: + url_captcha_html = re.search(r'(index.php\?id=10&.*&captcha=1)', page).group(1).replace("amp;", "") + + except Exception, e: + self.logDebug("Exception during Captcha regex: %s" % e.message) page = None - continue - try: - page = self.load(url_captcha_html, cookies=True) - captcha_url = "http://netload.in/" + re.search('(share/includes/captcha.php\?t=\d*)', page).group(1) - except Exception: - self.logDebug("Could not find captcha, try again from beginning") - captchawaited = False - continue - - file_id = re.search('<input name="file_id" type="hidden" value="(.*)" />', page).group(1) - if not captchawaited: - wait = self.get_wait_time(page) - if i == 0: - self.pyfile.waitUntil = time() # dont wait contrary to time on website - else: - self.pyfile.waitUntil = t - self.logInfo(_("Waiting for captcha %d seconds") % (self.pyfile.waitUntil - time())) - #self.setWait(wait) - self.wait() - captchawaited = True + else: + url_captcha_html = urljoin("http://netload.in/", url_captcha_html) + break + + self.html = self.load(url_captcha_html) - captcha = self.decryptCaptcha(captcha_url) - page = self.load("http://netload.in/index.php?id=10", post={"file_id": file_id, "captcha_check": captcha}, - cookies=True) + recaptcha = ReCaptcha(self) - return False + for _i in xrange(5): + challenge, response = recaptcha.challenge() + + response_page = self.load("http://www.netload.in/index.php?id=10", + post={'captcha_check' : '1', + 'recaptcha_challenge_field': challenge, + 'recaptcha_response_field' : response, + 'file_id' : self.api_data['fileid'], + 'Download_Next' : ''}) + if "Orange_Link" in response_page: + break + + if self.check_free_wait(response_page): + self.logDebug("Had to wait for next free slot, trying again") + return self.download_html() + + else: + download_url = self.get_file_url(response_page) + self.logDebug("Download URL after get_file: " + download_url) + if not download_url.startswith("http://"): + self.error("download url: %s" % download_url) + self.wait() + + self.url = download_url + return True def get_file_url(self, page): @@ -243,25 +271,24 @@ class NetloadIn(Hoster): file_url_pattern = r'<a href="(.+)" class="Orange_Link">Click here' attempt = re.search(file_url_pattern, page) return "http://netload.in/" + attempt.group(1) - except Exception: - self.logDebug("Getting final link failed") + + except Exception, e: + self.logDebug("Getting final link failed", e.message) return None def get_wait_time(self, page): - wait_seconds = int(re.search(r"countdown\((.+),'change\(\)'\)", page).group(1)) / 100 - return wait_seconds + return int(re.search(r"countdown\((.+),'change\(\)'\)", page).group(1)) / 100 def proceed(self, url): - self.logDebug("Downloading..") - self.download(url, disposition=True) - check = self.checkDownload({"empty": re.compile(r"^$"), "offline": re.compile("The file was deleted")}) - + check = self.checkDownload({'empty' : re.compile(r'^$'), + 'offline': re.compile("The file was deleted")}) if check == "empty": self.logInfo(_("Downloaded File was empty")) self.retry() + elif check == "offline": self.offline() |