diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-10-18 17:09:40 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-10-18 17:09:40 +0200 |
commit | 475c9ac64168438e89200261637cde4f97e10875 (patch) | |
tree | c8519a229f06deef192a61749157cca667494a27 | |
parent | Collect plugin utilities in a own file (diff) | |
download | pyload-475c9ac64168438e89200261637cde4f97e10875.tar.xz |
New plugin: Http
-rw-r--r-- | module/plugins/hoster/Http.py | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/module/plugins/hoster/Http.py b/module/plugins/hoster/Http.py new file mode 100644 index 000000000..d2ff2d2b9 --- /dev/null +++ b/module/plugins/hoster/Http.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- + +import re +import urlparse + +from module.network.HTTPRequest import BadHeader +from module.plugins.internal.SimpleHoster import create_getInfo +from module.plugins.internal.Hoster import Hoster + + +class Http(Hoster): + __name__ = "Http" + __type__ = "hoster" + __version__ = "0.01" + __status__ = "testing" + + __pattern__ = r'(?:jd|pys?)://.+' + __config__ = [("activated", "bool", "Activated", True)] + + __description__ = """Download from http link""" + __license__ = "GPLv3" + __authors__ = [("RaNaN", "RaNaN@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com")] + + + def setup(self): + self.chunk_limit = -1 + self.resume_download = True + + + def process(self, pyfile): + url = re.sub(r'^(jd|py)', "http", pyfile.url) + netloc = urlparse.urlparse(url).netloc + + link = self.is_download(url) + + if not link: + return + + for _i in xrange(2): + try: + self.download(link, ref=False, disposition=True) + + except BadHeader, e: + if e.code in (404, 410): + self.offline() + + elif e.code in (401, 403): + self.log_debug("Auth required", "Received HTTP status code: %d" % e.code) + + #@TODO: Recheck in 0.4.10 + if self.account: + servers = [x['login'] for x in self.account.getAllAccounts()] + else: + servers = [] + + if netloc in servers: + self.log_debug("Logging on to %s" % netloc) + self.req.addAuth(self.account.get_login('password')) + + else: + pwd = self.get_password() + if ':' in pwd: + self.req.addAuth(pwd) + else: + self.fail(_("Authorization required")) + else: + self.fail(e) + + else: + break + + self.check_download() + + + def check_download(self): + errmsg = self.check_file({'Html error' : re.compile(r'\A(?:\s*<.+>)?((?:[\w\s]*(?:[Ee]rror|ERROR)\s*\:?)?\s*\d{3})(?:\Z|\s+)'), + 'Html file' : re.compile(r'\A\s*<!DOCTYPE html'), + 'Request error': re.compile(r'([Aa]n error occured while processing your request)')}) + if not errmsg: + return + + try: + errmsg += " | " + self.last_check.group(1).strip() + + except Exception: + pass + + self.log_warning(_("Check result: ") + errmsg, _("Waiting 1 minute and retry")) + self.retry(3, 60, errmsg) + + +getInfo = create_getInfo(Http) |