# -*- coding: utf-8 -*- import re from time import time from traceback import print_exc from urlparse import urlparse from module.network.CookieJar import CookieJar from module.network.RequestFactory import getURL from module.plugins.Hoster import Hoster from module.plugins.Plugin import Fail from module.utils import fixup, html_unescape, parseFileSize #@TODO: Remove in 0.4.10 and redirect to self.error instead def _error(self, reason="", type=""): if not reason and not type: type = "unknown" msg = _("%s error") % type.strip().capitalize() if type else _("Error") msg += ": " + reason.strip() if reason else "" msg += _(" | Plugin may be out of date") if self.core.debug: print_exc() raise Fail(msg) def replace_patterns(string, ruleslist): for r in ruleslist: rf, rt = r string = re.sub(rf, rt, string) return string def set_cookies(cj, cookies): for cookie in cookies: if isinstance(cookie, tuple) and len(cookie) == 3: domain, name, value = cookie cj.setCookie(domain, name, value) def parseHtmlTagAttrValue(attr_name, tag): m = re.search(r"%s\s*=\s*([\"']?)((?<=\")[^\"]+|(?<=')[^']+|[^>\s\"'][^>\s]*)\1" % attr_name, tag, re.I) return m.group(2) if m else None def parseHtmlForm(attr_str, html, input_names=None): for form in re.finditer(r"(?P]*%s[^>]*>)(?P.*?)]*>" % attr_str, html, re.S | re.I): inputs = {} action = parseHtmlTagAttrValue("action", form.group('tag')) for inputtag in re.finditer(r'(<(input|textarea)[^>]*>)([^<]*(?=file_name) (?Pfile_size) (?Psize_unit)' or FILE_NAME_PATTERN: (optional) Name that will be set for the file example: FILE_NAME_PATTERN = r'(?Pfile_name)' FILE_SIZE_PATTERN: (optional) Size that will be checked for the file example: FILE_SIZE_PATTERN = r'(?Pfile_size) (?Psize_unit)' OFFLINE_PATTERN: (optional) Checks if the file is yet available online example: OFFLINE_PATTERN = r'File (deleted|not found)' TEMP_OFFLINE_PATTERN: (optional) Checks if the file is temporarily offline example: TEMP_OFFLINE_PATTERN = r'Server (maintenance|maintainance)' PREMIUM_ONLY_PATTERN: (optional) Checks if the file can be downloaded only with a premium account example: PREMIUM_ONLY_PATTERN = r'Premium account required' Instead overriding handleFree and handlePremium methods now you can define patterns for direct download: LINK_FREE_PATTERN: (optional) group(1) should be the direct link for free download example: LINK_FREE_PATTERN = r'