diff options
Diffstat (limited to 'pyload/plugins/internal')
| -rw-r--r-- | pyload/plugins/internal/AbstractExtractor.py | 8 | ||||
| -rw-r--r-- | pyload/plugins/internal/SimpleCrypter.py | 1 | ||||
| -rw-r--r-- | pyload/plugins/internal/SimpleHoster.py | 80 | ||||
| -rw-r--r-- | pyload/plugins/internal/UnRar.py | 9 | 
4 files changed, 65 insertions, 33 deletions
| diff --git a/pyload/plugins/internal/AbstractExtractor.py b/pyload/plugins/internal/AbstractExtractor.py index 3cd635eff..3ce76b6fa 100644 --- a/pyload/plugins/internal/AbstractExtractor.py +++ b/pyload/plugins/internal/AbstractExtractor.py @@ -11,6 +11,9 @@ class WrongPassword(Exception):      pass  class AbtractExtractor: + +    __version__ = "0.1" +      @staticmethod      def checkDeps():          """ Check if system satisfies dependencies @@ -27,7 +30,7 @@ class AbtractExtractor:          raise NotImplementedError -    def __init__(self, m, file, out, fullpath, overwrite, renice): +    def __init__(self, m, file, out, fullpath, overwrite, excludefiles, renice):          """Initialize extractor for specific file          :param m: ExtractArchive addon plugin @@ -42,6 +45,7 @@ class AbtractExtractor:          self.out = out          self.fullpath = fullpath          self.overwrite = overwrite +        self.excludefiles = excludefiles          self.renice = renice          self.files = [] # Store extracted files here @@ -90,4 +94,4 @@ class AbtractExtractor:      def getExtractedFiles(self):          """Populate self.files at some point while extracting""" -        return self.files
\ No newline at end of file +        return self.files diff --git a/pyload/plugins/internal/SimpleCrypter.py b/pyload/plugins/internal/SimpleCrypter.py index e26bf6644..d8132f4b3 100644 --- a/pyload/plugins/internal/SimpleCrypter.py +++ b/pyload/plugins/internal/SimpleCrypter.py @@ -22,6 +22,7 @@ import re  from pyload.plugins.Crypter import Crypter, Package  from pyload.utils import html_unescape +  class SimpleCrypter(Crypter):      __name__ = "SimpleCrypter"      __version__ = "0.06" diff --git a/pyload/plugins/internal/SimpleHoster.py b/pyload/plugins/internal/SimpleHoster.py index 745cbfd8f..856d3fde6 100644 --- a/pyload/plugins/internal/SimpleHoster.py +++ b/pyload/plugins/internal/SimpleHoster.py @@ -25,6 +25,7 @@ from module.utils import html_unescape, fixup, parseFileSize  from module.network.RequestFactory import getURL  from module.network.CookieJar import CookieJar +  def replace_patterns(string, ruleslist):      for r in ruleslist:          rf, rt = r @@ -32,18 +33,22 @@ def replace_patterns(string, ruleslist):          #self.logDebug(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 +    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<tag><form[^>]*%s[^>]*>)(?P<content>.*?)</?(form|body|html)[^>]*>" % attr_str, html, re.S | re.I): +    for form in re.finditer(r"(?P<tag><form[^>]*%s[^>]*>)(?P<content>.*?)</?(form|body|html)[^>]*>" % attr_str, +                            html, re.S | re.I):          inputs = {}          action = parseHtmlTagAttrValue("action", form.group('tag'))          for inputtag in re.finditer(r'(<(input|textarea)[^>]*>)([^<]*(?=</\2)|)', form.group('content'), re.S | re.I): @@ -65,19 +70,20 @@ def parseHtmlForm(attr_str, html, input_names=None):                          continue                      elif hasattr(val, "search") and re.match(val, inputs[key]):                          continue -                    break # attibute value does not match +                    break  # attibute value does not match                  else: -                    break # attibute name does not match +                    break  # attibute name does not match              else: -                return action, inputs # passed attribute check +                return action, inputs  # passed attribute check          else:              # no attribute check              return action, inputs -    return {}, None # no matching form found +    return {}, None  # no matching form found + -def parseFileInfo(self, url = '', html = ''): -    info = {"name" : url, "size" : 0, "status" : 3} +def parseFileInfo(self, url='', html=''): +    info = {"name": url, "size": 0, "status": 3}      if hasattr(self, "pyfile"):          url = self.pyfile.url @@ -85,10 +91,12 @@ def parseFileInfo(self, url = '', html = ''):      if hasattr(self, "req") and self.req.http.code == '404':          info['status'] = 1      else: -        if not html and hasattr(self, "html"): html = self.html +        if not html and hasattr(self, "html"): +            html = self.html          if isinstance(self.SH_BROKEN_ENCODING, (str, unicode)):              html = unicode(html, self.SH_BROKEN_ENCODING) -            if hasattr(self, "html"): self.html = html +            if hasattr(self, "html"): +                self.html = html          if hasattr(self, "FILE_OFFLINE_PATTERN") and re.search(self.FILE_OFFLINE_PATTERN, html):              # File offline @@ -113,10 +121,12 @@ def parseFileInfo(self, url = '', html = ''):                  if 'N' in info:                      info['name'] = replace_patterns(info['N'], self.FILE_NAME_REPLACEMENTS)                  if 'S' in info: -                    size = replace_patterns(info['S'] + info['U'] if 'U' in info else info['S'], self.FILE_SIZE_REPLACEMENTS) +                    size = replace_patterns(info['S'] + info['U'] if 'U' in info else info['S'], +                                            self.FILE_SIZE_REPLACEMENTS)                      info['size'] = parseFileSize(size)                  elif isinstance(info['size'], (str, unicode)): -                    if 'units' in info: info['size'] += info['units'] +                    if 'units' in info: +                        info['size'] += info['units']                      info['size'] = parseFileSize(info['size'])      if hasattr(self, "file_info"): @@ -124,50 +134,59 @@ def parseFileInfo(self, url = '', html = ''):      return info['name'], info['size'], info['status'], url +  def create_getInfo(plugin):      def getInfo(urls):          for url in urls:              cj = CookieJar(plugin.__name__) -            if isinstance(plugin.SH_COOKIES, list): set_cookies(cj, plugin.SH_COOKIES) -            file_info = parseFileInfo(plugin, url, getURL(replace_patterns(url, plugin.FILE_URL_REPLACEMENTS), \ -                decode = not plugin.SH_BROKEN_ENCODING, cookies = cj)) +            if isinstance(plugin.SH_COOKIES, list): +                set_cookies(cj, plugin.SH_COOKIES) +            file_info = parseFileInfo(plugin, url, getURL(replace_patterns(url, plugin.FILE_URL_REPLACEMENTS), +                                                          decode=not plugin.SH_BROKEN_ENCODING, cookies=cj))              yield file_info +      return getInfo +  def timestamp(): -    return int(time()*1000) +    return int(time() * 1000) +  class PluginParseError(Exception):      def __init__(self, msg):          Exception.__init__(self)          self.value = 'Parse error (%s) - plugin may be out of date' % msg +      def __str__(self):          return repr(self.value) +  class SimpleHoster(Hoster):      __name__ = "SimpleHoster" -    __version__ = "0.29" +    __version__ = "0.31"      __pattern__ = None      __type__ = "hoster"      __description__ = """Base hoster plugin""" -    __author_name__ = ("zoidberg") -    __author_mail__ = ("zoidberg@mujmail.cz") +    __author_name__ = ("zoidberg", "stickell") +    __author_mail__ = ("zoidberg@mujmail.cz", "l.stickell@yahoo.it")      """      These patterns should be defined by each hoster:      FILE_INFO_PATTERN = r'(?P<N>file_name) (?P<S>file_size) (?P<U>units)'      or FILE_NAME_PATTERN = r'(?P<N>file_name)'      and FILE_SIZE_PATTERN = r'(?P<S>file_size) (?P<U>units)'      FILE_OFFLINE_PATTERN = r'File (deleted|not found)' -    TEMP_OFFLINE_PATTERN = r'Server maintenance' +    TEMP_OFFLINE_PATTERN = r'Server maintainance' + +    You can also define a PREMIUM_ONLY_PATTERN to detect links that can be downloaded only with a premium account.      """      FILE_SIZE_REPLACEMENTS = []      FILE_NAME_REPLACEMENTS = [("&#?\w+;", fixup)]      FILE_URL_REPLACEMENTS = [] -    SH_BROKEN_ENCODING = False # Set to True or encoding name if encoding in http header is not correct -    SH_COOKIES = True # or False or list of tuples [(domain, name, value)] -    SH_CHECK_TRAFFIC = False # True = force check traffic left for a premium account +    SH_BROKEN_ENCODING = False  # Set to True or encoding name if encoding in http header is not correct +    SH_COOKIES = True  # or False or list of tuples [(domain, name, value)] +    SH_CHECK_TRAFFIC = False  # True = force check traffic left for a premium account      def init(self):          self.file_info = {} @@ -187,11 +206,16 @@ class SimpleHoster(Hoster):          if self.premium and (not self.SH_CHECK_TRAFFIC or self.checkTrafficLeft()):              self.handlePremium()          else: +            # This line is required due to the getURL workaround. Can be removed in 0.5 +            self.html = self.load(pyfile.url, decode=not self.SH_BROKEN_ENCODING, cookies=self.SH_COOKIES) +            if hasattr(self, 'PREMIUM_ONLY_PATTERN') and re.search(self.PREMIUM_ONLY_PATTERN, self.html): +                self.fail("This link require a premium account")              self.handleFree()      def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, decode=False):          if type(url) == unicode: url = url.encode('utf8') -        return Hoster.load(self, url=url, get=get, post=post, ref=ref, cookies=cookies, just_header=just_header, decode=decode) +        return Hoster.load(self, url=url, get=get, post=post, ref=ref, cookies=cookies, +                           just_header=just_header, decode=decode)      def getFileInfo(self):          self.logDebug("URL: %s" % self.pyfile.url) @@ -228,7 +252,7 @@ class SimpleHoster(Hoster):      def parseError(self, msg):          raise PluginParseError(msg) -    def longWait(self, wait_time = None, max_tries = 3): +    def longWait(self, wait_time=None, max_tries=3):          if wait_time and isinstance(wait_time, (int, long, float)):              time_str = "%dh %dm" % divmod(wait_time / 60, 60)          else: @@ -240,7 +264,7 @@ class SimpleHoster(Hoster):          self.setWait(wait_time, True)          self.wait() -        self.retry(max_tries = max_tries, reason="Download limit reached") +        self.retry(max_tries=max_tries, reason="Download limit reached")      def parseHtmlForm(self, attr_str='', input_names=None):          return parseHtmlForm(attr_str, self.html, input_names) @@ -251,4 +275,4 @@ class SimpleHoster(Hoster):              return True          size = self.pyfile.size / 1024          self.logInfo("Filesize: %i KiB, Traffic left for user %s: %i KiB" % (size, self.user, traffic)) -        return  size <= traffic
\ No newline at end of file +        return size <= traffic diff --git a/pyload/plugins/internal/UnRar.py b/pyload/plugins/internal/UnRar.py index 7becd663c..e406f124e 100644 --- a/pyload/plugins/internal/UnRar.py +++ b/pyload/plugins/internal/UnRar.py @@ -28,7 +28,7 @@ from module.plugins.internal.AbstractExtractor import AbtractExtractor, WrongPas  class UnRar(AbtractExtractor):      __name__ = "UnRar" -    __version__ = "0.13" +    __version__ = "0.14"      # there are some more uncovered rar formats      re_splitfile = re.compile(r"(.*)\.part(\d+)\.rar$", re.I) @@ -184,7 +184,11 @@ class UnRar(AbtractExtractor):          args = []          #overwrite flag          args.append("-o+") if self.overwrite else args.append("-o-") - +         +        if self.excludefiles: +            for word in self.excludefiles.split(';'): +                args.append("-x%s" % word ) +                          # assume yes on all queries          args.append("-y") @@ -194,7 +198,6 @@ class UnRar(AbtractExtractor):          else:              args.append("-p-") -          #NOTE: return codes are not reliable, some kind of threading, cleanup whatever issue          call = [self.CMD, command] + args + list(xargs)          self.m.logDebug(" ".join([decode(arg) for arg in call])) | 
