diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/hooks/CaptchaBrotherhood.py | 2 | ||||
-rw-r--r-- | module/plugins/hooks/ExternalScripts.py | 2 | ||||
-rw-r--r-- | module/plugins/hooks/ExtractArchive.py | 2 | ||||
-rw-r--r-- | module/plugins/hooks/PushBullet.py | 123 | ||||
-rw-r--r-- | module/plugins/hooks/PushOver.py | 124 | ||||
-rw-r--r-- | module/plugins/hooks/TransmissionRPC.py | 4 | ||||
-rw-r--r-- | module/plugins/internal/Extractor.py | 3 | ||||
-rw-r--r-- | module/plugins/internal/SimpleHoster.py | 1 | ||||
-rw-r--r-- | module/plugins/internal/utils.py | 4 |
9 files changed, 256 insertions, 9 deletions
diff --git a/module/plugins/hooks/CaptchaBrotherhood.py b/module/plugins/hooks/CaptchaBrotherhood.py index 5411322de..5334c1c5b 100644 --- a/module/plugins/hooks/CaptchaBrotherhood.py +++ b/module/plugins/hooks/CaptchaBrotherhood.py @@ -155,7 +155,7 @@ class CaptchaBrotherhood(Addon): def captcha_invalid(self, task): if task.data['service'] is self.classname and "ticket" in task.data: - res = self.api_response("complainCaptcha", task.data['ticket']) + self.api_response("complainCaptcha", task.data['ticket']) @threaded diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 6a11f8c6a..9fd22e0af 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -176,7 +176,7 @@ class ExternalScripts(Addon): else: dl_folder = self.pyload.config.get("general", "download_folder") - args = [pack.id, pack.name, dl_folder, pack.password] + args = [pypack.id, pack.name, dl_folder, pack.password] self._call("package_deleted", args) diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 93107810c..c001000c8 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -169,7 +169,7 @@ class ExtractArchive(Addon): @threaded def extract_queued(self, thread): - if self.extracting: #@NOTE: doing the check here for safty (called by coreReady) + if self.extracting: #@NOTE: doing the check here for safety (called by coreReady) return self.extracting = True diff --git a/module/plugins/hooks/PushBullet.py b/module/plugins/hooks/PushBullet.py new file mode 100644 index 000000000..8486913c6 --- /dev/null +++ b/module/plugins/hooks/PushBullet.py @@ -0,0 +1,123 @@ +# -*- coding: utf-8 -*- + +import time + +import pycurl + +from module.plugins.internal.Addon import Addon, Expose +from module.network.RequestFactory import getRequest as get_request + + +class PushBullet(Addon): + __name__ = "PushBullet" + __type__ = "hook" + __version__ = "0.01" + __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)] + + __description__ = """Send push notifications to your Phone (using PushBullet / based on AndroidPhoneNotify)""" + __license__ = "GPLv3" + __authors__ = [("Malkavi" , "")] + + + def init(self): + self.event_map = {'allDownloadsProcessed': "all_downloads_processed", + 'plugin_updated' : "plugin_updated" } + + self.last_notify = 0 + self.notifications = 0 + + + def plugin_updated(self, type_plugins): + if not self.get_config('notifyupdate'): + return + + self.notify(_("Plugins updated"), str(type_plugins)) + + + def activate(self): + self.key = self.get_config('tokenkey') + + + def exit(self): + if not self.get_config('notifyexit'): + return + + if self.pyload.do_restart: + self.notify(_("Restarting pyLoad")) + else: + self.notify(_("Exiting pyLoad")) + + + def captcha_task(self, task): + if not self.get_config('notifycaptcha'): + return + + self.notify(_("Captcha"), _("New request waiting user input")) + + + def package_finished(self, pypack): + if self.get_config('notifypackage'): + self.notify(_("Package finished"), pypack.name) + + + def all_downloads_processed(self): + if not self.get_config('notifyprocessed'): + 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")) + + + @Expose + def notify(self, + event, + msg=None, + key=None): + + key = key or self.key + if not key: + return + + if not msg: + msg = event + + if self.pyload.isClientConnected() and not self.get_config('ignoreclient'): + return + + elapsed_time = time.time() - self.last_notify + + if elapsed_time < self.get_config("sendtimewait"): + return + + if elapsed_time > 60: + self.notifications = 0 + + elif self.notifications >= self.get_config("sendpermin"): + return + + req = get_request() + req.c.setopt(pycurl.HTTPHEADER, ["Access-Token: %s" % str(key)]) + + self.load("https://api.pushbullet.com/v2/pushes", + post={'type' : 'note', + 'title' : event, + 'message': msg}, + req=req) + + self.last_notify = time.time() + self.notifications += 1 + + return True diff --git a/module/plugins/hooks/PushOver.py b/module/plugins/hooks/PushOver.py new file mode 100644 index 000000000..66c709a3c --- /dev/null +++ b/module/plugins/hooks/PushOver.py @@ -0,0 +1,124 @@ +# -*- coding: utf-8 -*- + +import time + +from module.plugins.internal.Addon import Addon, Expose + + +class PushOver(Addon): + __name__ = "PushOver" + __type__ = "hook" + __version__ = "0.01" + __status__ = "testing" + + __config__ = [("activated" , "bool", "Activated" , False), + ("tokenkey" , "str" , "API 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)] + + __description__ = """Send push notifications to your Phone (using PushOver / based on AndroidPhoneNotify)""" + __license__ = "GPLv3" + __authors__ = [("Malkavi" , "")] + + + def init(self): + self.event_map = {'allDownloadsProcessed': "all_downloads_processed", + 'plugin_updated' : "plugin_updated" } + + self.last_notify = 0 + self.notifications = 0 + + + def plugin_updated(self, type_plugins): + if not self.get_config('notifyupdate'): + return + + self.notify(_("Plugins updated"), str(type_plugins)) + + + def activate(self): + self.keytoken = self.get_config('tokenkey') + self.keyuser = self.get_config('userkey') + + + def exit(self): + if not self.get_config('notifyexit'): + return + + if self.pyload.do_restart: + self.notify(_("Restarting pyLoad")) + else: + self.notify(_("Exiting pyLoad")) + + + def captcha_task(self, task): + if not self.get_config('notifycaptcha'): + return + + self.notify(_("Captcha"), _("New request waiting user input")) + + + def package_finished(self, pypack): + if self.get_config('notifypackage'): + self.notify(_("Package finished"), pypack.name) + + + def all_downloads_processed(self): + if not self.get_config('notifyprocessed'): + 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")) + + + @Expose + def notify(self, + event, + msg=None, + keytoken=None, + keyuser=None): + + keytoken = keytoken or self.keytoken + if not keytoken: + return + + keyuser = keyuser or self.keyuser + if not keyuser: + return + + if not msg: + msg = event + + if self.pyload.isClientConnected() and not self.get_config('ignoreclient'): + return + + elapsed_time = time.time() - self.last_notify + + if elapsed_time < self.get_config("sendtimewait"): + return + + if elapsed_time > 60: + self.notifications = 0 + + elif self.notifications >= self.get_config("sendpermin"): + return + + self.load("https://api.pushover.net/1/messages.json", + post={'token' : keytoken, + 'user' : keyuser, + 'title' : event, + 'message': msg}) + + self.last_notify = time.time() + self.notifications += 1 + + return True diff --git a/module/plugins/hooks/TransmissionRPC.py b/module/plugins/hooks/TransmissionRPC.py index da4ea1fc5..7914d5c44 100644 --- a/module/plugins/hooks/TransmissionRPC.py +++ b/module/plugins/hooks/TransmissionRPC.py @@ -14,7 +14,7 @@ from module.plugins.internal.Addon import Addon class TransmissionRPC(Addon): __name__ = "TransmissionRPC" __type__ = "hook" - __version__ = "0.15" + __version__ = "0.16" __status__ = "testing" __pattern__ = r"https?://.+\.torrent|magnet:\?.+" @@ -53,7 +53,7 @@ class TransmissionRPC(Addon): req=req) except Exception, e: - if req.code == 409: + if isinstance(e, BadHeader) and e.code == 409: headers = dict(re.findall(r"(?P<name>.+?): (?P<value>.+?)\r?\n", req.header)) session_id = headers['X-Transmission-Session-Id'] req.c.setopt(pycurl.HTTPHEADER, ["X-Transmission-Session-Id: %s" % session_id]) diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py index 005bfbfd5..864792e49 100644 --- a/module/plugins/internal/Extractor.py +++ b/module/plugins/internal/Extractor.py @@ -5,6 +5,7 @@ import re from module.PyFile import PyFile from module.plugins.internal.Plugin import Plugin +from module.plugins.internal.utils import encode def renice(pid, value): @@ -75,7 +76,7 @@ class Extractor(Plugin): for fname, id, fout in files_ids: if cls.isarchive(fname): - pname = re.sub(cls.re_multipart, "", fname) if cls.ismultipart(fname) else os.path.splitext(fname)[0] + pname = re.sub(cls.re_multipart, "", fname) if cls.is_multipart(fname) else os.path.splitext(fname)[0] if pname not in processed: processed.append(pname) targets.append((fname, id, fout)) diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index b434c55ae..7821218ae 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -2,7 +2,6 @@ from __future__ import with_statement -import os import re import time diff --git a/module/plugins/internal/utils.py b/module/plugins/internal/utils.py index 723690f39..3a3ada07d 100644 --- a/module/plugins/internal/utils.py +++ b/module/plugins/internal/utils.py @@ -162,8 +162,8 @@ def encode(value, encoding=None, decoding=None): if type(value) is unicode: res = value.encode(encoding or "utf-8") - elif type(value) is str: - res = encode(decode(value, decoding), encoding) + #elif type(value) is str: + #res = encode(decode(value, decoding), encoding) else: res = str(value) |