summaryrefslogtreecommitdiffstats
path: root/pyload
diff options
context:
space:
mode:
Diffstat (limited to 'pyload')
-rw-r--r--pyload/Core.py3
-rw-r--r--pyload/FileManager.py2
-rw-r--r--pyload/PluginManager.py2
-rw-r--r--pyload/plugins/Addon.py15
-rw-r--r--pyload/plugins/Base.py3
-rw-r--r--pyload/plugins/Crypter.py27
-rw-r--r--pyload/plugins/Hoster.py2
-rw-r--r--pyload/plugins/addons/ClickAndLoad.py18
-rw-r--r--pyload/plugins/addons/ExternalScripts.py27
-rw-r--r--pyload/plugins/addons/ExtractArchive.py2
-rw-r--r--pyload/threads/DecrypterThread.py64
-rw-r--r--pyload/threads/InfoThread.py1
-rw-r--r--pyload/utils/__init__.py2
13 files changed, 87 insertions, 81 deletions
diff --git a/pyload/Core.py b/pyload/Core.py
index 3c56e2afe..328a25c94 100644
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -384,6 +384,7 @@ class Core(object):
self.api = Api(self)
self.scheduler = Scheduler(self)
+ self.js = JsEngine()
#hell yeah, so many important managers :D
self.pluginManager = PluginManager(self)
@@ -393,8 +394,6 @@ class Core(object):
self.addonManager = AddonManager(self)
self.remoteManager = RemoteManager(self)
- self.js = JsEngine()
-
# enough initialization for test cases
if tests: return
diff --git a/pyload/FileManager.py b/pyload/FileManager.py
index 61c164316..05f665135 100644
--- a/pyload/FileManager.py
+++ b/pyload/FileManager.py
@@ -489,7 +489,7 @@ class FileManager:
files = [self.getFileInfo(fid) for fid in fids]
orders = [f.fileorder for f in files]
if min(orders) + len(files) != max(orders) + 1:
- raise Exception("Tried to reorder non continous block of files")
+ raise Exception("Tried to reorder non continuous block of files")
# minimum fileorder
f = reduce(lambda x,y: x if x.fileorder < y.fileorder else y, files)
diff --git a/pyload/PluginManager.py b/pyload/PluginManager.py
index b6e4ed977..ea0515999 100644
--- a/pyload/PluginManager.py
+++ b/pyload/PluginManager.py
@@ -208,6 +208,8 @@ class PluginManager:
if name not in sys.modules: #could be already in modules
# TODO: only temporary
+ # TODO: strange side effects are caused by this workaround
+ # e.g a class instance is not associated correctly with its on instance because of wrong module names
if name.endswith("module"):
# name = "pyload."
name = name.replace(".module", "")
diff --git a/pyload/plugins/Addon.py b/pyload/plugins/Addon.py
index 5c27fa983..da5bbc1d7 100644
--- a/pyload/plugins/Addon.py
+++ b/pyload/plugins/Addon.py
@@ -97,9 +97,6 @@ class Addon(Base):
"""
- #: automatically register event listeners for functions, attribute will be deleted don't use it yourself
- event_map = None
-
#: periodic call interval in seconds
interval = 0
@@ -112,18 +109,6 @@ class Addon(Base):
#: `AddonManager`
self.manager = manager
- #register events
- if self.event_map:
- for event, funcs in self.event_map.iteritems():
- if type(funcs) in (list, tuple):
- for f in funcs:
- self.evm.listenTo(event, getattr(self, f))
- else:
- self.evm.listenTo(event, getattr(self, funcs))
-
- #delete for various reasons
- self.event_map = None
-
self.init()
# start periodically if set
diff --git a/pyload/plugins/Base.py b/pyload/plugins/Base.py
index ae8614b0d..b6668ea90 100644
--- a/pyload/plugins/Base.py
+++ b/pyload/plugins/Base.py
@@ -105,6 +105,9 @@ class Base(object):
#: last interaction task
self.task = None
+ #: js engine, see `JsEngine`
+ self.js = self.core.js
+
def __getitem__(self, item):
""" Retrieves meta data attribute """
return getattr(self, "__%s__" % item)
diff --git a/pyload/plugins/Crypter.py b/pyload/plugins/Crypter.py
index af3d5aba7..fcea1263a 100644
--- a/pyload/plugins/Crypter.py
+++ b/pyload/plugins/Crypter.py
@@ -48,8 +48,8 @@ class Package:
return self.name == other.name and self.links == other.links
def __repr__(self):
- return u"<CrypterPackage name=%s, links=[%s], packs=%s" % (self.name, ",".join(str(l) for l in self.links),
- self.packs)
+ return u"<CrypterPackage name=%s, links=[%s], packs=%s>" % (self.name, ", ".join(str(l) for l in self.links),
+ self.packs)
def __hash__(self):
return hash(self.name) ^ hash(frozenset(self.links)) ^ hash(self.name)
@@ -58,14 +58,20 @@ class Package:
class PyFileMockup:
""" Legacy class needed by old crypter plugins """
- def __init__(self, url, pack):
+ def __init__(self, url, pack_name):
self.url = url
self.name = url
- self._package = None
- self.packageid = pack.id if pack else -1
+ self.packageid = -1
+ self.pack_name = pack_name + " Package"
def package(self):
- return self._package
+ # mockes the pyfile package
+ class PyPackage:
+ def __init__(self, f):
+ self.name = f.pack_name
+ self.folder = self.name
+
+ return PyPackage(self)
class Crypter(Base):
@@ -145,6 +151,7 @@ class Crypter(Base):
#: Password supplied by user
self.password = password
+ # TODO: removed in future
# For old style decrypter, do not use these!
self.packages = []
self.urls = []
@@ -201,7 +208,7 @@ class Crypter(Base):
self.logDebug("Deprecated .decrypt() method in Crypter plugin")
result = []
for url in urls:
- self.pyfile = PyFileMockup(url)
+ self.pyfile = PyFileMockup(url, cls.__name__)
self.setup()
self.decrypt(self.pyfile)
result.extend(self.convertPackages())
@@ -276,7 +283,11 @@ class Crypter(Base):
def convertPackages(self):
""" Deprecated """
self.logDebug("Deprecated method .convertPackages()")
- res = [Package(name, urls) for name, urls in self.packages]
+ res = []
+ for pack in self.packages:
+ # only use name and urls
+ res.append(Package(pack[0], pack[1]))
+
res.extend(self.urls)
return res
diff --git a/pyload/plugins/Hoster.py b/pyload/plugins/Hoster.py
index 6bfe47e1f..68eb32baa 100644
--- a/pyload/plugins/Hoster.py
+++ b/pyload/plugins/Hoster.py
@@ -89,8 +89,6 @@ class Hoster(Base):
self.lastDownload = ""
#: re match of the last call to `checkDownload`
self.lastCheck = None
- #: js engine, see `JsEngine`
- self.js = self.core.js
self.retries = 0 # amount of retries already made
self.html = None # some plugins store html code here
diff --git a/pyload/plugins/addons/ClickAndLoad.py b/pyload/plugins/addons/ClickAndLoad.py
index 0fc78abfe..0d9538543 100644
--- a/pyload/plugins/addons/ClickAndLoad.py
+++ b/pyload/plugins/addons/ClickAndLoad.py
@@ -21,10 +21,9 @@
import socket
import thread
-from module.plugins.Hook import Hook
+from pyload.plugins.Addon import Addon
-
-class ClickAndLoad(Hook):
+class ClickAndLoad(Addon):
__name__ = "ClickAndLoad"
__version__ = "0.22"
__description__ = """Gives abillity to use jd's click and load. depends on webinterface"""
@@ -36,15 +35,12 @@ class ClickAndLoad(Hook):
def coreReady(self):
self.port = int(self.config['webinterface']['port'])
if self.config['webinterface']['activated']:
- try:
- if self.getConfig("extern"):
- ip = "0.0.0.0"
- else:
- ip = "127.0.0.1"
+ if self.getConfig("extern"):
+ ip = "0.0.0.0"
+ else:
+ ip = "127.0.0.1"
- thread.start_new_thread(proxy, (self, ip, self.port, 9666))
- except:
- self.logError("ClickAndLoad port already in use.")
+ thread.start_new_thread(proxy, (self, ip, self.port, 9666))
def proxy(self, *settings):
diff --git a/pyload/plugins/addons/ExternalScripts.py b/pyload/plugins/addons/ExternalScripts.py
index b1a9420bb..2a95a7af0 100644
--- a/pyload/plugins/addons/ExternalScripts.py
+++ b/pyload/plugins/addons/ExternalScripts.py
@@ -20,13 +20,14 @@
import subprocess
from os import listdir, access, X_OK, makedirs
-from os.path import join, exists, basename
+from os.path import join, exists, basename, abspath
-from module.plugins.Hook import Hook
-from module.utils import save_join
+from pyload.plugins.Addon import Addon, AddEventListener
+from pyload.utils.fs import safe_join
-class ExternalScripts(Hook):
+
+class ExternalScripts(Addon):
__name__ = "ExternalScripts"
__version__ = "0.23"
__description__ = """Run external scripts"""
@@ -34,13 +35,12 @@ class ExternalScripts(Hook):
__author_name__ = ("mkaay", "RaNaN", "spoob")
__author_mail__ = ("mkaay@mkaay.de", "ranan@pyload.org", "spoob@pyload.org")
- event_list = ["unrarFinished", "allDownloadsFinished", "allDownloadsProcessed"]
- def setup(self):
+ def activate(self):
self.scripts = {}
folders = ['download_preparing', 'download_finished', 'package_finished',
- 'before_reconnect', 'after_reconnect', 'unrar_finished',
+ 'before_reconnect', 'after_reconnect', 'extracting_finished',
'all_dls_finished', 'all_dls_processed']
for folder in folders:
@@ -73,7 +73,7 @@ class ExternalScripts(Hook):
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": os.path.abspath(script), "cmd": " ".join(cmd)})
+ self.logDebug("Executing %(script)s: %(cmd)s" % {"script": abspath(script), "cmd": " ".join(cmd)})
#output goes to pyload
subprocess.Popen(cmd, bufsize=-1)
except Exception, e:
@@ -86,13 +86,13 @@ class ExternalScripts(Hook):
def downloadFinished(self, pyfile):
for script in self.scripts['download_finished']:
self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.name,
- save_join(self.config['general']['download_folder'],
+ safe_join(self.config['general']['download_folder'],
pyfile.package().folder, pyfile.name), pyfile.id)
def packageFinished(self, pypack):
for script in self.scripts['package_finished']:
folder = self.config['general']['download_folder']
- folder = save_join(folder, pypack.folder)
+ folder = safe_join(folder, pypack.folder)
self.callScript(script, pypack.name, folder, pypack.password, pypack.id)
@@ -104,14 +104,17 @@ class ExternalScripts(Hook):
for script in self.scripts['after_reconnect']:
self.callScript(script, ip)
- def unrarFinished(self, folder, fname):
- for script in self.scripts["unrar_finished"]:
+ @AddEventListener("extracting:finished")
+ def extractingFinished(self, folder, fname):
+ for script in self.scripts["extracting_finished"]:
self.callScript(script, folder, fname)
+ @AddEventListener("download:allFinished")
def allDownloadsFinished(self):
for script in self.scripts["all_dls_finished"]:
self.callScript(script)
+ @AddEventListener("download:allProcessed")
def allDownloadsProcessed(self):
for script in self.scripts["all_dls_processed"]:
self.callScript(script)
diff --git a/pyload/plugins/addons/ExtractArchive.py b/pyload/plugins/addons/ExtractArchive.py
index 62c947f88..9a66f13c7 100644
--- a/pyload/plugins/addons/ExtractArchive.py
+++ b/pyload/plugins/addons/ExtractArchive.py
@@ -254,7 +254,7 @@ class ExtractArchive(Addon):
self.logDebug("%s does not exists" % f)
self.logInfo(basename(plugin.file), _("Extracting finished"))
- self.manager.dispatchEvent("unrarFinished", plugin.out, plugin.file)
+ self.manager.dispatchEvent("extracting:finished", plugin.out, plugin.file)
return plugin.getExtractedFiles()
diff --git a/pyload/threads/DecrypterThread.py b/pyload/threads/DecrypterThread.py
index 22a2d0037..10d47fcc2 100644
--- a/pyload/threads/DecrypterThread.py
+++ b/pyload/threads/DecrypterThread.py
@@ -42,51 +42,61 @@ class DecrypterThread(BaseThread):
for name, urls in plugin_map.iteritems():
klass = self.m.core.pluginManager.loadClass("crypter", name)
- plugin = klass(self.m.core, password)
+ plugin = None
plugin_result = []
- try:
+ #TODO: dependency check, there is a new error code for this
+ if not klass:
+ plugin_result.extend(LinkStatus(url, url, -1, DS.NotPossible, name) for url in urls)
+ self.log.debug("Plugin for decrypting was not loaded")
+ else:
try:
- plugin_result = plugin._decrypt(urls)
- except Retry:
- sleep(1)
- plugin_result = plugin._decrypt(urls)
- except Abort:
- plugin.logInfo(_("Decrypting aborted"))
- except Exception, e:
- plugin.logError(_("Decrypting failed"), e)
-
- # generate error linkStatus
- if err:
- plugin_result.extend(LinkStatus(url, url, -1, DS.Failed, name) for url in urls)
-
- if self.core.debug:
- self.core.print_exc()
- self.writeDebugReport(plugin.__name__, plugin=plugin)
- finally:
- plugin.clean()
-
- plugin.logDebug("Decrypted", plugin_result)
+ plugin = klass(self.m.core, password)
+
+ try:
+ plugin_result = plugin._decrypt(urls)
+ except Retry:
+ sleep(1)
+ plugin_result = plugin._decrypt(urls)
+
+ plugin.logDebug("Decrypted", plugin_result)
+
+ except Abort:
+ plugin.logInfo(_("Decrypting aborted"))
+ except Exception, e:
+ plugin.logError(_("Decrypting failed"), e)
+
+ # generate error linkStatus
+ if err:
+ plugin_result.extend(LinkStatus(url, url, -1, DS.Failed, name) for url in urls)
+
+ if self.core.debug:
+ self.core.print_exc()
+ self.writeDebugReport(plugin.__name__, plugin=plugin)
+ finally:
+ if plugin:
+ plugin.clean()
+
result.extend(plugin_result)
# generated packages
- pack_names = {}
+ packs = {}
# urls without package
urls = []
# merge urls and packages
for p in result:
if isinstance(p, Package):
- if p.name in pack_names:
- pack_names[p.name].urls.extend(p.urls)
+ if p.name in packs:
+ packs[p.name].urls.extend(p.urls)
else:
if not p.name:
urls.extend(p.links)
else:
- pack_names[p.name] = p
+ packs[p.name] = p
else:
urls.append(p)
urls = uniqify(urls)
- return urls, pack_names.values() \ No newline at end of file
+ return urls, packs.values() \ No newline at end of file
diff --git a/pyload/threads/InfoThread.py b/pyload/threads/InfoThread.py
index 62e309020..8d33df705 100644
--- a/pyload/threads/InfoThread.py
+++ b/pyload/threads/InfoThread.py
@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from time import time
-from traceback import print_exc
from pyload.Api import LinkStatus, DownloadStatus
from pyload.utils.packagetools import parseNames
diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py
index 577213dd1..09fb76229 100644
--- a/pyload/utils/__init__.py
+++ b/pyload/utils/__init__.py
@@ -64,7 +64,7 @@ def compare_time(start, end):
else: return False
def to_list(value):
- return value if type(value) == list else ([value] if value is not None else [])
+ return value if type(value) == list else list(value) if type(value) == set else ([value] if value is not None else [])
def formatSize(size):
print "Deprecated formatSize, use format_size"