summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/WindowsPhoneToastNotify.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/hooks/WindowsPhoneToastNotify.py')
-rw-r--r--module/plugins/hooks/WindowsPhoneToastNotify.py125
1 files changed, 74 insertions, 51 deletions
diff --git a/module/plugins/hooks/WindowsPhoneToastNotify.py b/module/plugins/hooks/WindowsPhoneToastNotify.py
index 25fa3abe5..20686ee36 100644
--- a/module/plugins/hooks/WindowsPhoneToastNotify.py
+++ b/module/plugins/hooks/WindowsPhoneToastNotify.py
@@ -1,72 +1,95 @@
# -*- coding: utf-8 -*-
-"""
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-"""
-import time
import httplib
+
+from time import time
+
from module.plugins.Hook import Hook
class WindowsPhoneToastNotify(Hook):
- __name__ = "WindowsPhoneToastNotify"
- __version__ = "0.02"
- __type__ = "hook"
+ __name__ = "WindowsPhoneToastNotify"
+ __type__ = "hook"
+ __version__ = "0.05"
- __config__ = [("activated", "bool", "Activated", False),
- ("force", "bool", "Force even if client is connected", False),
- ("pushId", "str", "pushId", ""),
- ("pushUrl", "str", "pushUrl", ""),
- ("pushTimeout", "int", "Timeout between notifications in seconds", 0)]
+ __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)]
__description__ = """Send push notifications to Windows Phone"""
- __author_name__ = "Andy Voigt"
- __author_mail__ = "phone-support@hotmail.de"
+ __license__ = "GPLv3"
+ __authors__ = [("Andy Voigt", "phone-support@hotmail.de"),
+ ("Walter Purcaro", "vuolter@gmail.com")]
+
+
+ event_list = ["allDownloadsProcessed"]
+
+
+ #@TODO: Remove in 0.4.10
+ def initPeriodical(self):
+ pass
def setup(self):
- self.info = {}
-
- def getXmlData(self):
- myxml = ("<?xml version='1.0' encoding='utf-8'?> <wp:Notification xmlns:wp='WPNotification'> "
- "<wp:Toast> <wp:Text1>Pyload Mobile</wp:Text1> <wp:Text2>Captcha waiting!</wp:Text2> "
- "</wp:Toast> </wp:Notification>")
- return myxml
-
- def doRequest(self):
- URL = self.getConfig("pushUrl")
- request = self.getXmlData()
- webservice = httplib.HTTP(URL)
- webservice.putrequest("POST", self.getConfig("pushId"))
- webservice.putheader("Host", URL)
- webservice.putheader("Content-type", "text/xml")
- webservice.putheader("X-NotificationClass", "2")
- webservice.putheader("X-WindowsPhone-Target", "toast")
- webservice.putheader("Content-length", "%d" % len(request))
- webservice.endheaders()
- webservice.send(request)
- webservice.close()
- self.setStorage("LAST_NOTIFY", time.time())
+ self.info = {} #@TODO: Remove in 0.4.10
+
def newCaptchaTask(self, task):
- if not self.getConfig("pushId") or not self.getConfig("pushUrl"):
+ if not self.getConfig("notifycaptcha"):
return False
- if self.core.isClientConnected() and not self.getConfig("force"):
+ if time() - float(self.getStorage("WindowsPhoneToastNotify", 0)) < self.getConf("timeout"):
+ return False
+
+ self.notify(_("Captcha"), _("New request waiting user input"))
+
+
+ def packageFinished(self, pypack):
+ if self.getConfig("notifypackage"):
+ self.notify(_("Package finished"), pypack.name)
+
+
+ def allDownloadsProcessed(self):
+ if not self.getConfig("notifyprocessed"):
+ return False
+
+ 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"))
+ else:
+ self.notify(_("All packages finished"))
+
+
+ def getXmlData(self, msg):
+ return ("<?xml version='1.0' encoding='utf-8'?> <wp:Notification xmlns:wp='WPNotification'> "
+ "<wp:Toast> <wp:Text1>pyLoad</wp:Text1> <wp:Text2>%s</wp:Text2> "
+ "</wp:Toast> </wp:Notification>" % msg)
+
+
+ def notify(self, event, msg=""):
+ id = self.getConfig("id")
+ url = self.getConfig("url")
+
+ if not id or not url:
return False
- if (time.time() - float(self.getStorage("LAST_NOTIFY", 0))) < self.getConf("pushTimeout"):
+ if self.core.isClientConnected() and not self.getConfig("force"):
return False
- self.doRequest()
+ request = self.getXmlData("%s: %s" % (event, msg) if msg else event)
+ webservice = httplib.HTTP(url)
+
+ webservice.putrequest("POST", id)
+ webservice.putheader("Host", url)
+ webservice.putheader("Content-type", "text/xml")
+ webservice.putheader("X-NotificationClass", "2")
+ webservice.putheader("X-WindowsPhone-Target", "toast")
+ webservice.putheader("Content-length", "%d" % len(request))
+ webservice.endheaders()
+ webservice.send(request)
+ webservice.close()
+
+ self.setStorage("WindowsPhoneToastNotify", time())