# -*- coding: utf-8 -*- import re import time from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo class MegasharesCom(SimpleHoster): __name__ = "MegasharesCom" __type__ = "hoster" __version__ = "0.35" __status__ = "testing" __pattern__ = r'http://(?:www\.)?(d\d{2}\.)?megashares\.com/((index\.php)?\?d\d{2}=|dl/)\w+' __config__ = [("activated" , "bool", "Activated" , True), ("use_premium", "bool", "Use premium account if available", True)] __description__ = """Megashares.com hoster plugin""" __license__ = "GPLv3" __authors__ = [("zoidberg", "zoidberg@mujmail.cz"), ("Walter Purcaro", "vuolter@gmail.com")] NAME_PATTERN = r'

]*title="(?P.+?)">' SIZE_PATTERN = r'Filesize: (?P[\d.,]+) (?P[\w^_]+)' OFFLINE_PATTERN = r'
(Invalid Link Request|Link has been deleted|Invalid link)' LINK_PATTERN = r'
All download slots for this link are currently filled' def setup(self): self.resume_download = True self.multiDL = self.premium def handle_premium(self, pyfile): self.handle_download(True) def handle_free(self, pyfile): if self.NO_SLOTS_PATTERN in self.data: self.retry(wait=5 * 60) m = re.search(self.REACTIVATE_PASSPORT_PATTERN, self.data) if m is not None: passport_num = m.group(1) request_uri = re.search(self.REQUEST_URI_PATTERN, self.data).group(1) random_num = re.search(self.REACTIVATE_NUM_PATTERN, self.data).group(1) verifyinput = self.captcha.decrypt("http://d01.megashares.com/index.php", get={'secgfx': "gfx", 'random_num': random_num}) self.log_info(_("Reactivating passport %s: %s %s") % (passport_num, random_num, verifyinput)) res = self.load("http://d01.megashares.com%s" % request_uri, get={'rs' : "check_passport_renewal", 'rsargs[]': verifyinput, 'rsargs[]': random_num, 'rsargs[]': passport_num, 'rsargs[]': "replace_sec_pprenewal", 'rsrnd[]' : str(int(time.time() * 1000))}) if 'Thank you for reactivating your passport' in res: self.captcha.correct() self.restart() else: self.retry_captcha(msg=_("Failed to reactivate passport")) m = re.search(self.PASSPORT_RENEW_PATTERN, self.data) if m is not None: time = [int(x) for x in m.groups()] renew = time[0] + (time[1] * 60) + (time[2] * 60) self.log_debug("Waiting %d seconds for a new passport" % renew) self.retry(wait=renew, msg=_("Passport renewal")) #: Check traffic left on passport m = re.search(self.PASSPORT_LEFT_PATTERN, self.data, re.M | re.S) if m is None: self.fail(_("Passport not found")) self.log_info(_("Download passport: %s") % m.group(1)) data_left = float(m.group(2)) * 1024 ** {'B': 0, 'KB': 1, 'MB': 2, 'GB': 3}[m.group(3)] self.log_info(_("Data left: %s %s (%d MB needed)") % (m.group(2), m.group(3), self.pyfile.size / 1048576)) if not data_left: self.retry(wait=600, msg=_("Passport renewal")) self.handle_download(False) def handle_download(self, premium=False): m = re.search(self.LINK_PATTERN % (1 if premium else 2), self.data) msg = _('%s download URL' % ('Premium' if premium else 'Free')) if m is None: self.error(msg) self.link = m.group(1) self.log_debug("%s: %s" % (msg, self.link)) getInfo = create_getInfo(MegasharesCom)