Skip to content

Commit 250b64d

Browse files
committed
DDLStorage: rewritten to use API.
(cherry picked from commit b2e7352)
1 parent 3cbe096 commit 250b64d

3 files changed

Lines changed: 125 additions & 8 deletions

File tree

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,51 @@
11
# -*- coding: utf-8 -*-
2+
from hashlib import md5
3+
from time import mktime, strptime
4+
25
from module.plugins.internal.XFSPAccount import XFSPAccount
6+
from module.common.json_layer import json_loads
7+
from module.utils import parseFileSize
8+
9+
# DDLStorage API Documentation:
10+
# http://www.ddlstorage.com/cgi-bin/api_req.cgi?req_type=doc
311

412

513
class DdlstorageCom(XFSPAccount):
614
__name__ = "DdlstorageCom"
7-
__version__ = "0.01"
15+
__version__ = "1.00"
816
__type__ = "account"
917
__description__ = """DDLStorage.com account plugin"""
10-
__author_name__ = ("zoidberg")
11-
__author_mail__ = ("zoidberg@mujmail.cz")
18+
__author_name__ = ("stickell")
19+
__author_mail__ = ("l.stickell@yahoo.it")
1220

1321
MAIN_PAGE = "http://ddlstorage.com/"
22+
23+
def loadAccountInfo(self, user, req):
24+
password = self.accounts[user]['password']
25+
api_data = req.load('http://www.ddlstorage.com/cgi-bin/api_req.cgi',
26+
post={'req_type': 'user_info',
27+
'client_id': 53472,
28+
'user_login': user,
29+
'user_password': md5(password).hexdigest(),
30+
'sign': md5('user_info%d%s%s%s' % (53472, user, md5(password).hexdigest(),
31+
'25JcpU2dPOKg8E2OEoRqMSRu068r0Cv3')).hexdigest()})
32+
api_data = api_data.replace('<pre>', '').replace('</pre>', '')
33+
self.logDebug('Account Info API data: ' + api_data)
34+
api_data = json_loads(api_data)
35+
36+
if api_data['status'] != 'OK': # 'status' must be always OK for a working account
37+
return {"premium": False, "valid": False}
38+
39+
if api_data['account_type'] == 'REGISTERED':
40+
premium = False
41+
validuntil = None
42+
else:
43+
premium = True
44+
validuntil = int(mktime(strptime(api_data['premium_expire'], "%Y-%m-%d %H:%M:%S")))
45+
46+
if api_data['usr_bandwidth_available'] == 'UNLIMITED':
47+
trafficleft = -1
48+
else:
49+
trafficleft = parseFileSize(api_data['usr_bandwidth_available']) / 1024
50+
51+
return {"premium": premium, "validuntil": validuntil, "trafficleft": trafficleft}

pyload/plugins/addons/Checksum.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from os import remove
2323
from os.path import getsize, isfile, splitext
2424
import re
25+
import base64
2526

2627
from module.utils import save_join, fs_encode
2728
from module.plugins.Hook import Hook
@@ -48,13 +49,25 @@ def computeChecksum(local_file, algorithm):
4849

4950
return "%x" % last
5051

52+
# Special Hash used by DDLStorage.com
53+
# It compute the MD5 hash only on the first and the last 4096 bytes, then the hash is base64 encoded
54+
elif algorithm == 'md5_ddlstorage':
55+
h = hashlib.md5()
56+
57+
with open(local_file, 'rb') as f:
58+
h.update(f.read(4096))
59+
f.seek(-4096, 2)
60+
h.update(f.read(4096))
61+
62+
return base64.b64encode(h.digest()).rstrip('=')
63+
5164
else:
5265
return None
5366

5467

