diff options
Diffstat (limited to 'pyload/plugins/hooks/ExternalScripts.py')
-rw-r--r-- | pyload/plugins/hooks/ExternalScripts.py | 75 |
1 files changed, 54 insertions, 21 deletions
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) |