diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-14 03:17:03 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-27 20:52:34 +0100 |
commit | 65fc05e88db6af85a6a4e5ac5f6c22d41270a48b (patch) | |
tree | 3fad449f10ba75801c1df28228c270826fb216f9 /module | |
parent | [XFileSharing] regexp hotfix (diff) | |
download | pyload-65fc05e88db6af85a6a4e5ac5f6c22d41270a48b.tar.xz |
Update notifiers
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/hooks/AndroidPhoneNotify.py | 27 | ||||
-rw-r--r-- | module/plugins/hooks/PushBullet.py | 27 | ||||
-rw-r--r-- | module/plugins/hooks/PushOver.py | 29 | ||||
-rw-r--r-- | module/plugins/hooks/WindowsPhoneNotify.py | 29 | ||||
-rw-r--r-- | module/plugins/internal/Notifier.py | 116 |
5 files changed, 142 insertions, 86 deletions
diff --git a/module/plugins/hooks/AndroidPhoneNotify.py b/module/plugins/hooks/AndroidPhoneNotify.py index cc7fe8d6b..5a5188365 100644 --- a/module/plugins/hooks/AndroidPhoneNotify.py +++ b/module/plugins/hooks/AndroidPhoneNotify.py @@ -6,19 +6,22 @@ from module.plugins.internal.Notifier import Notifier class AndroidPhoneNotify(Notifier): __name__ = "AndroidPhoneNotify" __type__ = "hook" - __version__ = "0.13" + __version__ = "0.15" __status__ = "testing" - __config__ = [("activated" , "bool", "Activated" , False), - ("apikey" , "str" , "API key" , "" ), - ("notifycaptcha" , "bool", "Notify captcha request" , True ), - ("notifypackage" , "bool", "Notify package finished" , True ), - ("notifyprocessed", "bool", "Notify packages processed" , True ), - ("notifyupdate" , "bool", "Notify plugin updates" , True ), - ("notifyexit" , "bool", "Notify pyLoad shutdown" , True ), - ("sendtimewait" , "int" , "Timewait in seconds between notifications", 5 ), - ("sendpermin" , "int" , "Max notifications per minute" , 12 ), - ("ignoreclient" , "bool", "Send notifications if client is connected", False)] + __config__ = [("activated" , "bool", "Activated" , False), + ("apikey" , "str" , "API key" , "" ), + ("captcha" , "bool", "Notify captcha request" , True ), + ("reconnection" , "bool", "Notify reconnection request" , False), + ("downloadfinished", "bool", "Notify download finished" , True ), + ("downloadfailed" , "bool", "Notify download failed" , True ), + ("packagefinished" , "bool", "Notify package finished" , True ), + ("packagefailed" , "bool", "Notify package failed" , True ), + ("update" , "bool", "Notify pyLoad update" , False), + ("exit" , "bool", "Notify pyLoad shutdown/restart" , False), + ("sendinterval" , "int" , "Interval in seconds between notifications", 1 ), + ("sendpermin" , "int" , "Max notifications per minute" , 60 ), + ("ignoreclient" , "bool", "Send notifications if client is connected", True )] __description__ = """Send push notifications to your Android Phone using notifymyandroid.com""" __license__ = "GPLv3" @@ -27,7 +30,7 @@ class AndroidPhoneNotify(Notifier): def get_key(self): - return self.get_config('apikey') + return self.config.get('apikey') def send(self, event, msg, key): diff --git a/module/plugins/hooks/PushBullet.py b/module/plugins/hooks/PushBullet.py index 6cf7dc173..47a0f594e 100644 --- a/module/plugins/hooks/PushBullet.py +++ b/module/plugins/hooks/PushBullet.py @@ -9,19 +9,22 @@ from module.plugins.internal.Notifier import Notifier class PushBullet(Notifier): __name__ = "PushBullet" __type__ = "hook" - __version__ = "0.02" + __version__ = "0.04" __status__ = "testing" - __config__ = [("activated" , "bool", "Activated" , False), - ("tokenkey" , "str" , "Access Token" , "" ), - ("notifycaptcha" , "bool", "Notify captcha request" , True ), - ("notifypackage" , "bool", "Notify package finished" , True ), - ("notifyprocessed", "bool", "Notify packages processed" , True ), - ("notifyupdate" , "bool", "Notify plugin updates" , True ), - ("notifyexit" , "bool", "Notify pyLoad shutdown" , True ), - ("sendtimewait" , "int" , "Timewait in seconds between notifications", 5 ), - ("sendpermin" , "int" , "Max notifications per minute" , 12 ), - ("ignoreclient" , "bool", "Send notifications if client is connected", False)] + __config__ = [("activated" , "bool", "Activated" , False), + ("tokenkey" , "str" , "Access Token" , "" ), + ("captcha" , "bool", "Notify captcha request" , True ), + ("reconnection" , "bool", "Notify reconnection request" , False), + ("downloadfinished", "bool", "Notify download finished" , True ), + ("downloadfailed" , "bool", "Notify download failed" , True ), + ("packagefinished" , "bool", "Notify package finished" , True ), + ("packagefailed" , "bool", "Notify package failed" , True ), + ("update" , "bool", "Notify pyLoad update" , False), + ("exit" , "bool", "Notify pyLoad shutdown/restart" , False), + ("sendinterval" , "int" , "Interval in seconds between notifications", 1 ), + ("sendpermin" , "int" , "Max notifications per minute" , 60 ), + ("ignoreclient" , "bool", "Send notifications if client is connected", True )] __description__ = """Send push notifications to your phone using pushbullet.com""" __license__ = "GPLv3" @@ -29,7 +32,7 @@ class PushBullet(Notifier): def get_key(self): - return self.get_config('tokenkey') + return self.config.get('tokenkey') def send(self, event, msg, key): diff --git a/module/plugins/hooks/PushOver.py b/module/plugins/hooks/PushOver.py index 5d5e927ac..418f7a133 100644 --- a/module/plugins/hooks/PushOver.py +++ b/module/plugins/hooks/PushOver.py @@ -8,20 +8,23 @@ from module.plugins.internal.Notifier import Notifier class PushOver(Notifier): __name__ = "PushOver" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.06" __status__ = "testing" - __config__ = [("activated" , "bool", "Activated" , False), - ("tokenkey" , "str" , "Token key" , "" ), - ("userkey" , "str" , "User key" , "" ), - ("notifycaptcha" , "bool", "Notify captcha request" , True ), - ("notifypackage" , "bool", "Notify package finished" , True ), - ("notifyprocessed", "bool", "Notify packages processed" , True ), - ("notifyupdate" , "bool", "Notify plugin updates" , True ), - ("notifyexit" , "bool", "Notify pyLoad shutdown" , True ), - ("sendtimewait" , "int" , "Timewait in seconds between notifications", 5 ), - ("sendpermin" , "int" , "Max notifications per minute" , 12 ), - ("ignoreclient" , "bool", "Send notifications if client is connected", False)] + __config__ = [("activated" , "bool", "Activated" , False), + ("tokenkey" , "str" , "Token key" , "" ), + ("userkey" , "str" , "User key" , "" ), + ("captcha" , "bool", "Notify captcha request" , True ), + ("reconnection" , "bool", "Notify reconnection request" , False), + ("downloadfinished", "bool", "Notify download finished" , True ), + ("downloadfailed" , "bool", "Notify download failed" , True ), + ("packagefinished" , "bool", "Notify package finished" , True ), + ("packagefailed" , "bool", "Notify package failed" , True ), + ("update" , "bool", "Notify pyLoad update" , False), + ("exit" , "bool", "Notify pyLoad shutdown/restart" , False), + ("sendinterval" , "int" , "Interval in seconds between notifications", 1 ), + ("sendpermin" , "int" , "Max notifications per minute" , 60 ), + ("ignoreclient" , "bool", "Send notifications if client is connected", True )] __description__ = """Send push notifications to your phone using pushover.net""" __license__ = "GPLv3" @@ -29,7 +32,7 @@ class PushOver(Notifier): def get_key(self): - return self.get_config('tokenkey'), self.get_config('userkey') + return self.config.get('tokenkey'), self.config.get('userkey') def send(self, event, msg, key): diff --git a/module/plugins/hooks/WindowsPhoneNotify.py b/module/plugins/hooks/WindowsPhoneNotify.py index cd5f5dea4..84d122811 100644 --- a/module/plugins/hooks/WindowsPhoneNotify.py +++ b/module/plugins/hooks/WindowsPhoneNotify.py @@ -9,20 +9,23 @@ from module.plugins.internal.Notifier import Notifier class WindowsPhoneNotify(Notifier): __name__ = "WindowsPhoneNotify" __type__ = "hook" - __version__ = "0.15" + __version__ = "0.17" __status__ = "testing" - __config__ = [("activated" , "bool", "Activated" , False), - ("push-id" , "str" , "Push ID" , "" ), - ("push-url" , "str" , "Push url" , "" ), - ("notifycaptcha" , "bool", "Notify captcha request" , True ), - ("notifypackage" , "bool", "Notify package finished" , True ), - ("notifyprocessed", "bool", "Notify packages processed" , True ), - ("notifyupdate" , "bool", "Notify plugin updates" , True ), - ("notifyexit" , "bool", "Notify pyLoad shutdown" , True ), - ("sendtimewait" , "int" , "Timewait in seconds between notifications", 5 ), - ("sendpermin" , "int" , "Max notifications per minute" , 12 ), - ("ignoreclient" , "bool", "Send notifications if client is connected", False)] + __config__ = [("activated" , "bool", "Activated" , False), + ("pushid" , "str" , "Push ID" , "" ), + ("pushurl" , "str" , "Push url" , "" ), + ("captcha" , "bool", "Notify captcha request" , True ), + ("reconnection" , "bool", "Notify reconnection request" , False), + ("downloadfinished", "bool", "Notify download finished" , True ), + ("downloadfailed" , "bool", "Notify download failed" , True ), + ("packagefinished" , "bool", "Notify package finished" , True ), + ("packagefailed" , "bool", "Notify package failed" , True ), + ("update" , "bool", "Notify pyLoad update" , False), + ("exit" , "bool", "Notify pyLoad shutdown/restart" , False), + ("sendinterval" , "int" , "Interval in seconds between notifications", 1 ), + ("sendpermin" , "int" , "Max notifications per minute" , 60 ), + ("ignoreclient" , "bool", "Send notifications if client is connected", True )] __description__ = """Send push notifications to Windows Phone""" __license__ = "GPLv3" @@ -31,7 +34,7 @@ class WindowsPhoneNotify(Notifier): def get_key(self): - return self.get_config('push-id'), self.get_config('push-url') + return self.config.get('pushid'), self.config.get('pushurl') def format_request(self, msg): diff --git a/module/plugins/internal/Notifier.py b/module/plugins/internal/Notifier.py index d0fd28906..2cffb6ac1 100644 --- a/module/plugins/internal/Notifier.py +++ b/module/plugins/internal/Notifier.py @@ -2,25 +2,28 @@ import time -from module.plugins.internal.Addon import Addon, Expose -from module.plugins.internal.utils import isiterable +from module.plugins.internal.Addon import Addon +from module.plugins.internal.misc import Expose, encode, isiterable class Notifier(Addon): __name__ = "Notifier" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.07" __status__ = "testing" - __config__ = [("activated" , "bool", "Activated" , False), - ("notifycaptcha" , "bool", "Notify captcha request" , True ), - ("notifypackage" , "bool", "Notify package finished" , True ), - ("notifyprocessed", "bool", "Notify packages processed" , True ), - ("notifyupdate" , "bool", "Notify plugin updates" , True ), - ("notifyexit" , "bool", "Notify pyLoad shutdown" , True ), - ("sendtimewait" , "int" , "Timewait in seconds between notifications", 5 ), - ("sendpermin" , "int" , "Max notifications per minute" , 12 ), - ("ignoreclient" , "bool", "Send notifications if client is connected", False)] + __config__ = [("activated" , "bool", "Activated" , False), + ("captcha" , "bool", "Notify captcha request" , True ), + ("reconnection" , "bool", "Notify reconnection request" , False), + ("downloadfinished", "bool", "Notify download finished" , True ), + ("downloadfailed" , "bool", "Notify download failed" , True ), + ("packagefinished" , "bool", "Notify package finished" , True ), + ("packagefailed" , "bool", "Notify package failed" , True ), + ("update" , "bool", "Notify pyLoad update" , False), + ("exit" , "bool", "Notify pyLoad shutdown/restart" , False), + ("sendinterval" , "int" , "Interval in seconds between notifications", 1 ), + ("sendpermin" , "int" , "Max notifications per minute" , 60 ), + ("ignoreclient" , "bool", "Send notifications if client is connected", True )] __description__ = """Base notifier plugin""" __license__ = "GPLv3" @@ -29,21 +32,29 @@ class Notifier(Addon): def init(self): self.event_map = {'allDownloadsProcessed': "all_downloads_processed", - 'plugin_updated' : "plugin_updated" } + 'pyload_updated' : "pyload_updated" } self.last_notify = 0 self.notifications = 0 - def plugin_updated(self, type_plugins): - if not self.get_config('notifyupdate'): + def get_key(self): + raise NotImplementedError + + + def send(self, event, msg, key): + raise NotImplementedError + + + def pyload_updated(self, etag): + if not self.config.get('update', True): return - self.notify(_("Plugins updated"), str(type_plugins)) + self.notify(_("pyLoad updated"), etag) def exit(self): - if not self.get_config('notifyexit'): + if not self.config.get('exit', True): return if self.pyload.do_restart: @@ -53,65 +64,98 @@ class Notifier(Addon): def captcha_task(self, task): - if not self.get_config('notifycaptcha'): + if not self.config.get('captcha', True): return self.notify(_("Captcha"), _("New request waiting user input")) + def before_reconnect(self, ip): + if not self.config.get('reconnection', False): + return + + self.notify(_("Waiting reconnection"), _("Current IP: %s") % ip) + + + def after_reconnect(self, ip, oldip): + if not self.config.get('reconnection', False): + return + + self.notify(_("Reconnection failed"), _("Current IP: %s") % ip) + + def package_finished(self, pypack): - if self.get_config('notifypackage'): - self.notify(_("Package finished"), pypack.name) + if not self.config.get('packagefinished', True): + return + self.notify(_("Package finished"), pypack.name) - def all_downloads_processed(self): - if not self.get_config('notifyprocessed'): + + def package_failed(self, pypack): + if not self.config.get('packagefailed', True): return - if any(True for pdata in self.pyload.api.getQueue() if pdata.linksdone < pdata.linkstotal): - self.notify(_("Package failed"), _("One or more packages was not completed successfully")) - else: - self.notify(_("All packages finished")) + self.notify(_("Package failed"), pypack.name) - def get_key(self): - raise NotImplementedError + def download_finished(self, pyfile): + if not self.config.get('downloadfinished', False): + return + self.notify(_("Download finished"), pyfile.name) - def send(self, event, msg, key): - raise NotImplementedError + + def download_failed(self, pyfile): + if self.config.get('downloadfailed', True): + return + + self.notify(_("Download failed"), pyfile.name) + + + def all_downloads_processed(self): + self.notify(_("All downloads processed")) + + + def all_downloads_finished(self): + self.notify(_("All downloads finished")) @Expose - def notify(self, event, msg="", key=None): + def notify(self, event, msg=None, key=None): key = key or self.get_key() if not key or isiterable(key) and not all(key): return - if self.pyload.isClientConnected() and not self.get_config('ignoreclient'): + if isiterable(msg): + msg = " | ".join(encode(a).strip() for a in msg if a) + else: + msg = encode(msg) + + if self.pyload.isClientConnected() and not self.config.get('ignoreclient', False): return elapsed_time = time.time() - self.last_notify - if elapsed_time < self.get_config("sendtimewait"): + if elapsed_time < self.config.get("sendinterval", 1): return elif elapsed_time > 60: self.notifications = 0 - elif self.notifications >= self.get_config("sendpermin"): + elif self.notifications >= self.config.get("sendpermin", 60): return - self.log_info(_("Sending notification...")) + self.log_debug("Sending notification...") try: - resp = self.send(event, msg, key) + self.send(event, msg, key) except Exception, e: self.log_error(_("Error sending notification"), e) return False else: + self.log_debug("Notification sent") return True finally: |