5568
class Checksum(Hook):
5669
__name__ = "Checksum"
57-
__version__ = "0.08"
70+
__version__ = "0.09"
5871
__description__ = "Verify downloaded file size and checksum (enable in general preferences)"
5972
__config__ = [("activated", "bool", "Activated", True),
6073
("action", "fail;retry;nothing", "What to do if check fails?", "retry"),
@@ -75,6 +88,7 @@ def setup(self):
7588
self.algorithms = sorted(
7689
getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")), reverse=True)
7790
self.algorithms.extend(["crc32", "adler32"])
91+
self.algorithms.append('md5_ddlstorage')
7892
self.formats = self.algorithms + ['sfv', 'crc', 'hash']
7993

8094
def downloadFinished(self, pyfile):
Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,84 @@
11
# -*- coding: utf-8 -*-
2+
import re
3+
from hashlib import md5
24

3-
from module.plugins.hoster.XFileSharingPro import XFileSharingPro, create_getInfo
5+
from module.plugins.hoster.XFileSharingPro import XFileSharingPro
6+
from module.network.RequestFactory import getURL
7+
from module.plugins.Plugin import chunks
8+
from module.common.json_layer import json_loads
9+
10+
11+
def getInfo(urls):
12+
# DDLStorage API Documentation:
13+
# http://www.ddlstorage.com/cgi-bin/api_req.cgi?req_type=doc
14+
ids = dict()
15+
for url in urls:
16+
m = re.search(DdlstorageCom.__pattern__, url)
17+
ids[m.group('ID')] = url
18+
19+
for chunk in chunks(ids.keys(), 5):
20+
api = getURL('http://www.ddlstorage.com/cgi-bin/api_req.cgi',
21+
post={'req_type': 'file_info_free',
22+
'client_id': 53472,
23+
'file_code': ','.join(chunk),
24+
'sign': md5('file_info_free%d%s%s' % (53472, ','.join(chunk),
25+
'25JcpU2dPOKg8E2OEoRqMSRu068r0Cv3')).hexdigest()})
26+
api = api.replace('<pre>', '').replace('</pre>', '')
27+
api = json_loads(api)
28+
29+
result = list()
30+
for el in api:
31+
if el['status'] == 'online':
32+
result.append((el['file_name'], int(el['file_size']), 2, ids[el['file_code']]))
33+
else:
34+
result.append((ids[el['file_code']], 0, 1, ids[el['file_code']]))
35+
yield result
436

537

638
class DdlstorageCom(XFileSharingPro):
739
__name__ = "DdlstorageCom"
840
__type__ = "hoster"
9-
__pattern__ = r"http://(?:\w*\.)*?ddlstorage.com/\w{12}"
10-
__version__ = "0.07"
41+
__pattern__ = r"http://(?:\w*\.)*?ddlstorage.com/(?P<ID>\w{12})"
42+
__version__ = "1.00"
1143
__description__ = """DDLStorage.com hoster plugin"""
1244
__author_name__ = ("zoidberg", "stickell")
1345
__author_mail__ = ("zoidberg@mujmail.cz", "l.stickell@yahoo.it")
1446

1547
FILE_INFO_PATTERN = r'<p class="sub_title"[^>]*>(?P<N>.+) \((?P<S>[^)]+)\)</p>'
1648
HOSTER_NAME = "ddlstorage.com"
1749

50+
def prepare(self):
51+
self.getAPIData()
52+
super(DdlstorageCom, self).prepare()
53+
54+
def getAPIData(self):
55+
file_id = re.search(self.__pattern__, self.pyfile.url).group('ID')
56+
data = {'client_id': 53472,
57+
'file_code': file_id}
58+
if self.user:
59+
passwd = self.account.getAccountData(self.user)["password"]
60+
data['req_type'] = 'file_info_reg'
61+
data['user_login'] = self.user
62+
data['user_password'] = md5(passwd).hexdigest()
63+
data['sign'] = md5('file_info_reg%d%s%s%s%s' % (data['client_id'], data['user_login'],
64+
data['user_password'], data['file_code'],
65+
'25JcpU2dPOKg8E2OEoRqMSRu068r0Cv3')).hexdigest()
66+
else:
67+
data['req_type'] = 'file_info_free'
68+
data['sign'] = md5('file_info_free%d%s%s' % (data['client_id'], data['file_code'],
69+
'25JcpU2dPOKg8E2OEoRqMSRu068r0Cv3')).hexdigest()
70+
71+
self.api_data = self.load('http://www.ddlstorage.com/cgi-bin/api_req.cgi', post=data)
72+
self.api_data = self.api_data.replace('<pre>', '').replace('</pre>', '')
73+
self.logDebug('API Data: ' + self.api_data)
74+
self.api_data = json_loads(self.api_data)[0]
75+
76+
if self.api_data['status'] == 'offline':
77+
self.offline()
1878

19-
getInfo = create_getInfo(DdlstorageCom)
79+
if 'file_name' in self.api_data:
80+
self.pyfile.name = self.api_data['file_name']
81+
if 'file_size' in self.api_data:
82+
self.pyfile.size = self.api_data['size'] = self.api_data['file_size']
83+
if 'file_md5_base64' in self.api_data:
84+
self.api_data['md5_ddlstorage'] = self.api_data['file_md5_base64']

0 commit comments

Comments
 (0)