summaryrefslogtreecommitdiffstats
path: root/pyload/plugin/addon/WindowsPhoneNotify.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/plugin/addon/WindowsPhoneNotify.py')
-rw-r--r--pyload/plugin/addon/WindowsPhoneNotify.py93
1 files changed, 64 insertions, 29 deletions
diff --git a/pyload/plugin/addon/WindowsPhoneNotify.py b/pyload/plugin/addon/WindowsPhoneNotify.py
index b9710c2f0..e61057f9f 100644
--- a/pyload/plugin/addon/WindowsPhoneNotify.py
+++ b/pyload/plugin/addon/WindowsPhoneNotify.py
@@ -1,57 +1,75 @@
# -*- coding: utf-8 -*-
import httplib
+import time
-from time import time
+from module.plugins.Hook import Hook, Expose
-from pyload.plugin.Addon import Addon
-
-class WindowsPhoneNotify(Addon):
+class WindowsPhoneNotify(Hook):
__name__ = "WindowsPhoneNotify"
- __type__ = "addon"
- __version__ = "0.07"
+ __type__ = "hook"
+ __version__ = "0.09"
__config__ = [("id" , "str" , "Push ID" , "" ),
("url" , "str" , "Push url" , "" ),
("notifycaptcha" , "bool", "Notify captcha request" , True ),
("notifypackage" , "bool", "Notify package finished" , True ),
- ("notifyprocessed", "bool", "Notify processed packages status" , True ),
- ("timeout" , "int" , "Timeout between captchas in seconds" , 5 ),
- ("force" , "bool", "Send notifications if client is connected", False)]
+ ("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)]
__description__ = """Send push notifications to Windows Phone"""
__license__ = "GPLv3"
- __authors__ = [("Andy Voigt", "phone-support@hotmail.de"),
- ("Walter Purcaro", "vuolter@gmail.com")]
+ __authors__ = [("Andy Voigt" , "phone-support@hotmail.de"),
+ ("Walter Purcaro", "vuolter@gmail.com" )]
- event_list = ["allDownloadsProcessed"]
+ event_list = ["allDownloadsProcessed", "plugin_updated"]
+ interval = 0 #@TODO: Remove in 0.4.10
def setup(self):
- self.info = {} #@TODO: Remove in 0.4.10
- self.last_notify = 0
+ self.info = {} #@TODO: Remove in 0.4.10
+ self.last_notify = 0
+ self.notifications = 0
- def newCaptchaTask(self, task):
- if not self.getConfig("notifycaptcha"):
- return False
+ def plugin_updated(self, type_plugins):
+ if not self.getConfig('notifyupdate'):
+ return
+
+ self.notify(_("Plugins updated"), str(type_plugins))
+
- if time() - self.last_notify < self.getConf("timeout"):
- return False
+ def coreExiting(self):
+ if not self.getConfig('notifyexit'):
+ return
+
+ if self.core.do_restart:
+ self.notify(_("Restarting pyLoad"))
+ else:
+ self.notify(_("Exiting pyLoad"))
+
+
+ def newCaptchaTask(self, task):
+ if not self.getConfig('notifycaptcha'):
+ return
self.notify(_("Captcha"), _("New request waiting user input"))
def packageFinished(self, pypack):
- if self.getConfig("notifypackage"):
+ if self.getConfig('notifypackage'):
self.notify(_("Package finished"), pypack.name)
def allDownloadsProcessed(self):
- if not self.getConfig("notifyprocessed"):
- return False
+ if not self.getConfig('notifyprocessed'):
+ return
if any(True for pdata in self.core.api.getQueue() if pdata.linksdone < pdata.linkstotal):
self.notify(_("Package failed"), _("One or more packages was not completed successfully"))
@@ -65,15 +83,31 @@ class WindowsPhoneNotify(Addon):
"</wp:Toast> </wp:Notification>" % msg)
- def notify(self, event, msg=""):
- id = self.getConfig("id")
- url = self.getConfig("url")
+ @Expose
+ def notify(self,
+ event,
+ msg="",
+ key=(self.getConfig('id'), self.getConfig('url'))):
+
+ id, url = key
if not id or not url:
- return False
+ return
+
+ if self.core.isClientConnected() and not self.getConfig('ignoreclient'):
+ return
+
+ elapsed_time = time.time() - self.last_notify
+
+ if elapsed_time < self.getConf("sendtimewait"):
+ return
+
+ if elapsed_time > 60:
+ self.notifications = 0
+
+ elif self.notifications >= self.getConf("sendpermin"):
+ return
- if self.core.isClientConnected() and not self.getConfig("force"):
- return False
request = self.getXmlData("%s: %s" % (event, msg) if msg else event)
webservice = httplib.HTTP(url)
@@ -88,4 +122,5 @@ class WindowsPhoneNotify(Addon):
webservice.send(request)
webservice.close()
- self.last_notify = time()
+ self.last_notify = time.time()
+ self.notifications += 1