summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-07-19 09:42:34 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-07-19 09:42:34 +0200
commit502517f37c7540b0bddb092e69386d9d6f08800c (patch)
treea90f2143063538f466b0283383a97067f7ea829d /module/plugins/internal
parentImprove fixurl method (diff)
downloadpyload-502517f37c7540b0bddb092e69386d9d6f08800c.tar.xz
Fix addons
Diffstat (limited to 'module/plugins/internal')
-rw-r--r--module/plugins/internal/Account.py3
-rw-r--r--module/plugins/internal/Addon.py242
-rw-r--r--module/plugins/internal/Captcha.py9
-rw-r--r--module/plugins/internal/Extractor.py2
-rw-r--r--module/plugins/internal/Hook.py238
-rw-r--r--module/plugins/internal/MultiHook.py4
-rw-r--r--module/plugins/internal/MultiHoster.py5
-rw-r--r--module/plugins/internal/OCR.py8
-rw-r--r--module/plugins/internal/Plugin.py4
-rw-r--r--module/plugins/internal/SimpleCrypter.py1
-rw-r--r--module/plugins/internal/SimpleHoster.py3
11 files changed, 274 insertions, 245 deletions
diff --git a/module/plugins/internal/Account.py b/module/plugins/internal/Account.py
index 534f5607d..7bf8964ad 100644
--- a/module/plugins/internal/Account.py
+++ b/module/plugins/internal/Account.py
@@ -41,6 +41,9 @@ class Account(Plugin):
def init(self):
+ """
+ Initialize additional data structures
+ """
pass
diff --git a/module/plugins/internal/Addon.py b/module/plugins/internal/Addon.py
new file mode 100644
index 000000000..f3da5272f
--- /dev/null
+++ b/module/plugins/internal/Addon.py
@@ -0,0 +1,242 @@
+# -*- coding: utf-8 -*-
+
+import traceback
+
+from module.plugins.internal.Plugin import Plugin
+
+
+class Expose(object):
+ """
+ Used for decoration to declare rpc services
+ """
+ def __new__(cls, f, *args, **kwargs):
+ hookManager.addRPC(f.__module__, f.func_name, f.func_doc)
+ return f
+
+
+def threaded(fn):
+
+ def run(*args, **kwargs):
+ hookManager.startThread(fn, *args, **kwargs)
+
+ return run
+
+
+class Addon(Plugin):
+ __name__ = "Addon"
+ __type__ = "hook" #@TODO: Change to `addon` in 0.4.10
+ __version__ = "0.01"
+
+ __config__ = [] #: [("name", "type", "desc", "default")]
+ __threaded__ = [] #@TODO: Remove in 0.4.10
+
+ __description__ = """Base addon plugin"""
+ __license__ = "GPLv3"
+ __authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
+
+
+ def __init__(self, core, manager):
+ super(Addon, self).__init__(core)
+
+ #: `HookManager`
+ self.manager = manager
+
+ #: Automatically register event listeners for functions, attribute will be deleted dont use it yourself
+ self.event_map = {}
+
+ #: Deprecated alternative to event_map
+ #: List of events the plugin can handle, name the functions exactly like eventname.
+ self.event_list = [] #@NOTE: dont make duplicate entries in event_map
+
+ #: Callback of periodical job task, used by HookManager
+ self.cb = None
+ self.interval = 60
+
+ self.init()
+ self.init_events()
+
+
+ def init_events(self):
+ if self.event_map:
+ for event, funcs in self.event_map.iteritems():
+ if type(funcs) in (list, tuple):
+ for f in funcs:
+ self.manager.addEvent(event, getattr(self, f))
+ else:
+ self.manager.addEvent(event, getattr(self, funcs))
+
+ #: Delete for various reasons
+ self.event_map = None
+
+ if self.event_list:
+ self.log_debug("Deprecated method `event_list`, use `event_map` instead")
+
+ for f in self.event_list:
+ self.manager.addEvent(f, getattr(self, f))
+
+ self.event_list = None
+
+
+ def init_periodical(self, delay=0, threaded=False):
+ self.cb = self.core.scheduler.addJob(max(0, delay), self._periodical, [threaded], threaded=threaded)
+
+
+ #: Deprecated method, use `init_periodical` instead
+ def initPeriodical(self, *args, **kwargs):
+ return self.init_periodical(*args, **kwargs)
+
+
+ def _periodical(self, threaded):
+ if self.interval < 0:
+ self.cb = None
+ return
+
+ try:
+ self.periodical()
+
+ except Exception, e:
+ self.log_error(_("Error executing addon: %s") % e)
+ if self.core.debug:
+ traceback.print_exc()
+
+ self.cb = self.core.scheduler.addJob(self.interval, self._periodical, [threaded], threaded=threaded)
+
+
+ def periodical(self):
+ pass
+
+
+ def __repr__(self):
+ return "<Addon %s>" % self.__name__
+
+
+ def is_activated(self):
+ """
+ Checks if addon is activated
+ """
+ return self.get_config("activated")
+
+
+ #: Deprecated method, use `is_activated` instead
+ def isActivated(self, *args, **kwargs):
+ return self.is_activated(*args, **kwargs)
+
+
+ def deactivate(self):
+ """
+ Called when addon was deactivated
+ """
+ pass
+
+
+ #: Deprecated method, use `deactivate` instead
+ def unload(self, *args, **kwargs):
+ return self.deactivate(*args, **kwargs)
+
+
+ def activate(self):
+ """
+ Called when addon was activated
+ """
+ pass
+
+
+ #: Deprecated method, use `activate` instead
+ def coreReady(self, *args, **kwargs):
+ return self.activate(*args, **kwargs)
+
+
+ def exit(self):
+ """
+ Called by core.shutdown just before pyLoad exit
+ """
+ pass
+
+
+ #: Deprecated method, use `exit` instead
+ def coreExiting(self, *args, **kwargs):
+ return self.exit(*args, **kwargs)
+
+
+ def download_preparing(self, pyfile):
+ pass
+
+
+ #: Deprecated method, use `download_preparing` instead
+ def downloadPreparing(self, *args, **kwargs):
+ return self.download_preparing(*args, **kwargs)
+
+
+ def download_finished(self, pyfile):
+ pass
+
+
+ #: Deprecated method, use `download_finished` instead
+ def downloadFinished(self, *args, **kwargs):
+ return self.download_finished(*args, **kwargs)
+
+
+ def download_failed(self, pyfile):
+ pass
+
+
+ #: Deprecated method, use `download_failed` instead
+ def downloadFailed(self, *args, **kwargs):
+ return self.download_failed(*args, **kwargs)
+
+
+ def package_finished(self, pypack):
+ pass
+
+
+ #: Deprecated method, use `package_finished` instead
+ def packageFinished(self, *args, **kwargs):
+ return self.package_finished(*args, **kwargs)
+
+
+ def before_reconnect(self, ip):
+ pass
+
+
+ #: Deprecated method, use `before_reconnect` instead
+ def beforeReconnecting(self, *args, **kwargs):
+ return self.before_reconnect(*args, **kwargs)
+
+
+ def after_reconnect(self, ip, oldip):
+ pass
+
+
+ #: Deprecated method, use `after_reconnect` instead
+ def afterReconnecting(self, ip):
+ return self.after_reconnect(ip, None)
+
+
+ def captcha_task(self, task):
+ """
+ New captcha task for the plugin, it MUST set the handler and timeout or will be ignored
+ """
+ pass
+
+
+ #: Deprecated method, use `captcha_task` instead
+ def newCaptchaTask(self, *args, **kwargs):
+ return self.captcha_task(*args, **kwargs)
+
+
+ def captcha_correct(self, task):
+ pass
+
+
+ #: Deprecated method, use `captcha_correct` instead
+ def captchaCorrect(self, *args, **kwargs):
+ return self.captcha_correct(*args, **kwargs)
+
+
+ def captcha_invalid(self, task):
+ pass
+
+
+ #: Deprecated method, use `captcha_invalid` instead
+ def captchaInvalid(self, *args, **kwargs):
+ return self.captcha_invalid(*args, **kwargs)
diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py
index 68d5d3bb8..1309b0d6b 100644
--- a/module/plugins/internal/Captcha.py
+++ b/module/plugins/internal/Captcha.py
@@ -19,6 +19,15 @@ class Captcha(Plugin):
self.plugin = plugin
self.key = None #: Last key detected
+ self.init()
+
+
+ def init(self):
+ """
+ Initialize additional data structures
+ """
+ pass
+
#@TODO: Recheck in 0.4.10
def retrieve_key(self, html):
diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py
index 60d8b3b3b..929ef5378 100644
--- a/module/plugins/internal/Extractor.py
+++ b/module/plugins/internal/Extractor.py
@@ -99,6 +99,8 @@ class Extractor(Plugin):
pyfile = self.manager.core.files.getFile(fid) if fid else None
self.notify_progress = lambda x: pyfile.setProgress(x) if pyfile else lambda x: None
+ self.init()
+
def init(self):
"""
diff --git a/module/plugins/internal/Hook.py b/module/plugins/internal/Hook.py
index 162c9ecbf..a17037a11 100644
--- a/module/plugins/internal/Hook.py
+++ b/module/plugins/internal/Hook.py
@@ -1,34 +1,14 @@
# -*- coding: utf-8 -*-
-import traceback
+from module.plugins.internal.Addon import Addon
-from module.plugins.internal.Plugin import Plugin
-
-class Expose(object):
- """
- Used for decoration to declare rpc services
- """
- def __new__(cls, f, *args, **kwargs):
- hookManager.addRPC(f.__module__, f.func_name, f.func_doc)
- return f
-
-
-def threaded(fn):
-
- def run(*args, **kwargs):
- hookManager.startThread(fn, *args, **kwargs)
-
- return run
-
-
-class Hook(Plugin):
+class Hook(Addon):
__name__ = "Hook"
__type__ = "hook"
- __version__ = "0.09"
+ __version__ = "0.10"
__config__ = [] #: [("name", "type", "desc", "default")]
- __threaded__ = [] #@TODO: Remove in 0.4.10
__description__ = """Base hook plugin"""
__license__ = "GPLv3"
@@ -38,215 +18,5 @@ class Hook(Plugin):
def __init__(self, core, manager):
- super(Hook, self).__init__(core)
-
- #: `HookManager`
- self.manager = manager
-
- #: Automatically register event listeners for functions, attribute will be deleted dont use it yourself
- self.event_map = {}
-
- #: Deprecated alternative to event_map
- #: List of events the plugin can handle, name the functions exactly like eventname.
- self.event_list = [] #@NOTE: dont make duplicate entries in event_map
-
- #: Callback of periodical job task, used by HookManager
- self.cb = None
- self.interval = 60
-
- self.setup()
- self.init_events()
+ super(Hook, self).__init__(core, manager)
self.init_periodical(10)
-
-
- def init_events(self):
- if self.event_map:
- for event, funcs in self.event_map.iteritems():
- if type(funcs) in (list, tuple):
- for f in funcs:
- self.manager.addEvent(event, getattr(self, f))
- else:
- self.manager.addEvent(event, getattr(self, funcs))
-
- #: Delete for various reasons
- self.event_map = None
-
- if self.event_list:
- self.log_debug("Deprecated method `event_list`, use `event_map` instead")
-
- for f in self.event_list:
- self.manager.addEvent(f, getattr(self, f))
-
- self.event_list = None
-
-
- def init_periodical(self, delay=0, threaded=False):
- self.cb = self.core.scheduler.addJob(max(0, delay), self._periodical, [threaded], threaded=threaded)
-
-
- #: Deprecated method, use `init_periodical` instead
- def initPeriodical(self, *args, **kwargs):
- return self.init_periodical(*args, **kwargs)
-
-
- def _periodical(self, threaded):
- if self.interval < 0:
- self.cb = None
- return
-
- try:
- self.periodical()
-
- except Exception, e:
- self.log_error(_("Error executing hook: %s") % e)
- if self.core.debug:
- traceback.print_exc()
-
- self.cb = self.core.scheduler.addJob(self.interval, self._periodical, [threaded], threaded=threaded)
-
-
- def periodical(self):
- pass
-
-
- def __repr__(self):
- return "<Hook %s>" % self.__name__
-
-
- def setup(self):
- """
- More init stuff if needed
- """
- pass
-
-
- def is_activated(self):
- """
- Checks if hook is activated
- """
- return self.get_config("activated")
-
-
- #: Deprecated method, use `is_activated` instead
- def isActivated(self, *args, **kwargs):
- return self.is_activated(*args, **kwargs)
-
-
- def deactivate(self):
- """
- Called when hook was deactivated
- """
- pass
-
-
- #: Deprecated method, use `deactivate` instead
- def unload(self, *args, **kwargs):
- return self.deactivate(*args, **kwargs)
-
-
- def activate(self):
- """
- Called when hook was activated
- """
- pass
-
-
- #: Deprecated method, use `activate` instead
- def coreReady(self, *args, **kwargs):
- return self.activate(*args, **kwargs)
-
-
- def exit(self):
- """
- Called by core.shutdown just before pyLoad exit
- """
- pass
-
-
- #: Deprecated method, use `exit` instead
- def coreExiting(self, *args, **kwargs):
- return self.exit(*args, **kwargs)
-
-
- def download_preparing(self, pyfile):
- pass
-
-
- #: Deprecated method, use `download_preparing` instead
- def downloadPreparing(self, *args, **kwargs):
- return self.download_preparing(*args, **kwargs)
-
-
- def download_finished(self, pyfile):
- pass
-
-
- #: Deprecated method, use `download_finished` instead
- def downloadFinished(self, *args, **kwargs):
- return self.download_finished(*args, **kwargs)
-
-
- def download_failed(self, pyfile):
- pass
-
-
- #: Deprecated method, use `download_failed` instead
- def downloadFailed(self, *args, **kwargs):
- return self.download_failed(*args, **kwargs)
-
-
- def package_finished(self, pypack):
- pass
-
-
- #: Deprecated method, use `package_finished` instead
- def packageFinished(self, *args, **kwargs):
- return self.package_finished(*args, **kwargs)
-
-
- def before_reconnect(self, ip):
- pass
-
-
- #: Deprecated method, use `before_reconnect` instead
- def beforeReconnecting(self, *args, **kwargs):
- return self.before_reconnect(*args, **kwargs)
-
-
- def after_reconnect(self, ip, oldip):
- pass
-
-
- #: Deprecated method, use `after_reconnect` instead
- def afterReconnecting(self, ip):
- return self.after_reconnect(ip, None)
-
-
- def captcha_task(self, task):
- """
- New captcha task for the plugin, it MUST set the handler and timeout or will be ignored
- """
- pass
-
-
- #: Deprecated method, use `captcha_task` instead
- def newCaptchaTask(self, *args, **kwargs):
- return self.captcha_task(*args, **kwargs)
-
-
- def captcha_correct(self, task):
- pass
-
-
- #: Deprecated method, use `captcha_correct` instead
- def captchaCorrect(self, *args, **kwargs):
- return self.captcha_correct(*args, **kwargs)
-
-
- def captcha_invalid(self, task):
- pass
-
-
- #: Deprecated method, use `captcha_invalid` instead
- def captchaInvalid(self, *args, **kwargs):
- return self.captcha_invalid(*args, **kwargs)
diff --git a/module/plugins/internal/MultiHook.py b/module/plugins/internal/MultiHook.py
index 4a43e89c7..127d83ab5 100644
--- a/module/plugins/internal/MultiHook.py
+++ b/module/plugins/internal/MultiHook.py
@@ -11,7 +11,7 @@ from module.utils import decode, remove_chars
class MultiHook(Hook):
__name__ = "MultiHook"
__type__ = "hook"
- __version__ = "0.50"
+ __version__ = "0.51"
__config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"),
("pluginlist" , "str" , "Plugin list (comma separated)", "" ),
@@ -54,7 +54,7 @@ class MultiHook(Hook):
(r'^0' , "zero" )]
- def setup(self):
+ def init(self):
self.plugins = []
self.supported = []
self.new_supported = []
diff --git a/module/plugins/internal/MultiHoster.py b/module/plugins/internal/MultiHoster.py
index 363d46739..7bba2f6d3 100644
--- a/module/plugins/internal/MultiHoster.py
+++ b/module/plugins/internal/MultiHoster.py
@@ -30,9 +30,8 @@ class MultiHoster(SimpleHoster):
def prepare(self):
- self.info = {}
- self.html = ""
- self.link = "" #@TODO: Move to Hoster in 0.4.10
+ self.html = ""
+ self.link = "" #@TODO: Move to Hoster in 0.4.10
self.direct_dl = False #@TODO: Move to Hoster in 0.4.10
if not self.get_config('use_premium', True):
diff --git a/module/plugins/internal/OCR.py b/module/plugins/internal/OCR.py
index 9ddca0315..387db1d13 100644
--- a/module/plugins/internal/OCR.py
+++ b/module/plugins/internal/OCR.py
@@ -29,6 +29,14 @@ class OCR(Plugin):
def __init__(self):
self.logger = logging.getLogger("log")
+ self.init()
+
+
+ def init(self):
+ """
+ Initialize additional data structures
+ """
+ pass
def load_image(self, image):
diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py
index 93dd2ecbe..d0f75a8a3 100644
--- a/module/plugins/internal/Plugin.py
+++ b/module/plugins/internal/Plugin.py
@@ -122,9 +122,7 @@ class Plugin(object):
def __init__(self, core):
self.core = core
-
- #: Provide information in dict here
- self.info = {}
+ self.info = {} #: Provide information in dict here
def _log(self, level, args):
diff --git a/module/plugins/internal/SimpleCrypter.py b/module/plugins/internal/SimpleCrypter.py
index 82f5ef332..cd447db6b 100644
--- a/module/plugins/internal/SimpleCrypter.py
+++ b/module/plugins/internal/SimpleCrypter.py
@@ -66,7 +66,6 @@ class SimpleCrypter(Crypter, SimpleHoster):
def prepare(self):
self.pyfile.error = "" #@TODO: Remove in 0.4.10
- self.info = {}
self.html = "" #@TODO: Recheck in 0.4.10
self.link = "" #@TODO: Recheck in 0.4.10
self.links = []
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py
index 5bf2f0417..911a7d411 100644
--- a/module/plugins/internal/SimpleHoster.py
+++ b/module/plugins/internal/SimpleHoster.py
@@ -204,10 +204,9 @@ class SimpleHoster(Hoster):
def prepare(self):
self.pyfile.error = "" #@TODO: Remove in 0.4.10
- self.info = {}
self.html = "" #@TODO: Recheck in 0.4.10
self.link = "" #@TODO: Recheck in 0.4.10
- self.direct_dl = False
+ self.direct_dl = False
self.multihost = False
if not self.get_config('use_premium', True):