Repository navigation
Expand file tree
/
Copy pathDatafileCom.py
More file actions
90 lines (64 loc) · 3.4 KB
/
Copy pathDatafileCom.py
File metadata and controls
90 lines (64 loc) · 3.4 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
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
import re
from module.plugins.internal.misc import json, seconds_to_midnight
from module.plugins.captcha.ReCaptcha import ReCaptcha
from module.plugins.internal.SimpleHoster import SimpleHoster
class DatafileCom(SimpleHoster):
__name__ = "DatafileCom"
__type__ = "hoster"
__version__ = "0.02"
__status__ = "testing"
__pattern__ = r'https?://(?:www\.)?datafile\.com/d/(?P<ID>\w{17})'
__config__ = [("activated" , "bool", "Activated" , True),
("use_premium" , "bool", "Use premium account if available" , True),
("fallback" , "bool", "Fallback to free download if premium fails" , True),
("chk_filesize", "bool", "Check file size" , True),
("max_wait" , "int" , "Reconnect if waiting time is greater than minutes", 10 )]
__description__ = """Datafile.com hoster plugin"""
__license__ = "GPLv3"
__authors__ = [("GammaC0de", "nitzo2001[AT]yahoo[DOT]com")]
NAME_PATTERN = r'<div class="file-name">(?P<N>.+?)</div>'
SIZE_PATTERN = r'>Filesize: <span class="lime">(?P<S>[\d.,]+) (?P<U>[\w^_]+)'
OFFLINE_PATTERN = r'Invalid Link|Link Expired|This file was deleted'
TEMP_OFFLINE_PATTERN = r'You are downloading another file at this moment'
PREMIUM_ONLY_PATTERN = r'This file is only available for premium users'
DIRECT_LINK = False
DISPOSITION = False
def handle_free(self, pyfile):
m = re.search(r'<span class="time">([\d:]+)<', self.data)
if m:
wait_time = sum(int(_d) * 60 ** _i for _i, _d in enumerate(reversed(m.group(1).split(':'))))
else:
wait_time = 0
self.captcha = ReCaptcha(pyfile)
captcha_key = self.captcha.detect_key()
if captcha_key:
response, challenge = self.captcha.challenge(captcha_key)
post_data = {'doaction' : "validateCaptcha",
'recaptcha_challenge_field': challenge,
'recaptcha_response_field' : response,
'fileid' : self.info['pattern']['ID']}
catcha_result = json.loads(self.load("http://www.datafile.com/files/ajax.html", post=post_data))
if not catcha_result['success']:
self.retry_captcha()
self.captcha.correct()
self.wait(wait_time)
post_data['doaction'] = "getFileDownloadLink"
post_data['token'] = catcha_result['token']
file_info = json.loads(self.load("http://www.datafile.com/files/ajax.html", post=post_data))
if file_info['success']:
self.link = file_info['link']
self.log_debug("URL:%s" % file_info['link'])
else:
m = re.search(r'error\.html\?code=(\d+)', self.req.lastEffectiveURL)
if m:
error_code = int(m.group(1))
if error_code in (2, 3):
self.offline()
elif error_code == 7:
wait_time = seconds_to_midnight()
self.retry(wait=wait_time, msg=_("Download limit exceeded"))
elif error_code == 9:
self.temp_offline()
else:
self.log_debug("Unknown error code %s" % error_code)