diff options
Diffstat (limited to 'module/plugins')
| -rw-r--r-- | module/plugins/Account.py | 30 | ||||
| -rw-r--r-- | module/plugins/Crypter.py | 92 | ||||
| -rw-r--r-- | module/plugins/crypter/LinkList.py (renamed from module/plugins/container/LinkList.py) | 32 | ||||
| -rw-r--r-- | module/plugins/hoster/YoutubeCom.py | 6 | 
4 files changed, 90 insertions, 70 deletions
| diff --git a/module/plugins/Account.py b/module/plugins/Account.py index 6b65051db..dcf36f8a0 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -48,10 +48,6 @@ class Account(Base, AccountInfo):          else:              activated = Account.activated -        for opt in self.known_opt: -            if opt not in options: -                options[opt] = "" -          for opt in options.keys():              if opt not in self.known_opt:                  del options[opt] @@ -74,12 +70,9 @@ class Account(Base, AccountInfo):      def init(self):          pass -    #TODO: remove user, data -    def login(self, user, data, req): +    def login(self, req):          """login into account, the cookies will be saved so user can be recognized -        :param user: Deprecated -        :param data: Deprecated          :param req: `Request` instance          """          raise NotImplemented @@ -98,7 +91,13 @@ class Account(Base, AccountInfo):          self.login_ts = time()          try: -            self.login(self.loginname, {"password": self.password}, req) +            try: +                self.login(req) +            except TypeError: #TODO: temporary +                self.logDebug("Deprecated .login(...) signature ommit user, data") +                self.login(self.loginname, {"password": self.password}, req) + +                              self.valid = True          except WrongPassword:              self.logWarning( @@ -117,24 +116,23 @@ class Account(Base, AccountInfo):          return self.valid      def restoreDefaults(self): -        self.valid = Account.valid          self.validuntil = Account.validuntil          self.trafficleft = Account.trafficleft          self.maxtraffic = Account.maxtraffic          self.premium = Account.premium -        self.activated = Account.activated -    def update(self, password=None, options={}): +    def update(self, password=None, options=None):          """ updates account and return true if anything changed """          self.login_ts = 0 +        self.valid = True #set valid so it will be retried to login          if "activated" in options:              self.activated = from_string(options["avtivated"], "bool")          if password:              self.password = password -            self._login() +            self.relogin()              return True          if options:              # remove unknown options @@ -172,7 +170,11 @@ class Account(Base, AccountInfo):              self.checkLogin(req)              self.logDebug("Get Account Info for %s" % self.loginname)              try: -                infos = self.loadAccountInfo(self.loginname, req) +                try: +                    infos = self.loadAccountInfo(req) +                except TypeError: #TODO: temporary +                    self.logDebug("Deprecated .loadAccountInfo(...) signature, ommit user argument.") +                    infos = self.loadAccountInfo(self.loginname, req)              except Exception, e:                  infos = {"error": str(e)}              finally: diff --git a/module/plugins/Crypter.py b/module/plugins/Crypter.py index fc54b32d7..7c76afee7 100644 --- a/module/plugins/Crypter.py +++ b/module/plugins/Crypter.py @@ -1,9 +1,11 @@  # -*- coding: utf-8 -*- +from traceback import print_exc +  from module.Api import Destination  from module.common.packagetools import parseNames -from module.utils import to_list -from module.utils.fs import exists +from module.utils import to_list, has_method +from module.utils.fs import exists, remove, fs_encode  from Base import Base, Retry @@ -17,6 +19,12 @@ class Package:      def addUrl(self, url):          self.urls.append(url) +    def __eq__(self, other): +        return self.name == other.name and self.urls == other.urls + +    def __repr__(self): +        return "<CrypterPackage name=%s, links=%s, dest=%s" % (self.name, self.urls, self.dest) +  class PyFileMockup:      """ Legacy class needed by old crypter plugins """      def __init__(self, url): @@ -49,8 +57,8 @@ class Crypter(Base):          """Static method to decrypt, something. Can be used by other plugins.          :param core: pyLoad `Core`, needed in decrypt context -        :param url_or_urls: List of urls or urls -        :return: List of decrypted urls, all packages info removed +        :param url_or_urls: List of urls or single url/ file content +        :return: List of decrypted urls, all package info removed          """          urls = to_list(url_or_urls)          p = cls(core) @@ -66,18 +74,19 @@ class Crypter(Base):                  ret.extend(url_or_pack.urls)              else: # single url                  ret.append(url_or_pack) +        # eliminate duplicates +        return set(ret) -        return ret - -    def __init__(self, core, pid=-1, password=None): +    def __init__(self, core, package=None, password=None):          Base.__init__(self, core)          self.req = core.requestFactory.getRequest(self.__name__) -        # Package id plugin was initilized for, dont use this, its not guaranteed to be set -        self.pid = pid - +        # Package the plugin was initialized for, dont use this, its not guaranteed to be set +        self.package = package          #: Password supplied by user          self.password = password +        #: Propose a renaming of the owner package +        self.rename = None          # For old style decrypter, do not use these !          self.packages = [] @@ -125,7 +134,7 @@ class Crypter(Base):          """          return [Package(name, purls) for name, purls in parseNames([(url,url) for url in urls]).iteritems()] -    def processDecrypt(self, urls): +    def _decrypt(self, urls):          """ Internal  method to select decrypting method          :param urls: List of urls/content @@ -136,28 +145,47 @@ class Crypter(Base):          # seperate local and remote files          content, urls = self.getLocalContent(urls) -        if hasattr(cls, "decryptURLs"): +        if has_method(cls, "decryptURLs"):              self.setup()              result = to_list(self.decryptURLs(urls)) -        elif hasattr(cls, "decryptURL"): +        elif has_method(cls, "decryptURL"):              result = []              for url in urls:                  self.setup()                  result.extend(to_list(self.decryptURL(url))) -        elif hasattr(cls, "decrypt"): +        elif has_method(cls, "decrypt"):              self.logDebug("Deprecated .decrypt() method in Crypter plugin") -            result = [] # TODO +            self.setup() +            self.decrypt() +            result = self.convertPackages()          else: -            self.logError("No Decrypting method was overwritten") +            if not has_method(cls, "decryptFile"): +                self.logDebug("No Decrypting method was overwritten in plugin %s" % self.__name__)              result = [] -        if hasattr(cls, "decryptFile"): -            for c in content: +        if has_method(cls, "decryptFile"): +            for f, c in content:                  self.setup()                  result.extend(to_list(self.decryptFile(c))) +                try: +                    if f.startswith("tmp_"): remove(f) +                except : +                    pass          return result +    def processDecrypt(self, urls): +        """ Catches all exceptions in decrypt methods and return results + +        :return: Decrypting results +        """ +        try: +            return self._decrypt(urls) +        except Exception: +            if self.core.debug: +                print_exc() +            return [] +      def getLocalContent(self, urls):          """Load files from disk @@ -178,9 +206,13 @@ class Crypter(Base):                      path = self.core.path(url)                  if path: -                    f = open(path, "wb") -                    content.append(f.read()) -                    f.close() +                    try: +                        f = open(fs_encode(path), "rb") +                        content.append((f.name, f.read())) +                        f.close() +                    except IOError, e: +                        self.logError("IOError", e) +                        remote.append(url)                  else:                      remote.append(url) @@ -193,20 +225,12 @@ class Crypter(Base):          """ Retry decrypting, will only work once. Somewhat deprecated method, should be avoided. """          raise Retry() -    def createPackages(self): +    def convertPackages(self):          """ Deprecated """ -        self.logDebug("Deprecated method .createPackages()") -        for pack in self.packages: - -            self.log.debug("Parsed package %(name)s with %(len)d links" % { "name" : pack[0], "len" : len(pack[1]) } ) -             -            links = [x.decode("utf-8") for x in pack[1]] -             -            pid = self.core.api.files.addLinks(self.pid, links) - - -        if self.urls: -            self.core.api.generateAndAddPackages(self.urls) +        self.logDebug("Deprecated method .convertPackages()") +        res = [Package(name, urls) for name, urls in self.packages] +        res.extend(self.urls) +        return res      def clean(self):          if hasattr(self, "req"): diff --git a/module/plugins/container/LinkList.py b/module/plugins/crypter/LinkList.py index 614c76c90..8e46f88a9 100644 --- a/module/plugins/container/LinkList.py +++ b/module/plugins/crypter/LinkList.py @@ -1,25 +1,21 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- - -from module.plugins.Crypter import Crypter +from module.plugins.Crypter import Crypter, Package  class LinkList(Crypter):      __name__ = "LinkList"      __version__ = "0.11"      __pattern__ = r".+\.txt$"      __description__ = """Read Link Lists in txt format""" -    __config__ = [("clear", "bool", "Clear Linklist after adding", False)]      __author_name__ = ("spoob", "jeix")      __author_mail__ = ("spoob@pyload.org", "jeix@hasnomail.com") +    def decryptFile(self, content): +        links = content.splitlines() -    def decrypt(self, pyfile): -        txt = open(pyfile.url, 'r') -        links = txt.readlines() -        curPack = "Parsed links from %s" % pyfile.name -         -        packages = {curPack:[],} +        curPack = "default" +        packages = {curPack:[]}          for link in links:              link = link.strip() @@ -33,10 +29,8 @@ class LinkList(Crypter):                  packages[curPack] = []                  continue              packages[curPack].append(link) -        txt.close()          # empty packages fix -          delete = []          for key,value in packages.iteritems(): @@ -46,12 +40,12 @@ class LinkList(Crypter):          for key in delete:              del packages[key] -        if self.getConfig("clear"): -            try: -                txt = open(pyfile.url, 'wb') -                txt.close() -            except: -                self.log.warning(_("LinkList could not be cleared.")) -         +        urls = [] +          for name, links in packages.iteritems(): -            self.packages.append((name, links, name)) +            if name == "default": +                urls.extend(links) +            else: +                urls.append(Package(name, links)) + +        return urls
\ No newline at end of file diff --git a/module/plugins/hoster/YoutubeCom.py b/module/plugins/hoster/YoutubeCom.py index 2b3ea7ed7..b6ea36a3c 100644 --- a/module/plugins/hoster/YoutubeCom.py +++ b/module/plugins/hoster/YoutubeCom.py @@ -75,10 +75,10 @@ class YoutubeCom(Hoster):              fmt_dict[fmt] = unquote(url)          self.logDebug("Found links: %s" % fmt_dict) -	for fmt in fmt_dict.keys(): +        for fmt in fmt_dict.keys():              if fmt not in self.formats: -	        self.logDebug("FMT not supported: %s" % fmt) -		del fmt_dict[fmt] +                self.logDebug("FMT not supported: %s" % fmt) +                del fmt_dict[fmt]          allowed = lambda x: self.getConfig(self.formats[x][0])          sel = lambda x: self.formats[x][3] #select quality index | 
