diff options
Diffstat (limited to 'pyload/plugins/hooks')
28 files changed, 217 insertions, 153 deletions
| diff --git a/pyload/plugins/hooks/BypassCaptcha.py b/pyload/plugins/hooks/BypassCaptcha.py index 9558ba4c4..0f16d0b06 100644 --- a/pyload/plugins/hooks/BypassCaptcha.py +++ b/pyload/plugins/hooks/BypassCaptcha.py @@ -74,7 +74,7 @@ class BypassCaptcha(Hook):          result = data['Value']          ticket = data['TaskId'] -        self.logDebug("result %s : %s" % (ticket, result)) +        self.logDebug("Result %s : %s" % (ticket, result))          return ticket, result @@ -83,7 +83,7 @@ class BypassCaptcha(Hook):              response = getURL(self.RESPOND_URL, post={"task_id": ticket, "key": self.getConfig("passkey"),                                                        "cv": 1 if success else 0})          except BadHeader, e: -            self.logError("Could not send response.", str(e)) +            self.logError(_("Could not send response."), e      def newCaptchaTask(self, task):          if "service" in task.data: @@ -105,7 +105,7 @@ class BypassCaptcha(Hook):              start_new_thread(self.processCaptcha, (task,))          else: -            self.logInfo("Your %s account has not enough credits" % self.__name__) +            self.logInfo(_("Your %s account has not enough credits") % self.__name__)      def captchaCorrect(self, task):          if task.data['service'] == self.__name__ and "ticket" in task.data: diff --git a/pyload/plugins/hooks/Captcha9kw.py b/pyload/plugins/hooks/Captcha9kw.py index fcb5dd7c1..f8de28710 100644 --- a/pyload/plugins/hooks/Captcha9kw.py +++ b/pyload/plugins/hooks/Captcha9kw.py @@ -58,7 +58,7 @@ class Captcha9kw(Hook):          with open(task.captchaFile, 'rb') as f:              data = f.read()          data = b64encode(data) -        self.logDebug("%s : %s" % (task.captchaFile, data)) +        self.logDebug(task.captchaFile, data)          if task.isPositional():              mouse = 1          else: @@ -93,10 +93,10 @@ class Captcha9kw(Hook):              result = response2              task.data['ticket'] = response -            self.logInfo("result %s : %s" % (response, result)) +            self.logInfo(_("Result %s : %s") % (response, result))              task.setResult(result)          else: -            self.logError("Bad upload: %s" % response) +            self.logError(_("Bad upload"), response)              return False      def newCaptchaTask(self, task): @@ -129,12 +129,12 @@ class Captcha9kw(Hook):                                          "pyload": "1",                                          "source": "pyload",                                          "id": task.data['ticket']}) -                self.logInfo("Request correct: %s" % response) +                self.logInfo(_("Request correct", response)              except BadHeader, e: -                self.logError("Could not send correct request.", str(e)) +                self.logError(_("Could not send correct request."), e)          else: -            self.logError("No CaptchaID for correct request (task %s) found." % task) +            self.logError(_("No CaptchaID for correct request (task %s) found.") % task)      def captchaInvalid(self, task):          if "ticket" in task.data: @@ -148,9 +148,9 @@ class Captcha9kw(Hook):                                          "pyload": "1",                                          "source": "pyload",                                          "id": task.data['ticket']}) -                self.logInfo("Request refund: %s" % response) +                self.logInfo(_("Request refund", response)              except BadHeader, e: -                self.logError("Could not send refund request.", str(e)) +                self.logError(_("Could not send refund request."), e)          else: -            self.logError("No CaptchaID for not correct request (task %s) found." % task) +            self.logError(_("No CaptchaID for not correct request (task %s) found.") % task) diff --git a/pyload/plugins/hooks/CaptchaBrotherhood.py b/pyload/plugins/hooks/CaptchaBrotherhood.py index 81325be92..478a08cc5 100644 --- a/pyload/plugins/hooks/CaptchaBrotherhood.py +++ b/pyload/plugins/hooks/CaptchaBrotherhood.py @@ -139,7 +139,7 @@ class CaptchaBrotherhood(Hook):              task.setWaiting(100)              start_new_thread(self.processCaptcha, (task,))          else: -            self.logInfo("Your CaptchaBrotherhood Account has not enough credits") +            self.logInfo(_("Your CaptchaBrotherhood Account has not enough credits"))      def captchaInvalid(self, task):          if task.data['service'] == self.__name__ and "ticket" in task.data: diff --git a/pyload/plugins/hooks/Checksum.py b/pyload/plugins/hooks/Checksum.py index 75ebcdc4c..31d0cbf8c 100644 --- a/pyload/plugins/hooks/Checksum.py +++ b/pyload/plugins/hooks/Checksum.py @@ -62,7 +62,7 @@ class Checksum(Hook):      def coreReady(self):          if not self.getConfig("check_checksum"): -            self.logInfo("Checksum validation is disabled in plugin configuration") +            self.logInfo(_("Checksum validation is disabled in plugin configuration"))      def setup(self):          self.algorithms = sorted( @@ -101,7 +101,7 @@ class Checksum(Hook):              api_size = int(data['size'])              file_size = getsize(local_file)              if api_size != file_size: -                self.logWarning("File %s has incorrect size: %d B (%d expected)" % (pyfile.name, file_size, api_size)) +                self.logWarning(_("File %s has incorrect size: %d B (%d expected)") % (pyfile.name, file_size, api_size))                  self.checkFailed(pyfile, local_file, "Incorrect file size")              del data['size'] @@ -115,17 +115,17 @@ class Checksum(Hook):                      checksum = computeChecksum(local_file, key.replace("-", "").lower())                      if checksum:                          if checksum == data[key].lower(): -                            self.logInfo('File integrity of "%s" verified by %s checksum (%s).' % +                            self.logInfo(_('File integrity of "%s" verified by %s checksum (%s).') %                                          (pyfile.name, key.upper(), checksum))                              break                          else: -                            self.logWarning("%s checksum for file %s does not match (%s != %s)" % +                            self.logWarning(_("%s checksum for file %s does not match (%s != %s)") %                                             (key.upper(), pyfile.name, checksum, data[key]))                              self.checkFailed(pyfile, local_file, "Checksums do not match")                      else: -                        self.logWarning("Unsupported hashing algorithm: %s" % key.upper()) +                        self.logWarning(_("Unsupported hashing algorithm"), key.upper())              else: -                self.logWarning("Unable to validate checksum for file %s" % pyfile.name) +                self.logWarning(_("Unable to validate checksum for file"), pyfile.name)      def checkFailed(self, pyfile, local_file, msg):          check_action = self.getConfig("check_action") @@ -147,14 +147,13 @@ class Checksum(Hook):          for link in pypack.getChildren().itervalues():              file_type = splitext(link['name'])[1][1:].lower() -            #self.logDebug(link, file_type)              if file_type not in self.formats:                  continue              hash_file = fs_encode(safe_join(download_folder, link['name']))              if not isfile(hash_file): -                self.logWarning("File not found: %s" % link['name']) +                self.logWarning(_("File not found"), link['name'])                  continue              with open(hash_file) as f: @@ -168,8 +167,8 @@ class Checksum(Hook):                  algorithm = self.methods.get(file_type, file_type)                  checksum = computeChecksum(local_file, algorithm)                  if checksum == data['hash']: -                    self.logInfo('File integrity of "%s" verified by %s checksum (%s).' % +                    self.logInfo(_('File integrity of "%s" verified by %s checksum (%s).') %                                  (data['name'], algorithm, checksum))                  else: -                    self.logWarning("%s checksum for file %s does not match (%s != %s)" % +                    self.logWarning(_("%s checksum for file %s does not match (%s != %s)") %                                     (algorithm, data['name'], checksum, data['hash'])) diff --git a/pyload/plugins/hooks/ClickAndLoad.py b/pyload/plugins/hooks/ClickAndLoad.py index 47163ceef..501845840 100644 --- a/pyload/plugins/hooks/ClickAndLoad.py +++ b/pyload/plugins/hooks/ClickAndLoad.py @@ -30,7 +30,7 @@ class ClickAndLoad(Hook):                  thread.start_new_thread(proxy, (self, ip, self.port, 9666))              except: -                self.logError("ClickAndLoad port already in use.") +                self.logError(_("ClickAndLoad port already in use"))  def proxy(self, *settings): diff --git a/pyload/plugins/hooks/DeathByCaptcha.py b/pyload/plugins/hooks/DeathByCaptcha.py index 6db91b8c1..f2bae4848 100644 --- a/pyload/plugins/hooks/DeathByCaptcha.py +++ b/pyload/plugins/hooks/DeathByCaptcha.py @@ -146,7 +146,7 @@ class DeathByCaptcha(Hook):              raise DeathByCaptchaException('timed-out')          result = response['text'] -        self.logDebug("result %s : %s" % (ticket, result)) +        self.logDebug("Result %s : %s" % (ticket, result))          return ticket, result @@ -171,8 +171,9 @@ class DeathByCaptcha(Hook):              return False          balance, rate = self.info['balance'], self.info['rate'] -        self.logInfo("Account balance: US$%.3f (%d captchas left at %.2f cents each)" % (balance / 100, -                                                                                         balance // rate, rate)) +        self.logInfo(_("Account balance"), +                     _("US$%.3f (%d captchas left at %.2f cents each)") % (balance / 100, +                                                                           balance // rate, rate))          if balance > rate:              task.handler.append(self) diff --git a/pyload/plugins/hooks/DeleteFinished.py b/pyload/plugins/hooks/DeleteFinished.py index 99aa040bf..4b22c7fed 100644 --- a/pyload/plugins/hooks/DeleteFinished.py +++ b/pyload/plugins/hooks/DeleteFinished.py @@ -23,8 +23,8 @@ class DeleteFinished(Hook):          if not self.info['sleep']:              deloffline = self.getConfig('deloffline')              mode = '0,1,4' if deloffline else '0,4' -            msg = 'delete all finished packages in queue list (%s packages with offline links)' -            self.logInfo(msg % ('including' if deloffline else 'excluding')) +            msg = _('delete all finished packages in queue list (%s packages with offline links)') +            self.logInfo(msg % (_('including') if deloffline else _('excluding')))              self.deleteFinished(mode)              self.info['sleep'] = True              self.addEvent('packageFinished', self.wakeup) @@ -58,7 +58,7 @@ class DeleteFinished(Hook):          """Adds an event listener for event name"""          if event in self.m.events:              if func in self.m.events[event]: -                self.logDebug('Function already registered %s' % func) +                self.logDebug("Function already registered", func)              else:                  self.m.events[event].append(func)          else: diff --git a/pyload/plugins/hooks/DownloadScheduler.py b/pyload/plugins/hooks/DownloadScheduler.py index fc2e10aac..c5caee35d 100644 --- a/pyload/plugins/hooks/DownloadScheduler.py +++ b/pyload/plugins/hooks/DownloadScheduler.py @@ -35,7 +35,7 @@ class DownloadScheduler(Hook):          schedule = re.findall("(\d{1,2}):(\d{2})[\s]*(-?\d+)",                                schedule.lower().replace("full", "-1").replace("none", "0"))          if not schedule: -            self.logError("Invalid schedule") +            self.logError(_("Invalid schedule"))              return          t0 = localtime() @@ -58,7 +58,7 @@ class DownloadScheduler(Hook):      def setDownloadSpeed(self, speed):          if speed == 0:              abort = self.getConfig("abort") -            self.logInfo("Stopping download server. (Running downloads will %sbe aborted.)" % ('' if abort else 'not ')) +            self.logInfo(_("Stopping download server. (Running downloads will %sbe aborted.)") % '' if abort else _('not '))              self.core.api.pauseServer()              if abort:                  self.core.api.stopAllDownloads() @@ -66,10 +66,10 @@ class DownloadScheduler(Hook):              self.core.api.unpauseServer()              if speed > 0: -                self.logInfo("Setting download speed to %d kB/s" % speed) +                self.logInfo(_("Setting download speed to %d kB/s") % speed)                  self.core.api.setConfigValue("download", "limit_speed", 1)                  self.core.api.setConfigValue("download", "max_speed", speed)              else: -                self.logInfo("Setting download speed to FULL") +                self.logInfo(_("Setting download speed to FULL"))                  self.core.api.setConfigValue("download", "limit_speed", 0)                  self.core.api.setConfigValue("download", "max_speed", -1) diff --git a/pyload/plugins/hooks/EasybytezCom.py b/pyload/plugins/hooks/EasybytezCom.py index 1ec8a98f1..9d1cdc0db 100644 --- a/pyload/plugins/hooks/EasybytezCom.py +++ b/pyload/plugins/hooks/EasybytezCom.py @@ -31,7 +31,7 @@ class EasybytezCom(MultiHoster):              return m.group(1).split(',')          except Exception, e:              self.logDebug(e) -            self.logWarning("Unable to load supported hoster list, using last known") +            self.logWarning(_("Unable to load supported hoster list, using last known"))              return ["bitshare.com", "crocko.com", "ddlstorage.com", "depositfiles.com", "extabit.com", "hotfile.com",                      "mediafire.com", "netload.in", "rapidgator.net", "rapidshare.com", "uploading.com", "uload.to",                      "uploaded.to"] diff --git a/pyload/plugins/hooks/Ev0InFetcher.py b/pyload/plugins/hooks/Ev0InFetcher.py index c3def8add..cd7314fc9 100644 --- a/pyload/plugins/hooks/Ev0InFetcher.py +++ b/pyload/plugins/hooks/Ev0InFetcher.py @@ -67,15 +67,14 @@ class Ev0InFetcher(Hook):                  if show.lower() in normalizefiletitle(item['title']) and lastfound < int(mktime(item.date_parsed)):                      links = self.filterLinks(item['description'].split("<br />"))                      packagename = item['title'].encode("utf-8") -                    self.logInfo("Ev0InFetcher: new episode '%s' (matched '%s')" % (packagename, show)) +                    self.logInfo(_("New episode '%s' (matched '%s')") % (packagename, show))                      self.core.api.addPackage(packagename, links, 1 if self.getConfig("queue") else 0)                      self.setStorage("show_%s_lastfound" % show, int(mktime(item.date_parsed)))                      found = True          if not found: -            #self.logDebug("Ev0InFetcher: no new episodes found")              pass          for show, lastfound in self.getStorage().iteritems():              if int(lastfound) > 0 and int(lastfound) + (3600 * 24 * 30) < int(time()):                  self.delStorage("show_%s_lastfound" % show) -                self.logDebug("Ev0InFetcher: cleaned '%s' record" % show) +                self.logDebug("Cleaned '%s' record" % show) diff --git a/pyload/plugins/hooks/ExpertDecoders.py b/pyload/plugins/hooks/ExpertDecoders.py index ef5409b76..292c84b7c 100644 --- a/pyload/plugins/hooks/ExpertDecoders.py +++ b/pyload/plugins/hooks/ExpertDecoders.py @@ -49,7 +49,6 @@ class ExpertDecoders(Hook):          with open(task.captchaFile, 'rb') as f:              data = f.read()          data = b64encode(data) -        #self.logDebug("%s: %s : %s" % (ticket, task.captchaFile, data))          req = getRequest()          #raise timeout threshold @@ -61,7 +60,7 @@ class ExpertDecoders(Hook):          finally:              req.close() -        self.logDebug("result %s : %s" % (ticket, result)) +        self.logDebug("Result %s : %s" % (ticket, result))          task.setResult(result)      def newCaptchaTask(self, task): @@ -88,7 +87,7 @@ class ExpertDecoders(Hook):              try:                  response = getURL(self.API_URL, post={"action": "refund", "key": self.getConfig("passkey"),                                                        "gen_task_id": task.data['ticket']}) -                self.logInfo("Request refund: %s" % response) +                self.logInfo(_("Request refund"), response)              except BadHeader, e: -                self.logError("Could not send refund request.", str(e)) +                self.logError(_("Could not send refund request."), e) diff --git a/pyload/plugins/hooks/ExternalScripts.py b/pyload/plugins/hooks/ExternalScripts.py index 372035e82..2e8dace14 100644 --- a/pyload/plugins/hooks/ExternalScripts.py +++ b/pyload/plugins/hooks/ExternalScripts.py @@ -2,6 +2,7 @@  import subprocess +from itertools import chain  from os import listdir, access, X_OK, makedirs  from os.path import join, exists, basename, abspath @@ -12,23 +13,27 @@ from pyload.utils import safe_join  class ExternalScripts(Hook):      __name__ = "ExternalScripts"      __type__ = "hook" -    __version__ = "0.23" +    __version__ = "0.24"      __config__ = [("activated", "bool", "Activated", True)]      __description__ = """Run external scripts""" -    __author_name__ = ("mkaay", "RaNaN", "spoob") -    __author_mail__ = ("mkaay@mkaay.de", "ranan@pyload.org", "spoob@pyload.org") +    __author_name__ = ("mkaay", "RaNaN", "spoob", "Walter Purcaro") +    __author_mail__ = ("mkaay@mkaay.de", "ranan@pyload.org", "spoob@pyload.org", "vuolter@gmail.com") -    event_list = ["unrarFinished", "allDownloadsFinished", "allDownloadsProcessed"] +    event_list = ["archive_extracted", "package_extracted", "all_archives_extracted", "all_archives_processed", +                  "allDownloadsFinished", "allDownloadsProcessed"]      def setup(self):          self.scripts = {} -        folders = ["download_preparing", "download_finished", "package_finished", -                   "before_reconnect", "after_reconnect", "unrar_finished", -                   "all_dls_finished", "all_dls_processed"] +        folders = ["download_preparing", "download_finished", "all_downloads_finished", "all_downloads_processed", +                   "before_reconnect", "after_reconnect", +                   "package_finished", "package_extracted", +                   "archive_extracted", "all_archives_extracted", "all_archives_processed", +                   # deprecated folders +                   "unrar_finished", "all_dls_finished", "all_dls_processed"]          for folder in folders:              self.scripts[folder] = [] @@ -38,7 +43,8 @@ class ExternalScripts(Hook):          for script_type, names in self.scripts.iteritems():              if names: -                self.logInfo((_("Installed scripts for %s: ") % script_type) + ", ".join([basename(x) for x in names])) +                self.logInfo(_("Installed scripts for"), script_type, ", ".join([basename(x) for x in names])) +      def initPluginType(self, folder, path):          if not exists(path): @@ -57,48 +63,75 @@ class ExternalScripts(Hook):              self.scripts[folder].append(join(path, f)) +      def callScript(self, script, *args):          try:              cmd = [script] + [str(x) if not isinstance(x, basestring) else x for x in args] -            self.logDebug("Executing %(script)s: %(cmd)s" % {"script": abspath(script), "cmd": " ".join(cmd)}) +            self.logDebug("Executing", abspath(script), " ".join(cmd))              #output goes to pyload              subprocess.Popen(cmd, bufsize=-1)          except Exception, e: -            self.logError(_("Error in %(script)s: %(error)s") % {"script": basename(script), "error": str(e)}) +            self.logError(_("Error in %(script)s: %(error)s") % {"script": basename(script), "error": e}) +      def downloadPreparing(self, pyfile):          for script in self.scripts['download_preparing']:              self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.id) +      def downloadFinished(self, pyfile): +        download_folder = self.config['general']['download_folder']          for script in self.scripts['download_finished']: -            self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.name, -                            safe_join(self.config['general']['download_folder'], -                                      pyfile.package().folder, pyfile.name), pyfile.id) +            filename = safe_join(download_folder, pyfile.package().folder, pyfile.name) +            self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.name, filename, pyfile.id) +      def packageFinished(self, pypack): +        download_folder = self.config['general']['download_folder']          for script in self.scripts['package_finished']: -            folder = self.config['general']['download_folder'] -            folder = safe_join(folder, pypack.folder) - +            folder = safe_join(download_folder, pypack.folder)              self.callScript(script, pypack.name, folder, pypack.password, pypack.id) +      def beforeReconnecting(self, ip):          for script in self.scripts['before_reconnect']:              self.callScript(script, ip) +      def afterReconnecting(self, ip):          for script in self.scripts['after_reconnect']:              self.callScript(script, ip) -    def unrarFinished(self, folder, fname): -        for script in self.scripts['unrar_finished']: -            self.callScript(script, folder, fname) + +    def archive_extracted(self, pyfile, folder, filename, files): +        for script in self.scripts['archive_extracted']: +            self.callScript(script, folder, filename, files) +        for script in self.scripts['unrar_finished']:  #: deprecated +            self.callScript(script, folder, filename) + + +    def package_extracted(self, pypack): +        download_folder = self.config['general']['download_folder'] +        for script in self.scripts['package_extracted']: +            folder = save_join(download_folder, pypack.folder) +            self.callScript(script, pypack.name, folder, pypack.password, pypack.id) + + +    def all_archives_extracted(self): +        for script in self.scripts['all_archives_extracted']: +            self.callScript(script) + + +    def all_archives_processed(self): +        for script in self.scripts['all_archives_processed']: +            self.callScript(script) +      def allDownloadsFinished(self): -        for script in self.scripts['all_dls_finished']: +        for script in chain(self.scripts['all_downloads_finished'], self.scripts['all_dls_finished']):              self.callScript(script) +      def allDownloadsProcessed(self): -        for script in self.scripts['all_dls_processed']: +        for script in chain(self.scripts['all_downloads_processed'], self.scripts['all_dls_processed']):              self.callScript(script) diff --git a/pyload/plugins/hooks/ExtractArchive.py b/pyload/plugins/hooks/ExtractArchive.py index 1a2da53ad..8d6f09172 100644 --- a/pyload/plugins/hooks/ExtractArchive.py +++ b/pyload/plugins/hooks/ExtractArchive.py @@ -53,17 +53,14 @@ from pyload.utils import safe_join, fs_encode  class ExtractArchive(Hook): -    """ -    Provides: unrarFinished (folder, filename) -    """      __name__ = "ExtractArchive"      __type__ = "hook" -    __version__ = "0.16" +    __version__ = "0.17"      __config__ = [("activated", "bool", "Activated", True),                    ("fullpath", "bool", "Extract full path", True),                    ("overwrite", "bool", "Overwrite files", True), -                  ("passwordfile", "file", "password file", "unrar_passwords.txt"), +                  ("passwordfile", "file", "password file", "archive_password.txt"),                    ("deletearchive", "bool", "Delete archives when done", False),                    ("subfolder", "bool", "Create subfolder for each package", False),                    ("destination", "folder", "Extract files to", ""), @@ -73,8 +70,8 @@ class ExtractArchive(Hook):                    ("renice", "int", "CPU Priority", 0)]      __description__ = """Extract different kind of archives""" -    __author_name__ = ("pyLoad Team", "AndroKev") -    __author_mail__ = ("admin@pyload.org", "@pyloadforum") +    __author_name__ = ("RaNaN", "AndroKev", "Walter Purcaro") +    __author_mail__ = ("ranan@pyload.org", "@pyloadforum", "vuolter@gmail.com")      event_list = ["allDownloadsProcessed"] @@ -96,12 +93,12 @@ class ExtractArchive(Hook):                  if e.errno == 2:                      self.logInfo(_("No %s installed") % p)                  else: -                    self.logWarning(_("Could not activate %s") % p, str(e)) +                    self.logWarning(_("Could not activate %s") % p, e)                      if self.core.debug:                          print_exc()              except Exception, e: -                self.logWarning(_("Could not activate %s") % p, str(e)) +                self.logWarning(_("Could not activate %s") % p, e)                  if self.core.debug:                      print_exc() @@ -113,33 +110,50 @@ class ExtractArchive(Hook):          # queue with package ids          self.queue = [] +      @Expose      def extractPackage(self, id):          """ Extract package with given id"""          self.manager.startThread(self.extract, [id]) +      def packageFinished(self, pypack): +        pid = pypack.id          if self.getConfig("queue"):              self.logInfo(_("Package %s queued for later extracting") % pypack.name) -            self.queue.append(pypack.id) +            self.queue.append(pid)          else: -            self.manager.startThread(self.extract, [pypack.id]) +            self.manager.startThread(self.extract, [pid]) +      @threaded      def allDownloadsProcessed(self, thread):          local = copy(self.queue)          del self.queue[:] -        self.extract(local, thread) +        if self.extract(local, thread):  #: check only if all gone fine, no failed reporting for now +            self.manager.dispatchEvent("all_archives_extracted") +        self.manager.dispatchEvent("all_archives_processed") +      def extract(self, ids, thread=None): +        processed = [] +        extracted = [] +        failed = [] + +        destination = self.getConfig("destination") +        subfolder = self.getConfig("subfolder") +        fullpath = self.getConfig("fullpath") +        overwrite = self.getConfig("overwrite") +        excludefiles = self.getConfig("excludefiles") +        renice = self.getConfig("renice") +        recursive = self.getConfig("recursive") +          # reload from txt file          self.reloadPasswords()          # dl folder          dl = self.config['general']['download_folder'] -        extracted = [] -          #iterate packages -> plugins -> targets          for pid in ids:              p = self.core.files.getPackage(pid) @@ -149,21 +163,17 @@ class ExtractArchive(Hook):              # determine output folder              out = safe_join(dl, p.folder, "") -            # force trailing slash - -            if self.getConfig("destination") and self.getConfig("destination").lower() != "none":                  out = safe_join(dl, p.folder, self.getConfig("destination"), "") -                #relative to package folder if destination is relative, otherwise absolute path overwrites them - -                if self.getConfig("subfolder"): +            if subfolder:                      out = safe_join(out, fs_encode(p.folder)) -                if not exists(out): -                    makedirs(out) +            if not exists(out): +                makedirs(out)              files_ids = [(safe_join(dl, p.folder, x['name']), x['id']) for x in p.getChildren().itervalues()]              matched = False +            success = True              # check as long there are unseen files              while files_ids: @@ -175,36 +185,51 @@ class ExtractArchive(Hook):                          self.logDebug("Targets for %s: %s" % (plugin.__name__, targets))                          matched = True                      for target, fid in targets: -                        if target in extracted: +                        if target in processed:                              self.logDebug(basename(target), "skipped")                              continue -                        extracted.append(target)  # prevent extracting same file twice -                        klass = plugin(self, target, out, self.getConfig("fullpath"), self.getConfig("overwrite"), self.getConfig("excludefiles"), -                                       self.getConfig("renice")) -                        klass.init() +                        processed.append(target)  # prevent extracting same file twice                          self.logInfo(basename(target), _("Extract to %s") % out) -                        new_files = self.startExtracting(klass, fid, p.password.strip().splitlines(), thread) -                        self.logDebug("Extracted: %s" % new_files) +                        try: +                            klass = plugin(self, target, out, fullpath, overwrite, excludefiles, renice) +                            klass.init() +                            password = p.password.strip().splitlines() +                            new_files = self._extract(klass, fid, password, thread) +                        except Exception, e: +                            self.logError(basename(target), e) +                            success = False +                            continue + +                        self.logDebug("Extracted", new_files)                          self.setPermissions(new_files)                          for file in new_files:                              if not exists(file): -                                self.logDebug("new file %s does not exists" % file) +                                self.logDebug("New file %s does not exists" % file)                                  continue -                            if self.getConfig("recursive") and isfile(file): +                            if recursive and isfile(file):                                  new_files_ids.append((file, fid))  # append as new target                  files_ids = new_files_ids  # also check extracted files -            if not matched: +            if matched: +                if success: +                    extracted.append(pid) +                    self.manager.dispatchEvent("package_extracted", p) +                else: +                    failed.append(pid) +                    self.manager.dispatchEvent("package_extract_failed", p) +            else:                  self.logInfo(_("No files found to extract")) -    def startExtracting(self, plugin, fid, passwords, thread): +        return True if not failed else False + + +    def _extract(self, plugin, fid, passwords, thread):          pyfile = self.core.files.getFile(fid) -        if not pyfile: -            return [] +        deletearchive = self.getConfig("deletearchive")          pyfile.setCustomStatus(_("extracting"))          thread.addActive(pyfile)  # keep this file until everything is done @@ -218,17 +243,17 @@ class ExtractArchive(Hook):                  success = True              else:                  self.logInfo(basename(plugin.file), _("Password protected")) -                self.logDebug("Passwords: %s" % str(passwords)) +                self.logDebug("Passwords", passwords)                  pwlist = copy(self.getPasswords()) -                #remove already supplied pws from list (only local) +                # remove already supplied pws from list (only local)                  for pw in passwords:                      if pw in pwlist:                          pwlist.remove(pw)                  for pw in passwords + pwlist:                      try: -                        self.logDebug("Try password: %s" % pw) +                        self.logDebug("Try password", pw)                          if plugin.checkPassword(pw):                              plugin.extract(progress, pw)                              self.addPassword(pw) @@ -238,13 +263,12 @@ class ExtractArchive(Hook):                          self.logDebug("Password was wrong")              if not success: -                self.logError(basename(plugin.file), _("Wrong password")) -                return [] +                raise Exception(_("Wrong password"))              if self.core.debug: -                self.logDebug("Would delete: %s" % ", ".join(plugin.getDeleteFiles())) +                self.logDebug("Would delete", ", ".join(plugin.getDeleteFiles())) -            if self.getConfig("deletearchive"): +            if deletearchive:                  files = plugin.getDeleteFiles()                  self.logInfo(_("Deleting %s files") % len(files))                  for f in files: @@ -254,53 +278,60 @@ class ExtractArchive(Hook):                          self.logDebug("%s does not exists" % f)              self.logInfo(basename(plugin.file), _("Extracting finished")) -            self.manager.dispatchEvent("unrarFinished", plugin.out, plugin.file) -            return plugin.getExtractedFiles() +            extracted_files = plugin.getExtractedFiles() +            self.manager.dispatchEvent("archive_extracted", pyfile, plugin.out, plugin.file, extracted_files) + +            return extracted_files          except ArchiveError, e: -            self.logError(basename(plugin.file), _("Archive Error"), str(e)) +            self.logError(basename(plugin.file), _("Archive Error"), e)          except CRCError:              self.logError(basename(plugin.file), _("CRC Mismatch"))          except Exception, e:              if self.core.debug:                  print_exc() -            self.logError(basename(plugin.file), _("Unknown Error"), str(e)) +            self.logError(basename(plugin.file), _("Unknown Error"), e) + +        self.manager.dispatchEvent("archive_extract_failed", pyfile) +        raise Exception(_("Extract failed")) -        return []      @Expose      def getPasswords(self):          """ List of saved passwords """          return self.passwords +      def reloadPasswords(self): -        pwfile = self.getConfig("passwordfile") -        if not exists(pwfile): -            open(pwfile, "wb").close() +        passwordfile = self.getConfig("passwordfile") +        if not exists(passwordfile): +            open(passwordfile, "wb").close()          passwords = [] -        f = open(pwfile, "rb") +        f = open(passwordfile, "rb")          for pw in f.read().splitlines():              passwords.append(pw)          f.close()          self.passwords = passwords +      @Expose      def addPassword(self, pw):          """  Adds a password to saved list""" -        pwfile = self.getConfig("passwordfile") +        passwordfile = self.getConfig("passwordfile")          if pw in self.passwords:              self.passwords.remove(pw)          self.passwords.insert(0, pw) -        f = open(pwfile, "wb") +        f = open(passwordfile, "wb")          for pw in self.passwords:              f.write(pw + "\n")          f.close() +      def setPermissions(self, files):          for f in files:              if not exists(f): diff --git a/pyload/plugins/hooks/FreeWayMe.py b/pyload/plugins/hooks/FreeWayMe.py index 35b275067..635bc3415 100644 --- a/pyload/plugins/hooks/FreeWayMe.py +++ b/pyload/plugins/hooks/FreeWayMe.py @@ -22,5 +22,5 @@ class FreeWayMe(MultiHoster):      def getHoster(self):          hostis = getURL("https://www.free-way.me/ajax/jd.php", get={"id": 3}).replace("\"", "").strip() -        self.logDebug("hosters: %s" % hostis) +        self.logDebug("Hosters", hostis)          return [x.strip() for x in hostis.split(",") if x.strip()] diff --git a/pyload/plugins/hooks/IRCInterface.py b/pyload/plugins/hooks/IRCInterface.py index ef1fa2a09..99ac20acb 100644 --- a/pyload/plugins/hooks/IRCInterface.py +++ b/pyload/plugins/hooks/IRCInterface.py @@ -89,8 +89,8 @@ class IRCInterface(Thread, Hook):          for t in self.getConfig("owner").split():              if t.strip().startswith("#"):                  self.sock.send("JOIN %s\r\n" % t.strip()) -        self.logInfo("pyLoad IRC: Connected to %s!" % host) -        self.logInfo("pyLoad IRC: Switching to listening mode!") +        self.logInfo(_("Connected to"), host) +        self.logInfo(_("Switching to listening mode!"))          try:              self.main_loop() @@ -177,7 +177,7 @@ class IRCInterface(Thread, Hook):              for line in res:                  self.response(line, msg['origin'])          except Exception, e: -            self.logError("pyLoad IRC: " + repr(e)) +            self.logError(repr(e))      def response(self, msg, origin=""):          if origin == "": diff --git a/pyload/plugins/hooks/ImageTyperz.py b/pyload/plugins/hooks/ImageTyperz.py index 2591a1c78..8d2fb2006 100644 --- a/pyload/plugins/hooks/ImageTyperz.py +++ b/pyload/plugins/hooks/ImageTyperz.py @@ -61,7 +61,7 @@ class ImageTyperz(Hook):          except:              raise ImageTyperzException("invalid response") -        self.logInfo("Account balance: $%s left" % response) +        self.logInfo(_("Account balance: $%s left") % response)          return balance      def submit(self, captcha, captchaType="file", match=None): @@ -118,7 +118,7 @@ class ImageTyperz(Hook):              start_new_thread(self.processCaptcha, (task,))          else: -            self.logInfo("Your %s account has not enough credits" % self.__name__) +            self.logInfo(_("Your %s account has not enough credits") % self.__name__)      def captchaInvalid(self, task):          if task.data['service'] == self.__name__ and "ticket" in task.data: @@ -127,9 +127,9 @@ class ImageTyperz(Hook):                                                        "imageid": task.data['ticket']})              if response == "SUCCESS": -                self.logInfo("Bad captcha solution received, requested refund") +                self.logInfo(_("Bad captcha solution received, requested refund"))              else: -                self.logError("Bad captcha solution received, refund request failed", response) +                self.logError(_("Bad captcha solution received, refund request failed"), response)      def processCaptcha(self, task):          c = task.captchaFile diff --git a/pyload/plugins/hooks/LinkdecrypterCom.py b/pyload/plugins/hooks/LinkdecrypterCom.py index 34517761a..cb7ab9da5 100644 --- a/pyload/plugins/hooks/LinkdecrypterCom.py +++ b/pyload/plugins/hooks/LinkdecrypterCom.py @@ -52,4 +52,4 @@ class LinkdecrypterCom(Hook):          dict['pattern'] = regexp          dict['re'] = re.compile(regexp) -        self.logDebug("REGEXP: " + regexp) +        self.logDebug("REGEXP", regexp) diff --git a/pyload/plugins/hooks/MegaDebridEu.py b/pyload/plugins/hooks/MegaDebridEu.py index 8c8894c9b..0345e47fa 100644 --- a/pyload/plugins/hooks/MegaDebridEu.py +++ b/pyload/plugins/hooks/MegaDebridEu.py @@ -25,7 +25,7 @@ class MegaDebridEu(MultiHoster):          if json_data['response_code'] == "ok":              host_list = [element[0] for element in json_data['hosters']]          else: -            self.logError("Unable to retrieve hoster list") +            self.logError(_("Unable to retrieve hoster list"))              host_list = list()          return host_list diff --git a/pyload/plugins/hooks/MergeFiles.py b/pyload/plugins/hooks/MergeFiles.py index 5761a5990..540ebafdc 100644 --- a/pyload/plugins/hooks/MergeFiles.py +++ b/pyload/plugins/hooks/MergeFiles.py @@ -44,11 +44,11 @@ class MergeFiles(Hook):              download_folder = safe_join(download_folder, pack.folder)          for name, file_list in files.iteritems(): -            self.logInfo("Starting merging of %s" % name) +            self.logInfo(_("Starting merging of"), name)              final_file = open(safe_join(download_folder, name), "wb")              for splitted_file in file_list: -                self.logDebug("Merging part %s" % splitted_file) +                self.logDebug("Merging part", splitted_file)                  pyfile = self.core.files.getFile(fid_dict[splitted_file])                  pyfile.setStatus("processing")                  try: @@ -64,7 +64,7 @@ class MergeFiles(Hook):                          else:                              break                      s_file.close() -                    self.logDebug("Finished merging part %s" % splitted_file) +                    self.logDebug("Finished merging part", splitted_file)                  except Exception, e:                      print traceback.print_exc()                  finally: @@ -73,4 +73,4 @@ class MergeFiles(Hook):                      pyfile.release()              final_file.close() -            self.logInfo("Finished merging of %s" % name) +            self.logInfo(_("Finished merging of"), name) diff --git a/pyload/plugins/hooks/MultiHome.py b/pyload/plugins/hooks/MultiHome.py index 61fbdd230..968214b5c 100644 --- a/pyload/plugins/hooks/MultiHome.py +++ b/pyload/plugins/hooks/MultiHome.py @@ -44,7 +44,7 @@ class MultiHome(Hook):              if iface:                  iface.useFor(pluginName, account)                  requestFactory.iface = lambda: iface.adress -                self.logDebug("Multihome: using address: " + iface.adress) +                self.logDebug("Using address", iface.adress)              return oldGetRequest(pluginName, account)          requestFactory.getRequest = getRequest diff --git a/pyload/plugins/hooks/MyfastfileCom.py b/pyload/plugins/hooks/MyfastfileCom.py index 311bc2212..216dcaf5d 100644 --- a/pyload/plugins/hooks/MyfastfileCom.py +++ b/pyload/plugins/hooks/MyfastfileCom.py @@ -23,7 +23,7 @@ class MyfastfileCom(MultiHoster):      def getHoster(self):          json_data = getURL('http://myfastfile.com/api.php?hosts', decode=True) -        self.logDebug('JSON data: ' + json_data) +        self.logDebug("JSON data", json_data)          json_data = json_loads(json_data)          return json_data['hosts'] diff --git a/pyload/plugins/hooks/OverLoadMe.py b/pyload/plugins/hooks/OverLoadMe.py index a57c7c2b4..fae4209f8 100644 --- a/pyload/plugins/hooks/OverLoadMe.py +++ b/pyload/plugins/hooks/OverLoadMe.py @@ -26,6 +26,6 @@ class OverLoadMe(MultiHoster):          page = getURL(https + "://api.over-load.me/hoster.php",                        get={"auth": "0001-cb1f24dadb3aa487bda5afd3b76298935329be7700cd7-5329be77-00cf-1ca0135f"}                        ).replace("\"", "").strip() -        self.logDebug("Hosterlist: %s" % page) +        self.logDebug("Hosterlist", page)          return [x.strip() for x in page.split(",") if x.strip()] diff --git a/pyload/plugins/hooks/RehostTo.py b/pyload/plugins/hooks/RehostTo.py index 097ebc646..059f36284 100644 --- a/pyload/plugins/hooks/RehostTo.py +++ b/pyload/plugins/hooks/RehostTo.py @@ -30,7 +30,7 @@ class RehostTo(MultiHoster):          user = self.account.selectAccount()[0]          if not user: -            self.logError("Rehost.to: " + _("Please add your rehost.to account first and restart pyLoad")) +            self.logError(_("Please add your rehost.to account first and restart pyLoad"))              return          data = self.account.getAccountInfo(user) diff --git a/pyload/plugins/hooks/RestartFailed.py b/pyload/plugins/hooks/RestartFailed.py index a50ab60a4..8bad74620 100644 --- a/pyload/plugins/hooks/RestartFailed.py +++ b/pyload/plugins/hooks/RestartFailed.py @@ -31,7 +31,7 @@ class RestartFailed(Hook):                  self.logDebug("Invalid interval value, kept current")      def periodical(self): -        self.logInfo("Restart failed downloads") +        self.logInfo(_("Restart failed downloads"))          self.api.restartFailed()      def setup(self): diff --git a/pyload/plugins/hooks/UnSkipOnFail.py b/pyload/plugins/hooks/UnSkipOnFail.py index 941ce4fc7..40b0233f5 100644 --- a/pyload/plugins/hooks/UnSkipOnFail.py +++ b/pyload/plugins/hooks/UnSkipOnFail.py @@ -22,14 +22,14 @@ class UnSkipOnFail(Hook):      def downloadFailed(self, pyfile):          pyfile_name = basename(pyfile.name)          pid = pyfile.package().id -        msg = 'look for skipped duplicates for %s (pid:%s)...' +        msg = _('look for skipped duplicates for %s (pid:%s)')          self.logInfo(msg % (pyfile_name, pid))          dups = self.findDuplicates(pyfile)          for link in dups:              # check if link is "skipped"(=4)              if link.status == 4:                  lpid = link.packageID -                self.logInfo('restart "%s" (pid:%s)...' % (pyfile_name, lpid)) +                self.logInfo(_('restart "%s" (pid:%s)') % (pyfile_name, lpid))                  self.setLinkStatus(link, "queued")      def findDuplicates(self, pyfile): diff --git a/pyload/plugins/hooks/UpdateManager.py b/pyload/plugins/hooks/UpdateManager.py index ece7ca610..6da39b239 100644 --- a/pyload/plugins/hooks/UpdateManager.py +++ b/pyload/plugins/hooks/UpdateManager.py @@ -207,7 +207,7 @@ class UpdateManager(Hook):                  else:                      raise Exception, _("Version mismatch")              except Exception, e: -                self.logError(_("Error updating plugin %s") % filename, str(e)) +                self.logError(_("Error updating plugin %s") % filename, e)          if blacklist:              blacklisted = sorted(map(lambda x: (x.split('|')[0], x.split('|')[1].rsplit('.', 1)[0]), blacklist)) @@ -247,7 +247,7 @@ class UpdateManager(Hook):          if not type_plugins:              return -        self.logDebug("Request deletion of plugins: %s" % type_plugins) +        self.logDebug("Requested deletion of plugins", type_plugins)          removed = [] @@ -261,7 +261,7 @@ class UpdateManager(Hook):                  try:                      remove(filename)                  except Exception, e: -                    self.logDebug("Error deleting \"%s\"" % path.basename(filename), str(e)) +                    self.logDebug("Error deleting", path.basename(filename), e)                      err = True                  filename += "c" @@ -271,7 +271,7 @@ class UpdateManager(Hook):                              self.manager.deactivateHook(name)                          remove(filename)                      except Exception, e: -                        self.logDebug("Error deleting \"%s\"" % path.basename(filename), str(e)) +                        self.logDebug("Error deleting", path.basename(filename), e)                          err = True              if not err: diff --git a/pyload/plugins/hooks/XFileSharingPro.py b/pyload/plugins/hooks/XFileSharingPro.py index 7478034c6..635d5302b 100644 --- a/pyload/plugins/hooks/XFileSharingPro.py +++ b/pyload/plugins/hooks/XFileSharingPro.py @@ -8,7 +8,7 @@ from pyload.plugins.Hook import Hook  class XFileSharingPro(Hook):      __name__ = "XFileSharingPro"      __type__ = "hook" -    __version__ = "0.11" +    __version__ = "0.12"      __config__ = [("activated", "bool", "Activated", True),                    ("loadDefault", "bool", "Include default (built-in) hoster list", True), @@ -23,6 +23,7 @@ class XFileSharingPro(Hook):      def coreReady(self):          self.loadPattern() +      def loadPattern(self):          hosterList = self.getConfigSet('includeList')          excludeList = self.getConfigSet('excludeList') @@ -60,18 +61,19 @@ class XFileSharingPro(Hook):              self.unload()              return -        regexp = r"http://(?:[^/]*\.)?(%s)/\w{12}" % ("|".join(sorted(hosterList)).replace('.', '\.')) -        #self.logDebug(regexp) +        regexp = r"http://(?:[^/]*\.)?(%s)/(?:embed-)?\w{12}" % ("|".join(sorted(hosterList)).replace('.', '\.'))          dict = self.core.pluginManager.hosterPlugins['XFileSharingPro']          dict['pattern'] = regexp          dict['re'] = re.compile(regexp)          self.logDebug("Pattern loaded - handling %d hosters" % len(hosterList)) +      def getConfigSet(self, option):          s = self.getConfig(option).lower().replace('|', ',').replace(';', ',')          return set([x.strip() for x in s.split(',')]) +      def unload(self):          dict = self.core.pluginManager.hosterPlugins['XFileSharingPro']          dict['pattern'] = r'^unmatchable$' diff --git a/pyload/plugins/hooks/XMPPInterface.py b/pyload/plugins/hooks/XMPPInterface.py index 881e7f5dc..4a01493a6 100644 --- a/pyload/plugins/hooks/XMPPInterface.py +++ b/pyload/plugins/hooks/XMPPInterface.py @@ -84,22 +84,22 @@ class XMPPInterface(IRCInterface, JabberClient):          try:              self.loop()          except Exception, ex: -            self.logError("pyLoad XMPP: %s" % str(ex)) +            self.logError(ex)      def stream_state_changed(self, state, arg):          """This one is called when the state of stream connecting the component          to a server changes. This will usually be used to let the user          know what is going on.""" -        self.logDebug("pyLoad XMPP: *** State changed: %s %r ***" % (state, arg)) +        self.logDebug("*** State changed: %s %r ***" % (state, arg))      def disconnected(self): -        self.logDebug("pyLoad XMPP: Client was disconnected") +        self.logDebug("Client was disconnected")      def stream_closed(self, stream): -        self.logDebug("pyLoad XMPP: Stream was closed | %s" % stream) +        self.logDebug("Stream was closed", stream)      def stream_error(self, err): -        self.logDebug("pyLoad XMPP: Stream Error: %s" % err) +        self.logDebug("Stream Error", err)      def get_message_handlers(self):          """Return list of (message_type, message_handler) tuples. @@ -113,8 +113,8 @@ class XMPPInterface(IRCInterface, JabberClient):          subject = stanza.get_subject()          body = stanza.get_body()          t = stanza.get_type() -        self.logDebug(u'pyLoad XMPP: Message from %s received.' % (unicode(stanza.get_from(),))) -        self.logDebug(u'pyLoad XMPP: Body: %s Subject: %s Type: %s' % (body, subject, t)) +        self.logDebug("Message from %s received." % unicode(stanza.get_from())) +        self.logDebug("Body: %s Subject: %s Type: %s" % (body, subject, t))          if t == "headline":              # 'headline' messages should never be replied to @@ -158,7 +158,7 @@ class XMPPInterface(IRCInterface, JabberClient):                      messages.append(m)              except Exception, e: -                self.logError("pyLoad XMPP: " + repr(e)) +                self.logError(repr(e))              return messages @@ -171,7 +171,7 @@ class XMPPInterface(IRCInterface, JabberClient):      def announce(self, message):          """ send message to all owners"""          for user in self.getConfig("owners").split(";"): -            self.logDebug("pyLoad XMPP: Send message to %s" % user) +            self.logDebug("Send message to", user)              to_jid = JID(user) | 
