diff options
-rw-r--r-- | module/plugins/accounts/DdlstorageCom.py | 44 | ||||
-rw-r--r-- | module/plugins/hooks/Checksum.py | 16 | ||||
-rw-r--r-- | module/plugins/hoster/DdlstorageCom.py | 73 |
3 files changed, 125 insertions, 8 deletions
diff --git a/module/plugins/accounts/DdlstorageCom.py b/module/plugins/accounts/DdlstorageCom.py index 6c610aa84..7404348a4 100644 --- a/module/plugins/accounts/DdlstorageCom.py +++ b/module/plugins/accounts/DdlstorageCom.py @@ -1,13 +1,51 @@ # -*- coding: utf-8 -*- +from hashlib import md5 +from time import mktime, strptime + from module.plugins.internal.XFSPAccount import XFSPAccount +from module.common.json_layer import json_loads +from module.utils import parseFileSize + +# DDLStorage API Documentation: +# http://www.ddlstorage.com/cgi-bin/api_req.cgi?req_type=doc class DdlstorageCom(XFSPAccount): __name__ = "DdlstorageCom" - __version__ = "0.01" + __version__ = "1.00" __type__ = "account" __description__ = """DDLStorage.com account plugin""" - __author_name__ = ("zoidberg") - __author_mail__ = ("zoidberg@mujmail.cz") + __author_name__ = ("stickell") + __author_mail__ = ("l.stickell@yahoo.it") MAIN_PAGE = "http://ddlstorage.com/" + + def loadAccountInfo(self, user, req): + password = self.accounts[user]['password'] + api_data = req.load('http://www.ddlstorage.com/cgi-bin/api_req.cgi', + post={'req_type': 'user_info', + 'client_id': 53472, + 'user_login': user, + 'user_password': md5(password).hexdigest(), + 'sign': md5('user_info%d%s%s%s' % (53472, user, md5(password).hexdigest(), + '25JcpU2dPOKg8E2OEoRqMSRu068r0Cv3')).hexdigest()}) + api_data = api_data.replace('<pre>', '').replace('</pre>', '') + self.logDebug('Account Info API data: ' + api_data) + api_data = json_loads(api_data) + + if api_data['status'] != 'OK': # 'status' must be always OK for a working account + return {"premium": False, "valid": False} + + if api_data['account_type'] == 'REGISTERED': + premium = False + validuntil = None + else: + premium = True + validuntil = int(mktime(strptime(api_data['premium_expire'], "%Y-%m-%d %H:%M:%S"))) + + if api_data['usr_bandwidth_available'] == 'UNLIMITED': + trafficleft = -1 + else: + trafficleft = parseFileSize(api_data['usr_bandwidth_available']) / 1024 + + return {"premium": premium, "validuntil": validuntil, "trafficleft": trafficleft} diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index 08fd623b8..908286677 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -22,6 +22,7 @@ import zlib from os import remove from os.path import getsize, isfile, splitext import re +import base64 from module.utils import save_join, fs_encode from module.plugins.Hook import Hook @@ -48,13 +49,25 @@ def computeChecksum(local_file, algorithm): return "%x" % last + # Special Hash used by DDLStorage.com + # It compute the MD5 hash only on the first and the last 4096 bytes, then the hash is base64 encoded + elif algorithm == 'md5_ddlstorage': + h = hashlib.md5() + + with open(local_file, 'rb') as f: + h.update(f.read(4096)) + f.seek(-4096, 2) + h.update(f.read(4096)) + + return base64.b64encode(h.digest()).rstrip('=') + else: return None class Checksum(Hook): __name__ = "Checksum" - __version__ = "0.08" + __version__ = "0.09" __description__ = "Verify downloaded file size and checksum (enable in general preferences)" __config__ = [("activated", "bool", "Activated", True), ("action", "fail;retry;nothing", "What to do if check fails?", "retry"), @@ -75,6 +88,7 @@ class Checksum(Hook): self.algorithms = sorted( getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")), reverse=True) self.algorithms.extend(["crc32", "adler32"]) + self.algorithms.append('md5_ddlstorage') self.formats = self.algorithms + ['sfv', 'crc', 'hash'] def downloadFinished(self, pyfile): diff --git a/module/plugins/hoster/DdlstorageCom.py b/module/plugins/hoster/DdlstorageCom.py index 5eaebf1d1..82072aadb 100644 --- a/module/plugins/hoster/DdlstorageCom.py +++ b/module/plugins/hoster/DdlstorageCom.py @@ -1,13 +1,45 @@ # -*- coding: utf-8 -*- +import re +from hashlib import md5 -from module.plugins.hoster.XFileSharingPro import XFileSharingPro, create_getInfo +from module.plugins.hoster.XFileSharingPro import XFileSharingPro +from module.network.RequestFactory import getURL +from module.plugins.Plugin import chunks +from module.common.json_layer import json_loads + + +def getInfo(urls): + # DDLStorage API Documentation: + # http://www.ddlstorage.com/cgi-bin/api_req.cgi?req_type=doc + ids = dict() + for url in urls: + m = re.search(DdlstorageCom.__pattern__, url) + ids[m.group('ID')] = url + + for chunk in chunks(ids.keys(), 5): + api = getURL('http://www.ddlstorage.com/cgi-bin/api_req.cgi', + post={'req_type': 'file_info_free', + 'client_id': 53472, + 'file_code': ','.join(chunk), + 'sign': md5('file_info_free%d%s%s' % (53472, ','.join(chunk), + '25JcpU2dPOKg8E2OEoRqMSRu068r0Cv3')).hexdigest()}) + api = api.replace('<pre>', '').replace('</pre>', '') + api = json_loads(api) + + result = list() + for el in api: + if el['status'] == 'online': + result.append((el['file_name'], int(el['file_size']), 2, ids[el['file_code']])) + else: + result.append((ids[el['file_code']], 0, 1, ids[el['file_code']])) + yield result class DdlstorageCom(XFileSharingPro): __name__ = "DdlstorageCom" __type__ = "hoster" - __pattern__ = r"http://(?:\w*\.)*?ddlstorage.com/\w{12}" - __version__ = "0.07" + __pattern__ = r"http://(?:\w*\.)*?ddlstorage.com/(?P<ID>\w{12})" + __version__ = "1.00" __description__ = """DDLStorage.com hoster plugin""" __author_name__ = ("zoidberg", "stickell") __author_mail__ = ("zoidberg@mujmail.cz", "l.stickell@yahoo.it") @@ -15,5 +47,38 @@ class DdlstorageCom(XFileSharingPro): FILE_INFO_PATTERN = r'<p class="sub_title"[^>]*>(?P<N>.+) \((?P<S>[^)]+)\)</p>' HOSTER_NAME = "ddlstorage.com" + def prepare(self): + self.getAPIData() + super(DdlstorageCom, self).prepare() + + def getAPIData(self): + file_id = re.search(self.__pattern__, self.pyfile.url).group('ID') + data = {'client_id': 53472, + 'file_code': file_id} + if self.user: + passwd = self.account.getAccountData(self.user)["password"] + data['req_type'] = 'file_info_reg' + data['user_login'] = self.user + data['user_password'] = md5(passwd).hexdigest() + data['sign'] = md5('file_info_reg%d%s%s%s%s' % (data['client_id'], data['user_login'], + data['user_password'], data['file_code'], + '25JcpU2dPOKg8E2OEoRqMSRu068r0Cv3')).hexdigest() + else: + data['req_type'] = 'file_info_free' + data['sign'] = md5('file_info_free%d%s%s' % (data['client_id'], data['file_code'], + '25JcpU2dPOKg8E2OEoRqMSRu068r0Cv3')).hexdigest() + + self.api_data = self.load('http://www.ddlstorage.com/cgi-bin/api_req.cgi', post=data) + self.api_data = self.api_data.replace('<pre>', '').replace('</pre>', '') + self.logDebug('API Data: ' + self.api_data) + self.api_data = json_loads(self.api_data)[0] + + if self.api_data['status'] == 'offline': + self.offline() -getInfo = create_getInfo(DdlstorageCom)
\ No newline at end of file + if 'file_name' in self.api_data: + self.pyfile.name = self.api_data['file_name'] + if 'file_size' in self.api_data: + self.pyfile.size = self.api_data['size'] = self.api_data['file_size'] + if 'file_md5_base64' in self.api_data: + self.api_data['md5_ddlstorage'] = self.api_data['file_md5_base64'] |