Repository navigation
Expand file tree
/
Copy pathHttp.py
More file actions
80 lines (57 loc) · 2.3 KB
/
Copy pathHttp.py
File metadata and controls
80 lines (57 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
import re
import urlparse
from module.plugins.internal.Hoster import Hoster
class Http(Hoster):
__name__ = "Http"
__type__ = "hoster"
__version__ = "0.07"
__status__ = "testing"
__pattern__ = r'(?:jd|pys?)://.+'
__config__ = [("activated", "bool", "Activated", True)]
__description__ = """Download simple http link"""
__license__ = "GPLv3"
__authors__ = [("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
for _i in xrange(2):
self.download(url, ref=False, disposition=True)
if self.req.code in (404, 410):
self.offline()
elif self.req.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:
break
self.check_download()
def check_download(self):
errmsg = self.scan_download({
'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)