forked from pyload/pyload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidPhoneNotify.py
More file actions
108 lines (73 loc) · 3.43 KB
/
Copy pathAndroidPhoneNotify.py
File metadata and controls
108 lines (73 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
import time
from pyload.network.RequestFactory import getURL
from pyload.plugin.Addon import Addon, Expose
class AndroidPhoneNotify(Addon):
__name = "AndroidPhoneNotify"
__type = "addon"
__version = "0.07"
__config = [("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)]
__description = """Send push notifications to your Android Phone (using notifymyandroid.com)"""
__license = "GPLv3"
__authors = [("Steven Kosyra" , "steven.kosyra@gmail.com"),
("Walter Purcaro", "vuolter@gmail.com" )]
event_list = ["allDownloadsProcessed", "plugin_updated"]
def setup(self):
self.last_notify = 0
self.notifications = 0
def plugin_updated(self, type_plugins):
if not self.getConfig('notifyupdate'):
return
self.notify(_("Plugins updated"), str(type_plugins))
def exit(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'):
self.notify(_("Package finished"), pypack.name)
def allDownloadsProcessed(self):
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"))
else:
self.notify(_("All packages finished"))
@Expose
def notify(self,
event,
msg="",
key=self.getConfig('apikey')):
if not key:
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
getURL("http://www.notifymyandroid.com/publicapi/notify",
get={'apikey' : key,
'application': "pyLoad",
'event' : event,
'description': msg})
self.last_notify = time.time()
self.notifications += 1