diff options
Diffstat (limited to 'module/plugins/hooks')
54 files changed, 1594 insertions, 1394 deletions
diff --git a/module/plugins/hooks/AlldebridComHook.py b/module/plugins/hooks/AlldebridComHook.py index 092921134..402850d87 100644 --- a/module/plugins/hooks/AlldebridComHook.py +++ b/module/plugins/hooks/AlldebridComHook.py @@ -6,22 +6,20 @@ from module.plugins.internal.MultiHook import MultiHook class AlldebridComHook(MultiHook): __name__ = "AlldebridComHook" __type__ = "hook" - __version__ = "0.16" + __version__ = "0.17" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 ), - ("ssl" , "bool" , "Use HTTPS" , True )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Alldebrid.com hook plugin""" __license__ = "GPLv3" __authors__ = [("Andy Voigt", "spamsales@online.de")] - def getHosters(self): - https = "https" if self.getConfig('ssl') else "http" - html = self.getURL(https + "://www.alldebrid.com/api.php", get={'action': "get_host"}).replace("\"", "").strip() - + def get_hosters(self): + html = self.load("https://www.alldebrid.com/api.php", + get={'action': "get_host"}).replace("\"", "").strip() return [x.strip() for x in html.split(",") if x.strip()] diff --git a/module/plugins/hooks/AndroidPhoneNotify.py b/module/plugins/hooks/AndroidPhoneNotify.py index a8a1cff72..f79f226e4 100644 --- a/module/plugins/hooks/AndroidPhoneNotify.py +++ b/module/plugins/hooks/AndroidPhoneNotify.py @@ -2,14 +2,14 @@ import time -from module.network.RequestFactory import getURL -from module.plugins.Hook import Hook, Expose +from module.plugins.internal.Addon import Addon, Expose -class AndroidPhoneNotify(Hook): +class AndroidPhoneNotify(Addon): __name__ = "AndroidPhoneNotify" __type__ = "hook" - __version__ = "0.08" + __version__ = "0.10" + __status__ = "testing" __config__ = [("apikey" , "str" , "API key" , "" ), ("notifycaptcha" , "bool", "Notify captcha request" , True ), @@ -27,56 +27,52 @@ class AndroidPhoneNotify(Hook): ("Walter Purcaro", "vuolter@gmail.com" )] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - self.event_list = ["allDownloadsProcessed", "plugin_updated"] + def init(self): + self.event_list = ["plugin_updated"] + self.event_map = {'allDownloadsProcessed': "all_downloads_processed"} self.last_notify = 0 self.notifications = 0 def plugin_updated(self, type_plugins): - if not self.getConfig('notifyupdate'): + if not self.get_config('notifyupdate'): return self.notify(_("Plugins updated"), str(type_plugins)) - def coreReady(self): - self.key = self.getConfig('apikey') + def activate(self): + self.key = self.get_config('apikey') - def coreExiting(self): - if not self.getConfig('notifyexit'): + def exit(self): + if not self.get_config('notifyexit'): return - if self.core.do_restart: + if self.pyload.do_restart: self.notify(_("Restarting pyLoad")) else: self.notify(_("Exiting pyLoad")) - def newCaptchaTask(self, task): - if not self.getConfig('notifycaptcha'): + def captcha_task(self, task): + if not self.get_config('notifycaptcha'): return self.notify(_("Captcha"), _("New request waiting user input")) - def packageFinished(self, pypack): - if self.getConfig('notifypackage'): + def package_finished(self, pypack): + if self.get_config('notifypackage'): self.notify(_("Package finished"), pypack.name) - def allDownloadsProcessed(self): - if not self.getConfig('notifyprocessed'): + def all_downloads_processed(self): + if not self.get_config('notifyprocessed'): return - if any(True for pdata in self.core.api.getQueue() if pdata.linksdone < pdata.linkstotal): + 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")) @@ -92,21 +88,21 @@ class AndroidPhoneNotify(Hook): if not key: return - if self.core.isClientConnected() and not self.getConfig('ignoreclient'): + if self.pyload.isClientConnected() and not self.get_config('ignoreclient'): return elapsed_time = time.time() - self.last_notify - if elapsed_time < self.getConf("sendtimewait"): + if elapsed_time < self.get_config("sendtimewait"): return if elapsed_time > 60: self.notifications = 0 - elif self.notifications >= self.getConf("sendpermin"): + elif self.notifications >= self.get_config("sendpermin"): return - getURL("http://www.notifymyandroid.com/publicapi/notify", + self.load("http://www.notifymyandroid.com/publicapi/notify", get={'apikey' : key, 'application': "pyLoad", 'event' : event, diff --git a/module/plugins/hooks/AntiStandby.py b/module/plugins/hooks/AntiStandby.py new file mode 100644 index 000000000..48b86fa55 --- /dev/null +++ b/module/plugins/hooks/AntiStandby.py @@ -0,0 +1,175 @@ +# -*- coding: utf-8 -*- + +from __future__ import with_statement + +import os +import time +import subprocess +import sys + +try: + import caffeine +except ImportError: + pass + +from module.plugins.internal.Addon import Addon, Expose +from module.utils import fs_encode, save_join as fs_join + + +class Kernel32(object): + ES_AWAYMODE_REQUIRED = 0x00000040 + ES_CONTINUOUS = 0x80000000 + ES_DISPLAY_REQUIRED = 0x00000002 + ES_SYSTEM_REQUIRED = 0x00000001 + ES_USER_PRESENT = 0x00000004 + + +class AntiStandby(Addon): + __name__ = "AntiStandby" + __type__ = "hook" + __version__ = "0.11" + __status__ = "testing" + + __config__ = [("activated", "bool", "Activated" , True ), + ("hdd" , "bool", "Prevent HDD standby" , True ), + ("system" , "bool", "Prevent OS standby" , True ), + ("display" , "bool", "Prevent display standby" , False), + ("interval" , "int" , "HDD touching interval in seconds", 25 )] + + __description__ = """Prevent OS, HDD and display standby""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + TMP_FILE = ".antistandby" + MIN_INTERVAL = 5 + + + def init(self): + self.pid = None + self.mtime = 0 + + + def activate(self): + hdd = self.get_config('hdd') + system = not self.get_config('system') + display = not self.get_config('display') + + if hdd: + self.interval = max(self.get_config('interval'), self.MIN_INTERVAL) + self.init_periodical(threaded=True) + + if os.name == "nt": + self.win_standby(system, display) + + elif sys.platform == "darwin": + self.osx_standby(system, display) + + else: + self.linux_standby(system, display) + + + def deactivate(self): + try: + os.remove(self.TMP_FILE) + + except OSError: + pass + + if os.name == "nt": + self.win_standby(True) + + elif sys.platform == "darwin": + self.osx_standby(True) + + else: + self.linux_standby(True) + + + @Expose + def win_standby(self, system=True, display=True): + import ctypes + + set = ctypes.windll.kernel32.SetThreadExecutionState + + if system: + if display: + set(Kernel32.ES_CONTINUOUS) + else: + set(Kernel32.ES_CONTINUOUS | Kernel32.ES_DISPLAY_REQUIRED) + else: + if display: + set(Kernel32.ES_CONTINUOUS | Kernel32.ES_SYSTEM_REQUIRED) + else: + set(Kernel32.ES_CONTINUOUS | Kernel32.ES_SYSTEM_REQUIRED | Kernel32.ES_DISPLAY_REQUIRED) + + + @Expose + def osx_standby(self, system=True, display=True): + try: + if system: + caffeine.off() + else: + caffeine.on(display) + + except NameError: + self.log_warning(_("Unable to change power state"), + _("caffeine lib not found")) + + except Exception, e: + self.log_warning(_("Unable to change power state"), e) + + + @Expose + def linux_standby(self, system=True, display=True): + try: + if system: + if self.pid: + self.pid.kill() + + elif not self.pid: + self.pid = subprocess.Popen(["caffeine"]) + + except Exception, e: + self.log_warning(_("Unable to change system power state"), e) + + try: + if display: + subprocess.call(["xset", "+dpms", "s", "default"]) + else: + subprocess.call(["xset", "-dpms", "s", "off"]) + + except Exception, e: + self.log_warning(_("Unable to change display power state"), e) + + + @Expose + def touch(self, path): + with open(path, 'w'): + os.utime(path, None) + + self.mtime = time.time() + + + @Expose + def max_mtime(self, path): + return max(0, 0, + *(os.path.getmtime(fs_join(root, file)) + for root, dirs, files in os.walk(fs_encode(path), topdown=False) + for file in files)) + + + def periodical(self): + if self.get_config('hdd') is False: + return + + if (self.pyload.threadManager.pause or + not self.pyload.api.isTimeDownload() or + not self.pyload.threadManager.getActiveFiles()): + return + + download_folder = self.pyload.config.get("general", "download_folder") + if (self.max_mtime(download_folder) - self.mtime) < self.interval: + return + + self.touch(self.TMP_FILE) diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index c620f556d..b58d0b61d 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -9,14 +9,15 @@ try: except ImportError: pass -from module.plugins.Hook import Hook, Expose, threaded -from module.utils import fs_encode, save_join +from module.plugins.internal.Addon import Addon, Expose, threaded +from module.utils import fs_encode, save_join as fs_join -class AntiVirus(Hook): +class AntiVirus(Addon): __name__ = "AntiVirus" __type__ = "hook" - __version__ = "0.09" + __version__ = "0.12" + __status__ = "testing" #@TODO: add trash option (use Send2Trash lib) __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), @@ -32,20 +33,13 @@ class AntiVirus(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - @Expose @threaded def scan(self, pyfile, thread): - file = fs_encode(pyfile.plugin.lastDownload) - filename = os.path.basename(pyfile.plugin.lastDownload) - cmdfile = fs_encode(self.getConfig('cmdfile')) - cmdargs = fs_encode(self.getConfig('cmdargs').strip()) + file = fs_encode(pyfile.plugin.last_download) + filename = os.path.basename(pyfile.plugin.last_download) + cmdfile = fs_encode(self.get_config('cmdfile')) + cmdargs = fs_encode(self.get_config('cmdargs').strip()) if not os.path.isfile(file) or not os.path.isfile(cmdfile): return @@ -60,20 +54,20 @@ class AntiVirus(Hook): out, err = map(str.strip, p.communicate()) if out: - self.logInfo(filename, out) + self.log_info(filename, out) if err: - self.logWarning(filename, err) - if not self.getConfig('ignore-err'): - self.logDebug("Delete/Quarantine task is aborted") + self.log_warning(filename, err) + if not self.get_config('ignore-err'): + self.log_debug("Delete/Quarantine task is aborted") return if p.returncode: - pyfile.error = _("infected file") - action = self.getConfig('action') + pyfile.error = _("Infected file") + action = self.get_config('action') try: if action == "Delete": - if not self.getConfig('deltotrash'): + if not self.get_config('deltotrash'): os.remove(file) else: @@ -81,39 +75,38 @@ class AntiVirus(Hook): send2trash.send2trash(file) except NameError: - self.logWarning(_("Send2Trash lib not found, moving to quarantine instead")) + self.log_warning(_("Send2Trash lib not found, moving to quarantine instead")) pyfile.setCustomStatus(_("file moving")) - shutil.move(file, self.getConfig('quardir')) + shutil.move(file, self.get_config('quardir')) except Exception, e: - self.logWarning(_("Unable to move file to trash: %s, moving to quarantine instead") % e.message) + self.log_warning(_("Unable to move file to trash: %s, moving to quarantine instead") % e.message) pyfile.setCustomStatus(_("file moving")) - shutil.move(file, self.getConfig('quardir')) + shutil.move(file, self.get_config('quardir')) else: - self.logDebug(_("Successfully moved file to trash")) + self.log_debug("Successfully moved file to trash") elif action == "Quarantine": pyfile.setCustomStatus(_("file moving")) - shutil.move(file, self.getConfig('quardir')) + shutil.move(file, self.get_config('quardir')) except (IOError, shutil.Error), e: - self.logError(filename, action + " action failed!", e) + self.log_error(filename, action + " action failed!", e) elif not out and not err: - self.logDebug(filename, "No infected file found") + self.log_debug(filename, "No infected file found") finally: pyfile.setProgress(100) thread.finishFile(pyfile) - def downloadFinished(self, pyfile): + def download_finished(self, pyfile): return self.scan(pyfile) - def downloadFailed(self, pyfile): - #: Check if pyfile is still "failed", - # maybe might has been restarted in meantime - if pyfile.status == 8 and self.getConfig('scanfailed'): + def download_failed(self, pyfile): + #: Check if pyfile is still "failed", maybe might has been restarted in meantime + if pyfile.status == 8 and self.get_config('scanfailed'): return self.scan(pyfile) diff --git a/module/plugins/hooks/BypassCaptcha.py b/module/plugins/hooks/BypassCaptcha.py index 9e01edfa2..4b155a67e 100644 --- a/module/plugins/hooks/BypassCaptcha.py +++ b/module/plugins/hooks/BypassCaptcha.py @@ -3,8 +3,8 @@ import pycurl from module.network.HTTPRequest import BadHeader -from module.network.RequestFactory import getURL, getRequest -from module.plugins.Hook import Hook, threaded +from module.network.RequestFactory import getRequest as get_request +from module.plugins.internal.Hook import Hook, threaded class BypassCaptchaException(Exception): @@ -13,7 +13,7 @@ class BypassCaptchaException(Exception): self.err = err - def getCode(self): + def get_code(self): return self.err @@ -28,10 +28,11 @@ class BypassCaptchaException(Exception): class BypassCaptcha(Hook): __name__ = "BypassCaptcha" __type__ = "hook" - __version__ = "0.06" + __version__ = "0.08" + __status__ = "testing" - __config__ = [("force", "bool", "Force BC even if client is connected", False), - ("passkey", "password", "Passkey", "")] + __config__ = [("passkey" , "password", "Access key" , "" ), + ("check_client", "bool" , "Don't use if client is connected", True)] __description__ = """Send captchas to BypassCaptcha.com""" __license__ = "GPLv3" @@ -40,8 +41,6 @@ class BypassCaptcha(Hook): ("zoidberg" , "zoidberg@mujmail.cz" )] - interval = 0 #@TODO: Remove in 0.4.10 - PYLOAD_KEY = "4f771155b640970d5607f919a615bdefc67e7d32" SUBMIT_URL = "http://bypasscaptcha.com/upload.php" @@ -49,30 +48,26 @@ class BypassCaptcha(Hook): GETCREDITS_URL = "http://bypasscaptcha.com/ex_left.php" - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - - def getCredits(self): - res = getURL(self.GETCREDITS_URL, post={"key": self.getConfig('passkey')}) + def get_credits(self): + res = self.load(self.GETCREDITS_URL, post={'key': self.get_config('passkey')}) data = dict(x.split(' ', 1) for x in res.splitlines()) return int(data['Left']) def submit(self, captcha, captchaType="file", match=None): - req = getRequest() + req = get_request() - #raise timeout threshold + #: Raise timeout threshold req.c.setopt(pycurl.LOW_SPEED_TIME, 80) try: - res = req.load(self.SUBMIT_URL, - post={'vendor_key': self.PYLOAD_KEY, - 'key': self.getConfig('passkey'), - 'gen_task_id': "1", - 'file': (pycurl.FORM_FILE, captcha)}, - multipart=True) + res = self.load(self.SUBMIT_URL, + post={'vendor_key': self.PYLOAD_KEY, + 'key': self.get_config('passkey'), + 'gen_task_id': "1", + 'file': (pycurl.FORM_FILE, captcha)}, + req=req) finally: req.close() @@ -82,59 +77,59 @@ class BypassCaptcha(Hook): result = data['Value'] ticket = data['TaskId'] - self.logDebug("Result %s : %s" % (ticket, result)) + self.log_debug("Result %s : %s" % (ticket, result)) return ticket, result def respond(self, ticket, success): try: - res = getURL(self.RESPOND_URL, post={"task_id": ticket, "key": self.getConfig('passkey'), - "cv": 1 if success else 0}) + res = self.load(self.RESPOND_URL, post={'task_id': ticket, 'key': self.get_config('passkey'), + 'cv': 1 if success else 0}) except BadHeader, e: - self.logError(_("Could not send response"), e) + self.log_error(_("Could not send response"), e) - def newCaptchaTask(self, task): + def captcha_task(self, task): if "service" in task.data: return False if not task.isTextual(): return False - if not self.getConfig('passkey'): + if not self.get_config('passkey'): return False - if self.core.isClientConnected() and not self.getConfig('force'): + if self.pyload.isClientConnected() and self.get_config('check_client'): return False - if self.getCredits() > 0: + if self.get_credits() > 0: task.handler.append(self) task.data['service'] = self.__name__ task.setWaiting(100) - self._processCaptcha(task) + self._process_captcha(task) else: - self.logInfo(_("Your %s account has not enough credits") % self.__name__) + self.log_info(_("Your %s account has not enough credits") % self.__name__) - def captchaCorrect(self, task): - if task.data['service'] == self.__name__ and "ticket" in task.data: + def captcha_correct(self, task): + if task.data['service'] is self.__name__ and "ticket" in task.data: self.respond(task.data['ticket'], True) - def captchaInvalid(self, task): - if task.data['service'] == self.__name__ and "ticket" in task.data: + def captcha_invalid(self, task): + if task.data['service'] is self.__name__ and "ticket" in task.data: self.respond(task.data['ticket'], False) @threaded - def _processCaptcha(self, task): + def _process_captcha(self, task): c = task.captchaFile try: ticket, result = self.submit(c) except BypassCaptchaException, e: - task.error = e.getCode() + task.error = e.get_code() return task.data['ticket'] = ticket diff --git a/module/plugins/hooks/Captcha9Kw.py b/module/plugins/hooks/Captcha9Kw.py index 60482b8fc..2e2685978 100644 --- a/module/plugins/hooks/Captcha9Kw.py +++ b/module/plugins/hooks/Captcha9Kw.py @@ -8,18 +8,16 @@ import time from base64 import b64encode from module.network.HTTPRequest import BadHeader -from module.network.RequestFactory import getURL - -from module.plugins.Hook import Hook, threaded +from module.plugins.internal.Hook import Hook, threaded class Captcha9Kw(Hook): __name__ = "Captcha9Kw" __type__ = "hook" - __version__ = "0.28" + __version__ = "0.30" + __status__ = "testing" - __config__ = [("ssl" , "bool" , "Use HTTPS" , True ), - ("force" , "bool" , "Force captcha resolving even if client is connected" , True ), + __config__ = [("check_client" , "bool" , "Don't use if client is connected" , True ), ("confirm" , "bool" , "Confirm Captcha (cost +6 credits)" , False ), ("captchaperhour", "int" , "Captcha per hour" , "9999" ), ("captchapermin" , "int" , "Captcha per minute" , "9999" ), @@ -36,62 +34,54 @@ class Captcha9Kw(Hook): ("Walter Purcaro", "vuolter@gmail.com")] - interval = 0 #@TODO: Remove in 0.4.10 - - API_URL = "http://www.9kw.eu/index.cgi" - - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - if self.getConfig('ssl'): - self.API_URL = self.API_URL.replace("http://", "https://") + API_URL = "https://www.9kw.eu/index.cgi" - def getCredits(self): - res = getURL(self.API_URL, - get={'apikey': self.getConfig('passkey'), + def get_credits(self): + res = self.load(self.API_URL, + get={'apikey': self.get_config('passkey'), 'pyload': "1", 'source': "pyload", 'action': "usercaptchaguthaben"}) if res.isdigit(): - self.logInfo(_("%s credits left") % res) + self.log_info(_("%s credits left") % res) credits = self.info['credits'] = int(res) return credits else: - self.logError(res) + self.log_error(res) return 0 @threaded - def _processCaptcha(self, task): + def _process_captcha(self, task): try: with open(task.captchaFile, 'rb') as f: data = f.read() except IOError, e: - self.logError(e) + self.log_error(e) return - pluginname = re.search(r'_([^_]*)_\d+.\w+', task.captchaFile).group(1) + pluginname = re.search(r'_(.+?)_\d+.\w+', task.captchaFile).group(1) option = {'min' : 2, 'max' : 50, 'phrase' : 0, 'numeric' : 0, 'case_sensitive': 0, 'math' : 0, - 'prio' : min(max(self.getConfig('prio'), 0), 10), - 'confirm' : self.getConfig('confirm'), - 'timeout' : min(max(self.getConfig('timeout'), 300), 3999), - 'selfsolve' : self.getConfig('selfsolve'), - 'cph' : self.getConfig('captchaperhour'), - 'cpm' : self.getConfig('captchapermin')} + 'prio' : min(max(self.get_config('prio'), 0), 10), + 'confirm' : self.get_config('confirm'), + 'timeout' : min(max(self.get_config('timeout'), 300), 3999), + 'selfsolve' : self.get_config('selfsolve'), + 'cph' : self.get_config('captchaperhour'), + 'cpm' : self.get_config('captchapermin')} - for opt in str(self.getConfig('hoster_options').split('|')): + for opt in str(self.get_config('hoster_options').split('|')): details = map(str.strip, opt.split(':')) - if not details or details[0].lower() != pluginname.lower(): + if not details or details[0].lower() is not pluginname.lower(): continue for d in details: @@ -106,7 +96,7 @@ class Captcha9Kw(Hook): break - post_data = {'apikey' : self.getConfig('passkey'), + post_data = {'apikey' : self.get_config('passkey'), 'prio' : option['prio'], 'confirm' : option['confirm'], 'maxtimeout' : option['timeout'], @@ -120,32 +110,35 @@ class Captcha9Kw(Hook): 'numeric' : option['numeric'], 'math' : option['math'], 'oldsource' : pluginname, - 'pyload' : "1", + 'pyload' : 1, 'source' : "pyload", - 'base64' : "1", + 'base64' : 1, 'mouse' : 1 if task.isPositional() else 0, 'file-upload-01': b64encode(data), 'action' : "usercaptchaupload"} for _i in xrange(5): try: - res = getURL(self.API_URL, post=post_data) + res = self.load(self.API_URL, post=post_data) + except BadHeader, e: time.sleep(3) + else: if res and res.isdigit(): break + else: - self.logError(_("Bad upload: %s") % res) + self.log_error(_("Bad upload: %s") % res) return - self.logDebug(_("NewCaptchaID ticket: %s") % res, task.captchaFile) + self.log_debug("NewCaptchaID ticket: %s" % res, task.captchaFile) - task.data["ticket"] = res + task.data['ticket'] = res - for _i in xrange(int(self.getConfig('timeout') / 5)): - result = getURL(self.API_URL, - get={'apikey': self.getConfig('passkey'), + for _i in xrange(int(self.get_config('timeout') / 5)): + result = self.load(self.API_URL, + get={'apikey': self.get_config('passkey'), 'id' : res, 'pyload': "1", 'info' : "1", @@ -157,36 +150,36 @@ class Captcha9Kw(Hook): else: break else: - self.logDebug("Could not send request: %s" % res) + self.log_debug("Could not send request: %s" % res) result = None - self.logInfo(_("Captcha result for ticket %s: %s") % (res, result)) + self.log_info(_("Captcha result for ticket %s: %s") % (res, result)) task.setResult(result) - def newCaptchaTask(self, task): + def captcha_task(self, task): if not task.isTextual() and not task.isPositional(): return - if not self.getConfig('passkey'): + if not self.get_config('passkey'): return - if self.core.isClientConnected() and not self.getConfig('force'): + if self.pyload.isClientConnected() and self.get_config('check_client'): return - credits = self.getCredits() + credits = self.get_credits() if not credits: - self.logError(_("Your captcha 9kw.eu account has not enough credits")) + self.log_error(_("Your captcha 9kw.eu account has not enough credits")) return - queue = min(self.getConfig('queue'), 999) - timeout = min(max(self.getConfig('timeout'), 300), 3999) - pluginname = re.search(r'_([^_]*)_\d+.\w+', task.captchaFile).group(1) + queue = min(self.get_config('queue'), 999) + timeout = min(max(self.get_config('timeout'), 300), 3999) + pluginname = re.search(r'_(.+?)_\d+.\w+', task.captchaFile).group(1) for _i in xrange(5): - servercheck = getURL("http://www.9kw.eu/grafik/servercheck.txt") + servercheck = self.load("http://www.9kw.eu/grafik/servercheck.txt") if queue < re.search(r'queue=(\d+)', servercheck).group(1): break @@ -194,17 +187,17 @@ class Captcha9Kw(Hook): else: self.fail(_("Too many captchas in queue")) - for opt in str(self.getConfig('hoster_options').split('|')): + for opt in str(self.get_config('hoster_options').split('|')): details = map(str.strip, opt.split(':')) - if not details or details[0].lower() != pluginname.lower(): + if not details or details[0].lower() is not pluginname.lower(): continue for d in details: hosteroption = d.split("=") if len(hosteroption) > 1 \ - and hosteroption[0].lower() == 'timeout' \ + and hosteroption[0].lower() == "timeout" \ and hosteroption[1].isdigit(): timeout = int(hosteroption[1]) @@ -214,41 +207,41 @@ class Captcha9Kw(Hook): task.setWaiting(timeout) - self._processCaptcha(task) + self._process_captcha(task) - def _captchaResponse(self, task, correct): + def _captcha_response(self, task, correct): type = "correct" if correct else "refund" if 'ticket' not in task.data: - self.logDebug("No CaptchaID for %s request (task: %s)" % (type, task)) + self.log_debug("No CaptchaID for %s request (task: %s)" % (type, task)) return - passkey = self.getConfig('passkey') + passkey = self.get_config('passkey') for _i in xrange(3): - res = getURL(self.API_URL, + res = self.load(self.API_URL, get={'action' : "usercaptchacorrectback", 'apikey' : passkey, 'api_key': passkey, 'correct': "1" if correct else "2", 'pyload' : "1", 'source' : "pyload", - 'id' : task.data["ticket"]}) + 'id' : task.data['ticket']}) - self.logDebug("Request %s: %s" % (type, res)) + self.log_debug("Request %s: %s" % (type, res)) if res == "OK": break time.sleep(5) else: - self.logDebug("Could not send %s request: %s" % (type, res)) + self.log_debug("Could not send %s request: %s" % (type, res)) - def captchaCorrect(self, task): - self._captchaResponse(task, True) + def captcha_correct(self, task): + self._captcha_response(task, True) - def captchaInvalid(self, task): - self._captchaResponse(task, False) + def captcha_invalid(self, task): + self._captcha_response(task, False) diff --git a/module/plugins/hooks/CaptchaBrotherhood.py b/module/plugins/hooks/CaptchaBrotherhood.py index bda080037..0df1ab8a9 100644 --- a/module/plugins/hooks/CaptchaBrotherhood.py +++ b/module/plugins/hooks/CaptchaBrotherhood.py @@ -9,11 +9,12 @@ import urllib try: from PIL import Image + except ImportError: import Image -from module.network.RequestFactory import getURL, getRequest -from module.plugins.Hook import Hook, threaded +from module.network.RequestFactory import getRequest as get_request +from module.plugins.internal.Hook import Hook, threaded class CaptchaBrotherhoodException(Exception): @@ -22,7 +23,7 @@ class CaptchaBrotherhoodException(Exception): self.err = err - def getCode(self): + def get_code(self): return self.err @@ -37,11 +38,12 @@ class CaptchaBrotherhoodException(Exception): class CaptchaBrotherhood(Hook): __name__ = "CaptchaBrotherhood" __type__ = "hook" - __version__ = "0.08" + __version__ = "0.10" + __status__ = "testing" - __config__ = [("username", "str", "Username", ""), - ("force", "bool", "Force CT even if client is connected", False), - ("passkey", "password", "Password", "")] + __config__ = [("username" , "str" , "Username" , "" ), + ("password" , "password", "Password" , "" ), + ("check_client", "bool" , "Don't use if client is connected", True)] __description__ = """Send captchas to CaptchaBrotherhood.com""" __license__ = "GPLv3" @@ -49,23 +51,17 @@ class CaptchaBrotherhood(Hook): ("zoidberg", "zoidberg@mujmail.cz")] - interval = 0 #@TODO: Remove in 0.4.10 - API_URL = "http://www.captchabrotherhood.com/" - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - - def getCredits(self): - res = getURL(self.API_URL + "askCredits.aspx", - get={"username": self.getConfig('username'), "password": self.getConfig('passkey')}) + def get_credits(self): + res = self.load(self.API_URL + "askCredits.aspx", + get={'username': self.get_config('username'), 'password': self.get_config('password')}) if not res.startswith("OK"): raise CaptchaBrotherhoodException(res) else: credits = int(res[3:]) - self.logInfo(_("%d credits left") % credits) + self.log_info(_("%d credits left") % credits) self.info['credits'] = credits return credits @@ -74,7 +70,7 @@ class CaptchaBrotherhood(Hook): try: img = Image.open(captcha) output = StringIO.StringIO() - self.logDebug("CAPTCHA IMAGE", img, img.format, img.mode) + self.log_debug("CAPTCHA IMAGE", img, img.format, img.mode) if img.format in ("GIF", "JPEG"): img.save(output, img.format) else: @@ -86,11 +82,11 @@ class CaptchaBrotherhood(Hook): except Exception, e: raise CaptchaBrotherhoodException("Reading or converting captcha image failed: %s" % e) - req = getRequest() + req = get_request() url = "%ssendNewCaptcha.aspx?%s" % (self.API_URL, - urllib.urlencode({'username' : self.getConfig('username'), - 'password' : self.getConfig('passkey'), + urllib.urlencode({'username' : self.get_config('username'), + 'password' : self.get_config('password'), 'captchaSource': "pyLoad", 'timeout' : "80"})) @@ -122,50 +118,50 @@ class CaptchaBrotherhood(Hook): def api_response(self, api, ticket): - res = getURL("%s%s.aspx" % (self.API_URL, api), - get={"username": self.getConfig('username'), - "password": self.getConfig('passkey'), - "captchaID": ticket}) + res = self.load("%s%s.aspx" % (self.API_URL, api), + get={'username': self.get_config('username'), + 'password': self.get_config('password'), + 'captchaID': ticket}) if not res.startswith("OK"): raise CaptchaBrotherhoodException("Unknown response: %s" % res) return res - def newCaptchaTask(self, task): + def captcha_task(self, task): if "service" in task.data: return False if not task.isTextual(): return False - if not self.getConfig('username') or not self.getConfig('passkey'): + if not self.get_config('username') or not self.get_config('password'): return False - if self.core.isClientConnected() and not self.getConfig('force'): + if self.pyload.isClientConnected() and self.get_config('check_client'): return False - if self.getCredits() > 10: + if self.get_credits() > 10: task.handler.append(self) task.data['service'] = self.__name__ task.setWaiting(100) - self._processCaptcha(task) + self._process_captcha(task) else: - self.logInfo(_("Your CaptchaBrotherhood Account has not enough credits")) + self.log_info(_("Your CaptchaBrotherhood Account has not enough credits")) - def captchaInvalid(self, task): - if task.data['service'] == self.__name__ and "ticket" in task.data: + def captcha_invalid(self, task): + if task.data['service'] is self.__name__ and "ticket" in task.data: res = self.api_response("complainCaptcha", task.data['ticket']) @threaded - def _processCaptcha(self, task): + def _process_captcha(self, task): c = task.captchaFile try: ticket, result = self.submit(c) except CaptchaBrotherhoodException, e: - task.error = e.getCode() + task.error = e.get_code() return task.data['ticket'] = ticket diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index ab7daf701..6ecbfcda2 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -7,11 +7,11 @@ import os import re import zlib -from module.plugins.Hook import Hook -from module.utils import save_join, fs_encode +from module.plugins.internal.Addon import Addon +from module.utils import save_join as fs_join, fs_encode -def computeChecksum(local_file, algorithm): +def compute_checksum(local_file, algorithm): if algorithm in getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")): h = getattr(hashlib, algorithm)() @@ -35,16 +35,17 @@ def computeChecksum(local_file, algorithm): return None -class Checksum(Hook): +class Checksum(Addon): __name__ = "Checksum" __type__ = "hook" - __version__ = "0.16" + __version__ = "0.19" + __status__ = "testing" - __config__ = [("check_checksum", "bool", "Check checksum? (If False only size will be verified)", True), - ("check_action", "fail;retry;nothing", "What to do if check fails?", "retry"), - ("max_tries", "int", "Number of retries", 2), - ("retry_action", "fail;nothing", "What to do if all retries fail?", "fail"), - ("wait_time", "int", "Time to wait before each retry (seconds)", 1)] + __config__ = [("check_checksum", "bool" , "Check checksum? (If False only size will be verified)", True ), + ("check_action" , "fail;retry;nothing", "What to do if check fails?" , "retry"), + ("max_tries" , "int" , "Number of retries" , 2 ), + ("retry_action" , "fail;nothing" , "What to do if all retries fail?" , "fail" ), + ("wait_time" , "int" , "Time to wait before each retry (seconds)" , 1 )] __description__ = """Verify downloaded file size and checksum""" __license__ = "GPLv3" @@ -53,7 +54,6 @@ class Checksum(Hook): ("stickell" , "l.stickell@yahoo.it")] - interval = 0 #@TODO: Remove in 0.4.10 methods = {'sfv' : 'crc32', 'crc' : 'crc32', 'hash': 'md5'} @@ -63,13 +63,12 @@ class Checksum(Hook): 'default': r'^(?P<HASH>[0-9A-Fa-f]+)\s+\*?(?P<NAME>.+)$'} - def coreReady(self): - if not self.getConfig('check_checksum'): - self.logInfo(_("Checksum validation is disabled in plugin configuration")) + def activate(self): + if not self.get_config('check_checksum'): + self.log_info(_("Checksum validation is disabled in plugin configuration")) - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 + def init(self): self.algorithms = sorted( getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")), reverse=True) @@ -78,12 +77,12 @@ class Checksum(Hook): self.formats = self.algorithms + ["sfv", "crc", "hash"] - def downloadFinished(self, pyfile): + def download_finished(self, pyfile): """ Compute checksum for the downloaded file and compare it with the hash provided by the hoster. pyfile.plugin.check_data should be a dictionary which can contain: - a) if known, the exact filesize in bytes (e.g. "size": 123456789) - b) hexadecimal hash string with algorithm name as key (e.g. "md5": "d76505d0869f9f928a17d42d66326307") + a) if known, the exact filesize in bytes (e.g. 'size': 123456789) + b) hexadecimal hash string with algorithm name as key (e.g. 'md5': "d76505d0869f9f928a17d42d66326307") """ if hasattr(pyfile.plugin, "check_data") and isinstance(pyfile.plugin.check_data, dict): data = pyfile.plugin.check_data.copy() @@ -98,31 +97,31 @@ class Checksum(Hook): else: return - self.logDebug(data) + self.log_debug(data) - if not pyfile.plugin.lastDownload: - self.checkFailed(pyfile, None, "No file downloaded") + if not pyfile.plugin.last_download: + self.check_failed(pyfile, None, "No file downloaded") - local_file = fs_encode(pyfile.plugin.lastDownload) - #download_folder = self.config['general']['download_folder'] - #local_file = fs_encode(save_join(download_folder, pyfile.package().folder, pyfile.name)) + local_file = fs_encode(pyfile.plugin.last_download) + # download_folder = self.pyload.config.get("general", "download_folder") + # local_file = fs_encode(fs_join(download_folder, pyfile.package().folder, pyfile.name)) if not os.path.isfile(local_file): - self.checkFailed(pyfile, None, "File does not exist") + self.check_failed(pyfile, None, "File does not exist") - # validate file size + #: Validate file size if "size" in data: api_size = int(data['size']) file_size = os.path.getsize(local_file) - if api_size != file_size: - self.logWarning(_("File %s has incorrect size: %d B (%d expected)") % (pyfile.name, file_size, api_size)) - self.checkFailed(pyfile, local_file, "Incorrect file size") + if api_size is not file_size: + self.log_warning(_("File %s has incorrect size: %d B (%d expected)") % (pyfile.name, file_size, api_size)) + self.check_failed(pyfile, local_file, "Incorrect file size") data.pop('size', None) - # validate checksum - if data and self.getConfig('check_checksum'): + #: Validate checksum + if data and self.get_config('check_checksum'): if not 'md5' in data: for type in ("checksum", "hashsum", "hash"): @@ -134,29 +133,29 @@ class Checksum(Hook): if key in data: checksum = computeChecksum(local_file, key.replace("-", "").lower()) if checksum: - if checksum == data[key].lower(): - self.logInfo(_('File integrity of "%s" verified by %s checksum (%s)') % + if checksum is data[key].lower(): + self.log_info(_('File integrity of "%s" verified by %s checksum (%s)') % (pyfile.name, key.upper(), checksum)) break else: - self.logWarning(_("%s checksum for file %s does not match (%s != %s)") % + self.log_warning(_("%s checksum for file %s does not match (%s != %s)") % (key.upper(), pyfile.name, checksum, data[key])) - self.checkFailed(pyfile, local_file, "Checksums do not match") + self.check_failed(pyfile, local_file, "Checksums do not match") else: - self.logWarning(_("Unsupported hashing algorithm"), key.upper()) + self.log_warning(_("Unsupported hashing algorithm"), key.upper()) else: - self.logWarning(_("Unable to validate checksum for file: ") + pyfile.name) + self.log_warning(_("Unable to validate checksum for file: ") + pyfile.name) - def checkFailed(self, pyfile, local_file, msg): - check_action = self.getConfig('check_action') + def check_failed(self, pyfile, local_file, msg): + check_action = self.get_config('check_action') if check_action == "retry": - max_tries = self.getConfig('max_tries') - retry_action = self.getConfig('retry_action') + max_tries = self.get_config('max_tries') + retry_action = self.get_config('retry_action') if pyfile.plugin.retries < max_tries: if local_file: os.remove(local_file) - pyfile.plugin.retry(max_tries, self.getConfig('wait_time'), msg) + pyfile.plugin.retry(max_tries, self.get_config('wait_time'), msg) elif retry_action == "nothing": return elif check_action == "nothing": @@ -164,18 +163,18 @@ class Checksum(Hook): pyfile.plugin.fail(reason=msg) - def packageFinished(self, pypack): - download_folder = save_join(self.config['general']['download_folder'], pypack.folder, "") + def package_finished(self, pypack): + download_folder = fs_join(self.pyload.config.get("general", "download_folder"), pypack.folder, "") - for link in pypack.getChildren().itervalues(): + for link in pypack.getChildren().values(): file_type = os.path.splitext(link['name'])[1][1:].lower() if file_type not in self.formats: continue - hash_file = fs_encode(save_join(download_folder, link['name'])) + hash_file = fs_encode(fs_join(download_folder, link['name'])) if not os.path.isfile(hash_file): - self.logWarning(_("File not found"), link['name']) + self.log_warning(_("File not found"), link['name']) continue with open(hash_file) as f: @@ -183,14 +182,14 @@ class Checksum(Hook): for m in re.finditer(self.regexps.get(file_type, self.regexps['default']), text): data = m.groupdict() - self.logDebug(link['name'], data) + self.log_debug(link['name'], data) - local_file = fs_encode(save_join(download_folder, data['NAME'])) + local_file = fs_encode(fs_join(download_folder, data['NAME'])) algorithm = self.methods.get(file_type, file_type) checksum = computeChecksum(local_file, algorithm) - if checksum == data['HASH']: - self.logInfo(_('File integrity of "%s" verified by %s checksum (%s)') % + if checksum is data['HASH']: + self.log_info(_('File integrity of "%s" verified by %s checksum (%s)') % (data['NAME'], algorithm, checksum)) else: - self.logWarning(_("%s checksum for file %s does not match (%s != %s)") % + self.log_warning(_("%s checksum for file %s does not match (%s != %s)") % (algorithm, data['NAME'], checksum, data['HASH'])) diff --git a/module/plugins/hooks/ClickAndLoad.py b/module/plugins/hooks/ClickAndLoad.py index a7862045e..ba03129e6 100644 --- a/module/plugins/hooks/ClickAndLoad.py +++ b/module/plugins/hooks/ClickAndLoad.py @@ -10,7 +10,7 @@ except ImportError: from threading import Lock -from module.plugins.Hook import Hook, threaded +from module.plugins.internal.Addon import Addon, threaded def forward(source, destination): @@ -22,14 +22,15 @@ def forward(source, destination): bufdata = source.recv(bufsize) finally: destination.shutdown(socket.SHUT_WR) - # destination.close() + #: destination.close() #@TODO: IPv6 support -class ClickAndLoad(Hook): +class ClickAndLoad(Addon): __name__ = "ClickAndLoad" __type__ = "hook" - __version__ = "0.43" + __version__ = "0.45" + __status__ = "testing" __config__ = [("activated", "bool", "Activated" , True), ("port" , "int" , "Port" , 9666), @@ -41,20 +42,13 @@ class ClickAndLoad(Hook): ("Walter Purcaro", "vuolter@gmail.com")] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - - def coreReady(self): - if not self.config['webinterface']['activated']: + def activate(self): + if not self.pyload.config.get("webinterface", "activated"): return - ip = "" if self.getConfig('extern') else "127.0.0.1" - webport = self.config['webinterface']['port'] - cnlport = self.getConfig('port') + ip = "" if self.get_config('extern') else "127.0.0.1" + webport = self.pyload.config.get("webinterface", "port") + cnlport = self.get_config('port') self.proxy(ip, webport, cnlport) @@ -63,7 +57,7 @@ class ClickAndLoad(Hook): def proxy(self, ip, webport, cnlport): time.sleep(10) #@TODO: Remove in 0.4.10 (implement addon delay on startup) - self.logInfo(_("Proxy listening on %s:%s") % (ip or "0.0.0.0", cnlport)) + self.log_info(_("Proxy listening on %s:%s") % (ip or "0.0.0.0", cnlport)) self._server(ip, webport, cnlport) @@ -81,22 +75,22 @@ class ClickAndLoad(Hook): while True: client_socket, client_addr = dock_socket.accept() - self.logDebug("Connection from %s:%s" % client_addr) + self.log_debug("Connection from %s:%s" % client_addr) server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - if self.config['webinterface']['https']: + if self.pyload.config.get("webinterface", "https"): try: server_socket = ssl.wrap_socket(server_socket) except NameError: - self.logError(_("pyLoad's webinterface is configured to use HTTPS, Please install python's ssl lib or disable HTTPS")) - client_socket.close() #: reset the connection. + self.log_error(_("pyLoad's webinterface is configured to use HTTPS, Please install python's ssl lib or disable HTTPS")) + client_socket.close() #: Reset the connection. continue except Exception, e: - self.logError(_("SSL error: %s") % e.message) - client_socket.close() #: reset the connection. + self.log_error(_("SSL error: %s") % e.message) + client_socket.close() #: Reset the connection. continue server_socket.connect(("127.0.0.1", webport)) @@ -105,10 +99,10 @@ class ClickAndLoad(Hook): self.manager.startThread(forward, server_socket, client_socket) except socket.timeout: - self.logDebug("Connection timed out, retrying...") + self.log_debug("Connection timed out, retrying...") return self._server(ip, webport, cnlport) except socket.error, e: - self.logError(e) + self.log_error(e) time.sleep(240) return self._server(ip, webport, cnlport) diff --git a/module/plugins/hooks/DeathByCaptcha.py b/module/plugins/hooks/DeathByCaptcha.py index f9618f011..98572191e 100644 --- a/module/plugins/hooks/DeathByCaptcha.py +++ b/module/plugins/hooks/DeathByCaptcha.py @@ -10,8 +10,8 @@ from base64 import b64encode from module.common.json_layer import json_loads from module.network.HTTPRequest import BadHeader -from module.network.RequestFactory import getRequest -from module.plugins.Hook import Hook, threaded +from module.network.RequestFactory import getRequest as get_request +from module.plugins.internal.Hook import Hook, threaded class DeathByCaptchaException(Exception): @@ -29,11 +29,11 @@ class DeathByCaptchaException(Exception): self.err = err - def getCode(self): + def get_code(self): return self.err - def getDesc(self): + def get_desc(self): if self.err in self.DBC_ERRORS.keys(): return self.DBC_ERRORS[self.err] else: @@ -51,11 +51,12 @@ class DeathByCaptchaException(Exception): class DeathByCaptcha(Hook): __name__ = "DeathByCaptcha" __type__ = "hook" - __version__ = "0.06" + __version__ = "0.08" + __status__ = "testing" - __config__ = [("username", "str", "Username", ""), - ("passkey", "password", "Password", ""), - ("force", "bool", "Force DBC even if client is connected", False)] + __config__ = [("username" , "str" , "Username" , "" ), + ("password" , "password", "Password" , "" ), + ("check_client", "bool" , "Don't use if client is connected", True)] __description__ = """Send captchas to DeathByCaptcha.com""" __license__ = "GPLv3" @@ -63,31 +64,27 @@ class DeathByCaptcha(Hook): ("zoidberg", "zoidberg@mujmail.cz")] - interval = 0 #@TODO: Remove in 0.4.10 - API_URL = "http://api.dbcapi.me/api/" - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - def api_response(self, api="captcha", post=False, multipart=False): - req = getRequest() - req.c.setopt(pycurl.HTTPHEADER, ["Accept: application/json", "User-Agent: pyLoad %s" % self.core.version]) + req = get_request() + req.c.setopt(pycurl.HTTPHEADER, ["Accept: application/json", "User-Agent: pyLoad %s" % self.pyload.version]) if post: if not isinstance(post, dict): post = {} - post.update({"username": self.getConfig('username'), - "password": self.getConfig('passkey')}) + post.update({'username': self.get_config('username'), + 'password': self.get_config('password')}) res = None try: - json = req.load("%s%s" % (self.API_URL, api), - post=post, - multipart=multipart) - self.logDebug(json) + json = self.load("%s%s" % (self.API_URL, api), + post=post, + multipart=multipart, + req=req) + + self.log_debug(json) res = json_loads(json) if "error" in res: @@ -96,11 +93,11 @@ class DeathByCaptcha(Hook): raise DeathByCaptchaException(str(res)) except BadHeader, e: - if 403 == e.code: + if 403 is e.code: raise DeathByCaptchaException('not-logged-in') - elif 413 == e.code: + elif 413 is e.code: raise DeathByCaptchaException('invalid-captcha') - elif 503 == e.code: + elif 503 is e.code: raise DeathByCaptchaException('service-overload') elif e.code in (400, 405): raise DeathByCaptchaException('invalid-request') @@ -113,7 +110,7 @@ class DeathByCaptcha(Hook): return res - def getCredits(self): + def get_credits(self): res = self.api_response("user", True) if 'is_banned' in res and res['is_banned']: @@ -124,7 +121,7 @@ class DeathByCaptcha(Hook): raise DeathByCaptchaException(res) - def getStatus(self): + def get_status(self): res = self.api_response("status", False) if 'is_service_overloaded' in res and res['is_service_overloaded']: @@ -133,7 +130,7 @@ class DeathByCaptcha(Hook): def submit(self, captcha, captchaType="file", match=None): #@NOTE: Workaround multipart-post bug in HTTPRequest.py - if re.match("^\w*$", self.getConfig('passkey')): + if re.match("^\w*$", self.get_config('password')): multipart = True data = (pycurl.FORM_FILE, captcha) else: @@ -142,7 +139,7 @@ class DeathByCaptcha(Hook): data = f.read() data = "base64:" + b64encode(data) - res = self.api_response("captcha", {"captchafile": data}, multipart) + res = self.api_response("captcha", {'captchafile': data}, multipart) if "captcha" not in res: raise DeathByCaptchaException(res) @@ -157,33 +154,33 @@ class DeathByCaptcha(Hook): raise DeathByCaptchaException('timed-out') result = res['text'] - self.logDebug("Result %s : %s" % (ticket, result)) + self.log_debug("Result %s : %s" % (ticket, result)) return ticket, result - def newCaptchaTask(self, task): + def captcha_task(self, task): if "service" in task.data: return False if not task.isTextual(): return False - if not self.getConfig('username') or not self.getConfig('passkey'): + if not self.get_config('username') or not self.get_config('password'): return False - if self.core.isClientConnected() and not self.getConfig('force'): + if self.pyload.isClientConnected() and self.get_config('check_client'): return False try: - self.getStatus() - self.getCredits() + self.get_status() + self.get_credits() except DeathByCaptchaException, e: - self.logError(e.getDesc()) + self.log_error(e.getDesc()) return False balance, rate = self.info['balance'], self.info['rate'] - self.logInfo(_("Account balance"), + self.log_info(_("Account balance"), _("US$%.3f (%d captchas left at %.2f cents each)") % (balance / 100, balance // rate, rate)) @@ -191,29 +188,29 @@ class DeathByCaptcha(Hook): task.handler.append(self) task.data['service'] = self.__name__ task.setWaiting(180) - self._processCaptcha(task) + self._process_captcha(task) - def captchaInvalid(self, task): - if task.data['service'] == self.__name__ and "ticket" in task.data: + def captcha_invalid(self, task): + if task.data['service'] is self.__name__ and "ticket" in task.data: try: res = self.api_response("captcha/%d/report" % task.data['ticket'], True) except DeathByCaptchaException, e: - self.logError(e.getDesc()) + self.log_error(e.getDesc()) except Exception, e: - self.logError(e) + self.log_error(e) @threaded - def _processCaptcha(self, task): + def _process_captcha(self, task): c = task.captchaFile try: ticket, result = self.submit(c) except DeathByCaptchaException, e: - task.error = e.getCode() - self.logError(e.getDesc()) + task.error = e.get_code() + self.log_error(e.getDesc()) return task.data['ticket'] = ticket diff --git a/module/plugins/hooks/DebridItaliaComHook.py b/module/plugins/hooks/DebridItaliaComHook.py index 36b307696..1b000c665 100644 --- a/module/plugins/hooks/DebridItaliaComHook.py +++ b/module/plugins/hooks/DebridItaliaComHook.py @@ -8,13 +8,13 @@ from module.plugins.internal.MultiHook import MultiHook class DebridItaliaComHook(MultiHook): __name__ = "DebridItaliaComHook" __type__ = "hook" - __version__ = "0.12" + __version__ = "0.13" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Debriditalia.com hook plugin""" __license__ = "GPLv3" @@ -22,5 +22,5 @@ class DebridItaliaComHook(MultiHook): ("Walter Purcaro", "vuolter@gmail.com" )] - def getHosters(self): - return self.getURL("http://debriditalia.com/api.php", get={'hosts': ""}).replace('"', '').split(',') + def get_hosters(self): + return self.load("http://debriditalia.com/api.php", get={'hosts': ""}).replace('"', '').split(',') diff --git a/module/plugins/hooks/DeleteFinished.py b/module/plugins/hooks/DeleteFinished.py index be17c3c0f..75a282808 100644 --- a/module/plugins/hooks/DeleteFinished.py +++ b/module/plugins/hooks/DeleteFinished.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- from module.database import style -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon -class DeleteFinished(Hook): +class DeleteFinished(Addon): __name__ = "DeleteFinished" __type__ = "hook" - __version__ = "1.12" + __version__ = "1.14" + __status__ = "testing" __config__ = [("interval" , "int" , "Check interval in hours" , 72 ), ("deloffline", "bool", "Delete package with offline links", False)] @@ -21,59 +22,60 @@ class DeleteFinished(Hook): ## overwritten methods ## - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - # self.event_list = ["pluginConfigChanged"] + def init(self): + # self.event_map = {'pluginConfigChanged': "plugin_config_changed"} self.interval = self.MIN_CHECK_INTERVAL def periodical(self): if not self.info['sleep']: - deloffline = self.getConfig('deloffline') - mode = '0,1,4' if deloffline else '0,4' + deloffline = self.get_config('deloffline') + mode = "0,1,4" if deloffline else "0,4" msg = _('delete all finished packages in queue list (%s packages with offline links)') - self.logInfo(msg % (_('including') if deloffline else _('excluding'))) - self.deleteFinished(mode) + self.log_info(msg % (_('including') if deloffline else _('excluding'))) + self.delete_finished(mode) self.info['sleep'] = True - self.addEvent('packageFinished', self.wakeup) + self.add_event('package_finished', self.wakeup) - # def pluginConfigChanged(self, plugin, name, value): - # if name == "interval" and value != self.interval: + # def plugin_config_changed(self, plugin, name, value): + # if name == "interval" and value is not self.interval: # self.interval = value * 3600 - # self.initPeriodical() + # self.init_periodical() - def unload(self): - self.manager.removeEvent('packageFinished', self.wakeup) + def deactivate(self): + self.manager.removeEvent('package_finished', self.wakeup) - def coreReady(self): + def activate(self): self.info['sleep'] = True - # interval = self.getConfig('interval') - # self.pluginConfigChanged(self.__name__, 'interval', interval) - self.interval = max(self.MIN_CHECK_INTERVAL, self.getConfig('interval') * 60 * 60) - self.addEvent('packageFinished', self.wakeup) + # interval = self.get_config('interval') + # self.plugin_config_changed(self.__name__, 'interval', interval) + self.interval = max(self.MIN_CHECK_INTERVAL, self.get_config('interval') * 60 * 60) + self.add_event('package_finished', self.wakeup) ## own methods ## @style.queue - def deleteFinished(self, mode): + def delete_finished(self, mode): self.c.execute('DELETE FROM packages WHERE NOT EXISTS(SELECT 1 FROM links WHERE package=packages.id AND status NOT IN (%s))' % mode) self.c.execute('DELETE FROM links WHERE NOT EXISTS(SELECT 1 FROM packages WHERE id=links.package)') def wakeup(self, pypack): - self.manager.removeEvent('packageFinished', self.wakeup) + self.manager.removeEvent('package_finished', self.wakeup) self.info['sleep'] = False ## event managing ## - def addEvent(self, event, func): - """Adds an event listener for event name""" + def add_event(self, event, func): + """ + Adds an event listener for event name + """ if event in self.manager.events: if func in self.manager.events[event]: - self.logDebug("Function already registered", func) + self.log_debug("Function already registered", func) else: self.manager.events[event].append(func) else: diff --git a/module/plugins/hooks/DownloadScheduler.py b/module/plugins/hooks/DownloadScheduler.py index 9c74ac1d4..b2e804dce 100644 --- a/module/plugins/hooks/DownloadScheduler.py +++ b/module/plugins/hooks/DownloadScheduler.py @@ -3,17 +3,17 @@ import re import time -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon -class DownloadScheduler(Hook): +class DownloadScheduler(Addon): __name__ = "DownloadScheduler" __type__ = "hook" - __version__ = "0.22" + __version__ = "0.24" + __status__ = "testing" - __config__ = [("timetable", "str", "List time periods as hh:mm full or number(kB/s)", - "0:00 full, 7:00 250, 10:00 0, 17:00 150"), - ("abort", "bool", "Abort active downloads when start period with speed 0", False)] + __config__ = [("timetable", "str" , "List time periods as hh:mm full or number(kB/s)" , "0:00 full, 7:00 250, 10:00 0, 17:00 150"), + ("abort" , "bool", "Abort active downloads when start period with speed 0", False )] __description__ = """Download Scheduler""" __license__ = "GPLv3" @@ -21,61 +21,53 @@ class DownloadScheduler(Hook): ("stickell", "l.stickell@yahoo.it")] - interval = 0 #@TODO: Remove in 0.4.10 + def activate(self): + self.update_schedule() - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - self.cb = None # callback to scheduler job; will be by removed hookmanager when hook unloaded - - - def coreReady(self): - self.updateSchedule() - - - def updateSchedule(self, schedule=None): + def update_schedule(self, schedule=None): if schedule is None: - schedule = self.getConfig('timetable') + schedule = self.get_config('timetable') schedule = re.findall("(\d{1,2}):(\d{2})[\s]*(-?\d+)", schedule.lower().replace("full", "-1").replace("none", "0")) if not schedule: - self.logError(_("Invalid schedule")) + self.log_error(_("Invalid schedule")) return t0 = time.localtime() now = (t0.tm_hour, t0.tm_min, t0.tm_sec, "X") schedule = sorted([(int(x[0]), int(x[1]), 0, int(x[2])) for x in schedule] + [now]) - self.logDebug("Schedule", schedule) + self.log_debug("Schedule", schedule) for i, v in enumerate(schedule): if v[3] == "X": last, next = schedule[i - 1], schedule[(i + 1) % len(schedule)] - self.logDebug("Now/Last/Next", now, last, next) + self.log_debug("Now/Last/Next", now, last, next) - self.setDownloadSpeed(last[3]) + self.set_download_speed(last[3]) next_time = (((24 + next[0] - now[0]) * 60 + next[1] - now[1]) * 60 + next[2] - now[2]) % 86400 - self.core.scheduler.removeJob(self.cb) - self.cb = self.core.scheduler.addJob(next_time, self.updateSchedule, threaded=False) + self.pyload.scheduler.removeJob(self.cb) + self.cb = self.pyload.scheduler.addJob(next_time, self.update_schedule, threaded=False) - def setDownloadSpeed(self, speed): + def set_download_speed(self, speed): if speed == 0: - abort = self.getConfig('abort') - self.logInfo(_("Stopping download server. (Running downloads will %sbe aborted.)") % '' if abort else _('not ')) - self.core.api.pauseServer() + abort = self.get_config('abort') + self.log_info(_("Stopping download server. (Running downloads will %sbe aborted.)") % '' if abort else _('not ')) + self.pyload.api.pauseServer() if abort: - self.core.api.stopAllDownloads() + self.pyload.api.stopAllDownloads() else: - self.core.api.unpauseServer() + self.pyload.api.unpauseServer() if speed > 0: - self.logInfo(_("Setting download speed to %d kB/s") % speed) - self.core.api.setConfigValue("download", "limit_speed", 1) - self.core.api.setConfigValue("download", "max_speed", speed) + self.log_info(_("Setting download speed to %d kB/s") % speed) + self.pyload.config.set("download", "limit_speed", 1) + self.pyload.config.set("download", "max_speed", speed) else: - self.logInfo(_("Setting download speed to FULL")) - self.core.api.setConfigValue("download", "limit_speed", 0) - self.core.api.setConfigValue("download", "max_speed", -1) + self.log_info(_("Setting download speed to FULL")) + self.pyload.config.set("download", "limit_speed", 0) + self.pyload.config.set("download", "max_speed", -1) diff --git a/module/plugins/hooks/EasybytezComHook.py b/module/plugins/hooks/EasybytezComHook.py index 43efb5048..6f53619ac 100644 --- a/module/plugins/hooks/EasybytezComHook.py +++ b/module/plugins/hooks/EasybytezComHook.py @@ -8,23 +8,23 @@ from module.plugins.internal.MultiHook import MultiHook class EasybytezComHook(MultiHook): __name__ = "EasybytezComHook" __type__ = "hook" - __version__ = "0.07" + __version__ = "0.08" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """EasyBytez.com hook plugin""" __license__ = "GPLv3" __authors__ = [("zoidberg", "zoidberg@mujmail.cz")] - def getHosters(self): - user, data = self.account.selectAccount() + def get_hosters(self): + user, info = self.account.select() - req = self.account.getAccountRequest(user) - html = req.load("http://www.easybytez.com") + html = self.load("http://www.easybytez.com", + req=self.account.get_request(user)) return re.search(r'</textarea>\s*Supported sites:(.*)', html).group(1).split(',') diff --git a/module/plugins/hooks/ExpertDecoders.py b/module/plugins/hooks/ExpertDecoders.py index ccd48f664..630382f2d 100644 --- a/module/plugins/hooks/ExpertDecoders.py +++ b/module/plugins/hooks/ExpertDecoders.py @@ -8,17 +8,18 @@ import uuid from base64 import b64encode from module.network.HTTPRequest import BadHeader -from module.network.RequestFactory import getURL, getRequest -from module.plugins.Hook import Hook, threaded +from module.network.RequestFactory import getRequest as get_request +from module.plugins.internal.Hook import Hook, threaded class ExpertDecoders(Hook): __name__ = "ExpertDecoders" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.06" + __status__ = "testing" - __config__ = [("force", "bool", "Force CT even if client is connected", False), - ("passkey", "password", "Access key", "")] + __config__ = [("passkey" , "password", "Access key" , "" ), + ("check_client", "bool" , "Don't use if client is connected", True)] __description__ = """Send captchas to expertdecoders.com""" __license__ = "GPLv3" @@ -26,78 +27,73 @@ class ExpertDecoders(Hook): ("zoidberg", "zoidberg@mujmail.cz")] - interval = 0 #@TODO: Remove in 0.4.10 - API_URL = "http://www.fasttypers.org/imagepost.ashx" - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - - def getCredits(self): - res = getURL(self.API_URL, post={"key": self.getConfig('passkey'), "action": "balance"}) + def get_credits(self): + res = self.load(self.API_URL, post={'key': self.get_config('passkey'), 'action': "balance"}) if res.isdigit(): - self.logInfo(_("%s credits left") % res) + self.log_info(_("%s credits left") % res) self.info['credits'] = credits = int(res) return credits else: - self.logError(res) + self.log_error(res) return 0 @threaded - def _processCaptcha(self, task): + def _process_captcha(self, task): task.data['ticket'] = ticket = uuid.uuid4() result = None with open(task.captchaFile, 'rb') as f: data = f.read() - req = getRequest() - #raise timeout threshold + req = get_request() + #: Raise timeout threshold req.c.setopt(pycurl.LOW_SPEED_TIME, 80) try: - result = req.load(self.API_URL, - post={'action' : "upload", - 'key' : self.getConfig('passkey'), + result = self.load(self.API_URL, + post={'action' : "upload", + 'key' : self.get_config('passkey'), 'file' : b64encode(data), - 'gen_task_id': ticket}) + 'gen_task_id': ticket}, + req=req) finally: req.close() - self.logDebug("Result %s : %s" % (ticket, result)) + self.log_debug("Result %s : %s" % (ticket, result)) task.setResult(result) - def newCaptchaTask(self, task): + def captcha_task(self, task): if not task.isTextual(): return False - if not self.getConfig('passkey'): + if not self.get_config('passkey'): return False - if self.core.isClientConnected() and not self.getConfig('force'): + if self.pyload.isClientConnected() and self.get_config('check_client'): return False - if self.getCredits() > 0: + if self.get_credits() > 0: task.handler.append(self) task.setWaiting(100) - self._processCaptcha(task) + self._process_captcha(task) else: - self.logInfo(_("Your ExpertDecoders Account has not enough credits")) + self.log_info(_("Your ExpertDecoders Account has not enough credits")) - def captchaInvalid(self, task): + def captcha_invalid(self, task): if "ticket" in task.data: try: - res = getURL(self.API_URL, - post={'action': "refund", 'key': self.getConfig('passkey'), 'gen_task_id': task.data['ticket']}) - self.logInfo(_("Request refund"), res) + res = self.load(self.API_URL, + post={'action': "refund", 'key': self.get_config('passkey'), 'gen_task_id': task.data['ticket']}) + self.log_info(_("Request refund"), res) except BadHeader, e: - self.logError(_("Could not send refund request"), e) + self.log_error(_("Could not send refund request"), e) diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index a0815499b..b7495136a 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -3,17 +3,18 @@ import os import subprocess -from module.plugins.Hook import Hook -from module.utils import fs_encode, save_join +from module.plugins.internal.Addon import Addon, Expose +from module.utils import fs_encode, save_join as fs_join -class ExternalScripts(Hook): +class ExternalScripts(Addon): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.39" + __version__ = "0.46" + __status__ = "testing" __config__ = [("activated", "bool", "Activated" , True ), - ("waitend" , "bool", "Wait script ending", False)] + ("lock" , "bool", "Wait script ending", False)] __description__ = """Run external scripts""" __license__ = "GPLv3" @@ -23,18 +24,16 @@ class ExternalScripts(Hook): ("Walter Purcaro", "vuolter@gmail.com")] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - self.info = {'oldip': None} + def init(self): + self.info['oldip'] = None self.scripts = {} self.event_list = ["archive_extract_failed", "archive_extracted" , "package_extract_failed", "package_extracted" , - "all_archives_extracted", "all_archives_processed", - "allDownloadsFinished" , "allDownloadsProcessed" , - "packageDeleted"] + "all_archives_extracted", "all_archives_processed"] + self.event_map = {'allDownloadsFinished' : "all_downloads_finished" , + 'allDownloadsProcessed': "all_downloads_processed", + 'packageDeleted' : "package_deleted" } folders = ["pyload_start", "pyload_restart", "pyload_stop", "before_reconnect", "after_reconnect", @@ -45,174 +44,204 @@ class ExternalScripts(Hook): "all_archives_extracted", "all_archives_processed"] for folder in folders: - self.scripts[folder] = [] - for dir in (pypath, ''): - self.initPluginType(folder, os.path.join(dir, 'scripts', folder)) + path = os.path.join("scripts", folder) + self.init_folder(folder, path) - for script_type, names in self.scripts.iteritems(): - if names: - self.logInfo(_("Installed scripts for: ") + script_type, ", ".join(map(os.path.basename, names))) + for folder, scripts in self.scripts.items(): + if scripts: + self.log_info(_("Installed scripts in folder `%s`: %s") + % (folder, ", ".join(scripts))) self.pyload_start() - def initPluginType(self, name, dir): - if not os.path.isdir(dir): + def init_folder(self, name, path): + self.scripts[name] = [] + + if not os.path.isdir(path): try: - os.makedirs(dir) + os.makedirs(path) except OSError, e: - self.logDebug(e) + self.log_debug(e) return - for filename in os.listdir(dir): - file = save_join(dir, filename) - + for file in os.listdir(path): if not os.path.isfile(file): continue - if filename[0] in ("#", "_") or filename.endswith("~") or filename.endswith(".swp"): + if file[0] in ("#", "_") or file.endswith("~") or file.endswith(".swp"): continue if not os.access(file, os.X_OK): - self.logWarning(_("Script not executable:") + " %s/%s" % (name, filename)) + self.log_warning(_("Script not executable: [%s] %s") % (name, file)) self.scripts[name].append(file) - def callScript(self, script, *args): + @Expose + def call(self, script, args=[], lock=False): try: - cmd_args = [fs_encode(str(x) if not isinstance(x, basestring) else x) for x in args] - cmd = [script] + cmd_args - - self.logDebug("Executing: %s" % os.path.abspath(script), "Args: " + ' '.join(cmd_args)) + script = os.path.abspath(script) + args = [script] + map(encode, args) - p = subprocess.Popen(cmd, bufsize=-1) #@NOTE: output goes to pyload - if self.getConfig('waitend'): + self.log_info(_("EXECUTE [%s] %s") % (os.path.dirname(script), args)) + p = subprocess.Popen(args, bufsize=-1) #@NOTE: output goes to pyload + if lock: p.communicate() except Exception, e: - try: - self.logError(_("Runtime error: %s") % os.path.abspath(script), e) - except Exception: - self.logError(_("Runtime error: %s") % os.path.abspath(script), _("Unknown error")) + self.log_error(_("Runtime error: %s") % script, e or _("Unknown error")) def pyload_start(self): + lock = self.get_config('lock') for script in self.scripts['pyload_start']: - self.callScript(script) + self.call(script, lock=lock) - def coreExiting(self): - for script in self.scripts['pyload_restart' if self.core.do_restart else 'pyload_stop']: - self.callScript(script) + def exit(self): + lock = self.get_config('lock') + for script in self.scripts['pyload_restart' if self.pyload.do_restart else 'pyload_stop']: + self.call(script, lock=True) - def beforeReconnecting(self, ip): + def before_reconnect(self, ip): + lock = self.get_config('lock') for script in self.scripts['before_reconnect']: - self.callScript(script, ip) + args = [ip] + self.call(script, args, lock) self.info['oldip'] = ip - def afterReconnecting(self, ip): + def after_reconnect(self, ip): + lock = self.get_config('lock') for script in self.scripts['after_reconnect']: - self.callScript(script, ip, self.info['oldip']) #@TODO: Use built-in oldip in 0.4.10 + args = [ip, self.info['oldip']] #@TODO: Use built-in oldip in 0.4.10 + self.call(script, args, lock) - def downloadPreparing(self, pyfile): + def download_preparing(self, pyfile): + lock = self.get_config('lock') for script in self.scripts['download_preparing']: - self.callScript(script, pyfile.id, pyfile.name, None, pyfile.pluginname, pyfile.url) + args = [pyfile.id, pyfile.name, None, pyfile.pluginname, pyfile.url] + self.call(script, args, lock) - def downloadFailed(self, pyfile): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder) + def download_failed(self, pyfile): + lock = self.get_config('lock') + + if self.pyload.config.get("general", "folder_per_package"): + download_folder = fs_join(self.pyload.config.get("general", "download_folder"), pyfile.package().folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.pyload.config.get("general", "download_folder") for script in self.scripts['download_failed']: - file = save_join(download_folder, pyfile.name) - self.callScript(script, pyfile.id, pyfile.name, file, pyfile.pluginname, pyfile.url) + file = fs_join(download_folder, pyfile.name) + args = [script, pyfile.id, pyfile.name, file, pyfile.pluginname, pyfile.url] + self.call(script, args, lock) + + def download_finished(self, pyfile): + lock = self.get_config('lock') - def downloadFinished(self, pyfile): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder) + if self.pyload.config.get("general", "folder_per_package"): + download_folder = fs_join(self.pyload.config.get("general", "download_folder"), pyfile.package().folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.pyload.config.get("general", "download_folder") for script in self.scripts['download_finished']: - file = save_join(download_folder, pyfile.name) - self.callScript(script, pyfile.id, pyfile.name, file, pyfile.pluginname, pyfile.url) + file = fs_join(download_folder, pyfile.name) + args = [pyfile.id, pyfile.name, file, pyfile.pluginname, pyfile.url] + self.call(script, args, lock) def archive_extract_failed(self, pyfile, archive): + lock = self.get_config('lock') for script in self.scripts['archive_extract_failed']: - self.callScript(script, pyfile.id, pyfile.name, archive.filename, archive.out, archive.files) + args = [pyfile.id, pyfile.name, archive.filename, archive.out, archive.files] + self.call(script, args, lock) def archive_extracted(self, pyfile, archive): + lock = self.get_config('lock') for script in self.scripts['archive_extracted']: - self.callScript(script, pyfile.id, pyfile.name, archive.filename, archive.out, archive.files) + args = [script, pyfile.id, pyfile.name, archive.filename, archive.out, archive.files] + self.call(script, args, lock) + + def package_finished(self, pypack): + lock = self.get_config('lock') - def packageFinished(self, pypack): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + if self.pyload.config.get("general", "folder_per_package"): + download_folder = fs_join(self.pyload.config.get("general", "download_folder"), pypack.folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.pyload.config.get("general", "download_folder") for script in self.scripts['package_finished']: - self.callScript(script, pypack.id, pypack.name, download_folder, pypack.password) + args = [pypack.id, pypack.name, download_folder, pypack.password] + self.call(script, args, lock) - def packageDeleted(self, pid): - pack = self.core.api.getPackageInfo(pid) + def package_deleted(self, pid): + lock = self.get_config('lock') + pack = self.pyload.api.getPackageInfo(pid) - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pack.folder) + if self.pyload.config.get("general", "folder_per_package"): + download_folder = fs_join(self.pyload.config.get("general", "download_folder"), pack.folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.pyload.config.get("general", "download_folder") for script in self.scripts['package_deleted']: - self.callScript(script, pack.id, pack.name, download_folder, pack.password) + args = [pack.id, pack.name, download_folder, pack.password] + self.call(script, args, lock) def package_extract_failed(self, pypack): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + lock = self.get_config('lock') + + if self.pyload.config.get("general", "folder_per_package"): + download_folder = fs_join(self.pyload.config.get("general", "download_folder"), pypack.folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.pyload.config.get("general", "download_folder") for script in self.scripts['package_extract_failed']: - self.callScript(script, pypack.id, pypack.name, download_folder, pypack.password) + args = [pypack.id, pypack.name, download_folder, pypack.password] + self.call(script, args, lock) def package_extracted(self, pypack): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + lock = self.get_config('lock') + + if self.pyload.config.get("general", "folder_per_package"): + download_folder = fs_join(self.pyload.config.get("general", "download_folder"), pypack.folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.pyload.config.get("general", "download_folder") for script in self.scripts['package_extracted']: - self.callScript(script, pypack.id, pypack.name, download_folder) + args = [pypack.id, pypack.name, download_folder] + self.call(script, args, lock) - def allDownloadsFinished(self): + def all_downloads_finished(self): + lock = self.get_config('lock') for script in self.scripts['all_downloads_finished']: - self.callScript(script) + self.call(script, lock=lock) - def allDownloadsProcessed(self): + def all_downloads_processed(self): + lock = self.get_config('lock') for script in self.scripts['all_downloads_processed']: - self.callScript(script) + self.call(script, lock=lock) def all_archives_extracted(self): + lock = self.get_config('lock') for script in self.scripts['all_archives_extracted']: - self.callScript(script) + self.call(script, lock=lock) def all_archives_processed(self): + lock = self.get_config('lock') for script in self.scripts['all_archives_processed']: - self.callScript(script) + self.call(script, lock=lock) diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 3e371ec2b..eab196160 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -23,10 +23,12 @@ if sys.version_info < (2, 7) and os.name != "nt": raise - # unsued timeout option for older python version + #: Unsued timeout option for older python version def wait(self, timeout=0): - """Wait for child process to terminate. Returns returncode - attribute.""" + """ + Wait for child process to terminate. Returns returncode + attribute. + """ if self.returncode is None: try: pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0) @@ -34,9 +36,9 @@ if sys.version_info < (2, 7) and os.name != "nt": except OSError, e: if e.errno != errno.ECHILD: raise - # This happens if SIGCLD is set to be ignored or waiting - # for child processes has otherwise been disabled for our - # process. This child is dead, we can't get the status. + #: This happens if SIGCLD is set to be ignored or waiting + #: For child processes has otherwise been disabled for our + #: process. This child is dead, we can't get the status. sts = 0 self._handle_exitstatus(sts) return self.returncode @@ -48,15 +50,10 @@ try: except ImportError: pass -from copy import copy -if os.name != "nt": - from grp import getgrnam - from pwd import getpwnam - -from module.plugins.Hook import Hook, Expose, threaded +from module.plugins.internal.Addon import Addon, Expose, threaded +from module.plugins.internal.Plugin import replace_patterns from module.plugins.internal.Extractor import ArchiveError, CRCError, PasswordError -from module.plugins.internal.SimpleHoster import replace_patterns -from module.utils import fs_encode, save_join, uniqify +from module.utils import fs_encode, save_join as fs_join, uniqify class ArchiveQueue(object): @@ -68,7 +65,7 @@ class ArchiveQueue(object): def get(self): try: - return [int(pid) for pid in self.plugin.getStorage("ExtractArchive:%s" % self.storage, "").decode('base64').split()] + return [int(pid) for pid in self.plugin.retrieve("ExtractArchive:%s" % self.storage, "").decode('base64').split()] except Exception: return [] @@ -78,11 +75,11 @@ class ArchiveQueue(object): item = str(value)[1:-1].replace(' ', '').replace(',', ' ') else: item = str(value).strip() - return self.plugin.setStorage("ExtractArchive:%s" % self.storage, item.encode('base64')[:-1]) + return self.plugin.store("ExtractArchive:%s" % self.storage, item.encode('base64')[:-1]) def delete(self): - return self.plugin.delStorage("ExtractArchive:%s" % self.storage) + return self.plugin.delete("ExtractArchive:%s" % self.storage) def add(self, item): @@ -101,16 +98,17 @@ class ArchiveQueue(object): except ValueError: pass - if queue == []: + if queue is []: return self.delete() return self.set(queue) -class ExtractArchive(Hook): +class ExtractArchive(Addon): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "1.44" + __version__ = "1.49" + __status__ = "testing" __config__ = [("activated" , "bool" , "Activated" , True ), ("fullpath" , "bool" , "Extract with full paths" , True ), @@ -119,7 +117,7 @@ class ExtractArchive(Hook): ("repair" , "bool" , "Repair broken archives (RAR required)" , False ), ("test" , "bool" , "Test archive before extracting" , False ), ("usepasswordfile", "bool" , "Use password file" , True ), - ("passwordfile" , "file" , "Password file" , "archive_password.txt" ), + ("passwordfile" , "file" , "Password file" , "passwords.txt" ), ("delete" , "bool" , "Delete archive after extraction" , True ), ("deltotrash" , "bool" , "Move to trash (recycle bin) instead delete", True ), ("subfolder" , "bool" , "Create subfolder for each package" , False ), @@ -139,53 +137,53 @@ class ExtractArchive(Hook): NAME_REPLACEMENTS = [(r'\.part\d+\.rar$', ".part.rar")] - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - self.event_list = ["allDownloadsProcessed","packageDeleted"] + def init(self): + self.event_map = {'allDownloadsProcessed': "all_downloads_processed", + 'packageDeleted' : "package_deleted" } self.queue = ArchiveQueue(self, "Queue") self.failed = ArchiveQueue(self, "Failed") self.interval = 60 self.extracting = False - self.lastPackage = False + self.last_package = False self.extractors = [] self.passwords = [] self.repair = False - def coreReady(self): + def activate(self): for p in ("UnRar", "SevenZip", "UnZip"): try: - module = self.core.pluginManager.loadModule("internal", p) + module = self.pyload.pluginManager.loadModule("internal", p) klass = getattr(module, p) - if klass.isUsable(): + if klass.find(): self.extractors.append(klass) if klass.REPAIR: - self.repair = self.getConfig('repair') + self.repair = self.get_config('repair') except OSError, e: if e.errno == 2: - self.logWarning(_("No %s installed") % p) + self.log_warning(_("No %s installed") % p) else: - self.logWarning(_("Could not activate: %s") % p, e) - if self.core.debug: + self.log_warning(_("Could not activate: %s") % p, e) + if self.pyload.debug: traceback.print_exc() except Exception, e: - self.logWarning(_("Could not activate: %s") % p, e) - if self.core.debug: + self.log_warning(_("Could not activate: %s") % p, e) + if self.pyload.debug: traceback.print_exc() if self.extractors: - self.logDebug(*["Found %s %s" % (Extractor.__name__, Extractor.VERSION) for Extractor in self.extractors]) - self.extractQueued() #: Resume unfinished extractions + self.log_debug(*["Found %s %s" % (Extractor.__name__, Extractor.VERSION) for Extractor in self.extractors]) + self.extract_queued() #: Resume unfinished extractions else: - self.logInfo(_("No Extract plugins activated")) + self.log_info(_("No Extract plugins activated")) @threaded - def extractQueued(self, thread): + def extract_queued(self, thread): if self.extracting: #@NOTE: doing the check here for safty (called by coreReady) return @@ -193,8 +191,8 @@ class ExtractArchive(Hook): packages = self.queue.get() while packages: - if self.lastPackage: #: called from allDownloadsProcessed - self.lastPackage = False + if self.last_package: #: Called from allDownloadsProcessed + self.last_package = False if self.extract(packages, thread): #@NOTE: check only if all gone fine, no failed reporting for now self.manager.dispatchEvent("all_archives_extracted") self.manager.dispatchEvent("all_archives_processed") @@ -202,34 +200,45 @@ class ExtractArchive(Hook): if self.extract(packages, thread): #@NOTE: check only if all gone fine, no failed reporting for now pass - packages = self.queue.get() #: check for packages added during extraction + packages = self.queue.get() #: Check for packages added during extraction self.extracting = False + #: Deprecated method, use `extract_package` instead @Expose - def extractPackage(self, *ids): - """ Extract packages with given id""" + def extractPackage(self, *args, **kwargs): + """ + See `extract_package` + """ + return self.extract_package(*args, **kwargs) + + + @Expose + def extract_package(self, *ids): + """ + Extract packages with given id + """ for id in ids: self.queue.add(id) - if not self.getConfig('waitall') and not self.extracting: - self.extractQueued() + if not self.get_config('waitall') and not self.extracting: + self.extract_queued() - def packageDeleted(self, pid): + def package_deleted(self, pid): self.queue.remove(pid) - def packageFinished(self, pypack): + def package_finished(self, pypack): self.queue.add(pypack.id) - if not self.getConfig('waitall') and not self.extracting: - self.extractQueued() + if not self.get_config('waitall') and not self.extracting: + self.extract_queued() - def allDownloadsProcessed(self): - self.lastPackage = True - if self.getConfig('waitall') and not self.extracting: - self.extractQueued() + def all_downloads_processed(self): + self.last_package = True + if self.get_config('waitall') and not self.extracting: + self.extract_queued() @Expose @@ -243,51 +252,51 @@ class ExtractArchive(Hook): toList = lambda string: string.replace(' ', '').replace(',', '|').replace(';', '|').split('|') - destination = self.getConfig('destination') - subfolder = self.getConfig('subfolder') - fullpath = self.getConfig('fullpath') - overwrite = self.getConfig('overwrite') - renice = self.getConfig('renice') - recursive = self.getConfig('recursive') - delete = self.getConfig('delete') - keepbroken = self.getConfig('keepbroken') + destination = self.get_config('destination') + subfolder = self.get_config('subfolder') + fullpath = self.get_config('fullpath') + overwrite = self.get_config('overwrite') + renice = self.get_config('renice') + recursive = self.get_config('recursive') + delete = self.get_config('delete') + keepbroken = self.get_config('keepbroken') - extensions = [x.lstrip('.').lower() for x in toList(self.getConfig('extensions'))] - excludefiles = toList(self.getConfig('excludefiles')) + extensions = [x.lstrip('.').lower() for x in toList(self.get_config('extensions'))] + excludefiles = toList(self.get_config('excludefiles')) if extensions: - self.logDebug("Use for extensions: %s" % "|.".join(extensions)) + self.log_debug("Use for extensions: %s" % "|.".join(extensions)) - # reload from txt file - self.reloadPasswords() + #: Reload from txt file + self.reload_passwords() - download_folder = self.config['general']['download_folder'] + download_folder = self.pyload.config.get("general", "download_folder") - # iterate packages -> extractors -> targets + #: Iterate packages -> extractors -> targets for pid in ids: - pypack = self.core.files.getPackage(pid) + pypack = self.pyload.files.getPackage(pid) if not pypack: self.queue.remove(pid) continue - self.logInfo(_("Check package: %s") % pypack.name) + self.log_info(_("Check package: %s") % pypack.name) - # determine output folder - out = save_join(download_folder, pypack.folder, destination, "") #: force trailing slash + #: Determine output folder + out = fs_join(download_folder, pypack.folder, destination, "") #: Force trailing slash if subfolder: - out = save_join(out, pypack.folder) + out = fs_join(out, pypack.folder) if not os.path.exists(out): os.makedirs(out) matched = False success = True - files_ids = dict((pylink['name'],((save_join(download_folder, pypack.folder, pylink['name'])), pylink['id'], out)) for pylink \ - in sorted(pypack.getChildren().itervalues(), key=lambda k: k['name'])).values() #: remove duplicates + files_ids = dict((pylink['name'], ((fs_join(download_folder, pypack.folder, pylink['name'])), pylink['id'], out)) for pylink \ + in sorted(pypack.getChildren().values(), key=lambda k: k['name'])).values() #: Remove duplicates - # check as long there are unseen files + #: Check as long there are unseen files while files_ids: new_files_ids = [] @@ -296,21 +305,21 @@ class ExtractArchive(Hook): if filter(lambda ext: fname.lower().endswith(ext), extensions)] for Extractor in self.extractors: - targets = Extractor.getTargets(files_ids) + targets = Extractor.get_targets(files_ids) if targets: - self.logDebug("Targets for %s: %s" % (Extractor.__name__, targets)) + self.log_debug("Targets for %s: %s" % (Extractor.__name__, targets)) matched = True for fname, fid, fout in targets: name = os.path.basename(fname) if not os.path.exists(fname): - self.logDebug(name, "File not found") + self.log_debug(name, "File not found") continue - self.logInfo(name, _("Extract to: %s") % fout) + self.log_info(name, _("Extract to: %s") % fout) try: - pyfile = self.core.files.getFile(fid) + pyfile = self.pyload.files.getFile(fid) archive = Extractor(self, fname, fout, @@ -333,28 +342,30 @@ class ExtractArchive(Hook): thread.finishFile(pyfile) except Exception, e: - self.logError(name, e) + self.log_error(name, e) success = False continue - # remove processed file and related multiparts from list + #: Remove processed file and related multiparts from list files_ids = [(fname, fid, fout) for fname, fid, fout in files_ids \ - if fname not in archive.getDeleteFiles()] - self.logDebug("Extracted files: %s" % new_files) - self.setPermissions(new_files) + if fname not in archive.get_delete_files()] + self.log_debug("Extracted files: %s" % new_files) + + for file in new_files: + self.set_permissions(file) for filename in new_files: - file = fs_encode(save_join(os.path.dirname(archive.filename), filename)) + file = fs_encode(fs_join(os.path.dirname(archive.filename), filename)) if not os.path.exists(file): - self.logDebug("New file %s does not exists" % filename) + self.log_debug("New file %s does not exists" % filename) continue if recursive and os.path.isfile(file): - new_files_ids.append((filename, fid, os.path.dirname(filename))) #: append as new target + new_files_ids.append((filename, fid, os.path.dirname(filename))) #: Append as new target self.manager.dispatchEvent("archive_extracted", pyfile, archive) - files_ids = new_files_ids #: also check extracted files + files_ids = new_files_ids #: Also check extracted files if matched: if success: @@ -367,7 +378,7 @@ class ExtractArchive(Hook): self.failed.add(pid) else: - self.logInfo(_("No files found to extract")) + self.log_info(_("No files found to extract")) if not matched or not success and subfolder: try: @@ -388,44 +399,44 @@ class ExtractArchive(Hook): encrypted = False try: - self.logDebug("Password: %s" % (password or "None provided")) - passwords = uniqify([password] + self.getPasswords(False)) if self.getConfig('usepasswordfile') else [password] + self.log_debug("Password: %s" % (password or "None provided")) + passwords = uniqify([password] + self.get_passwords(False)) if self.get_config('usepasswordfile') else [password] for pw in passwords: try: - if self.getConfig('test') or self.repair: + if self.get_config('test') or self.repair: pyfile.setCustomStatus(_("archive testing")) if pw: - self.logDebug("Testing with password: %s" % pw) + self.log_debug("Testing with password: %s" % pw) pyfile.setProgress(0) archive.verify(pw) pyfile.setProgress(100) else: archive.check(pw) - self.addPassword(pw) + self.add_password(pw) break except PasswordError: if not encrypted: - self.logInfo(name, _("Password protected")) + self.log_info(name, _("Password protected")) encrypted = True except CRCError, e: - self.logDebug(name, e) - self.logInfo(name, _("CRC Error")) + self.log_debug(name, e) + self.log_info(name, _("CRC Error")) if self.repair: - self.logWarning(name, _("Repairing...")) + self.log_warning(name, _("Repairing...")) pyfile.setCustomStatus(_("archive repairing")) pyfile.setProgress(0) repaired = archive.repair() pyfile.setProgress(100) - if not repaired and not self.getConfig('keepbroken'): + if not repaired and not self.get_config('keepbroken'): raise CRCError("Archive damaged") - self.addPassword(pw) + self.add_password(pw) break raise CRCError("Archive damaged") @@ -436,33 +447,33 @@ class ExtractArchive(Hook): pyfile.setCustomStatus(_("extracting")) pyfile.setProgress(0) - if not encrypted or not self.getConfig('usepasswordfile'): - self.logDebug("Extracting using password: %s" % (password or "None")) + if not encrypted or not self.get_config('usepasswordfile'): + self.log_debug("Extracting using password: %s" % (password or "None")) archive.extract(password) else: - for pw in filter(None, uniqify([password] + self.getPasswords(False))): + for pw in filter(None, uniqify([password] + self.get_passwords(False))): try: - self.logDebug("Extracting using password: %s" % pw) + self.log_debug("Extracting using password: %s" % pw) archive.extract(pw) - self.addPassword(pw) + self.add_password(pw) break except PasswordError: - self.logDebug("Password was wrong") + self.log_debug("Password was wrong") else: raise PasswordError pyfile.setProgress(100) pyfile.setStatus("processing") - delfiles = archive.getDeleteFiles() - self.logDebug("Would delete: " + ", ".join(delfiles)) + delfiles = archive.get_delete_files() + self.log_debug("Would delete: " + ", ".join(delfiles)) - if self.getConfig('delete'): - self.logInfo(_("Deleting %s files") % len(delfiles)) + if self.get_config('delete'): + self.log_info(_("Deleting %s files") % len(delfiles)) - deltotrash = self.getConfig('deltotrash') + deltotrash = self.get_config('deltotrash') for f in delfiles: file = fs_encode(f) if not os.path.exists(file): @@ -476,31 +487,33 @@ class ExtractArchive(Hook): send2trash.send2trash(file) except NameError: - self.logWarning(_("Unable to move %s to trash: Send2Trash lib not found") % os.path.basename(f)) + self.log_warning(_("Unable to move %s to trash") % os.path.basename(f), + _("Send2Trash lib not found")) except Exception, e: - self.logWarning(_("Unable to move %s to trash: %s") % (os.path.basename(f), e.message)) + self.log_warning(_("Unable to move %s to trash") % os.path.basename(f), + e.message) else: - self.logDebug(_("Successfully moved %s to trash") % os.path.basename(f)) + self.log_info(_("Moved %s to trash") % os.path.basename(f)) - self.logInfo(name, _("Extracting finished")) + self.log_info(name, _("Extracting finished")) extracted_files = archive.files or archive.list() return extracted_files except PasswordError: - self.logError(name, _("Wrong password" if password else "No password found")) + self.log_error(name, _("Wrong password" if password else "No password found")) except CRCError, e: - self.logError(name, _("CRC mismatch"), e) + self.log_error(name, _("CRC mismatch"), e) except ArchiveError, e: - self.logError(name, _("Archive error"), e) + self.log_error(name, _("Archive error"), e) except Exception, e: - self.logError(name, _("Unknown error"), e) - if self.core.debug: + self.log_error(name, _("Unknown error"), e) + if self.pyload.debug: traceback.print_exc() self.manager.dispatchEvent("archive_extract_failed", pyfile, archive) @@ -508,63 +521,63 @@ class ExtractArchive(Hook): raise Exception(_("Extract failed")) + #: Deprecated method, use `get_passwords` instead @Expose - def getPasswords(self, reload=True): - """ List of saved passwords """ + def getPasswords(self, *args, **kwargs): + """ + See `get_passwords` + """ + return self.get_passwords(*args, **kwargs) + + + @Expose + def get_passwords(self, reload=True): + """ + List of saved passwords + """ if reload: - self.reloadPasswords() + self.reload_passwords() return self.passwords - def reloadPasswords(self): + def reload_passwords(self): try: passwords = [] - file = fs_encode(self.getConfig('passwordfile')) + file = fs_encode(self.get_config('passwordfile')) with open(file) as f: for pw in f.read().splitlines(): passwords.append(pw) except IOError, e: - self.logError(e) + self.log_error(e) else: self.passwords = passwords + #: Deprecated method, use `add_password` instead + @Expose + def addPassword(self, *args, **kwargs): + """ + See `add_password` + """ + return self.add_password(*args, **kwargs) + + @Expose - def addPassword(self, password): - """ Adds a password to saved list""" + def add_password(self, password): + """ + Adds a password to saved list + """ try: self.passwords = uniqify([password] + self.passwords) - file = fs_encode(self.getConfig('passwordfile')) + file = fs_encode(self.get_config('passwordfile')) with open(file, "wb") as f: for pw in self.passwords: f.write(pw + '\n') except IOError, e: - self.logError(e) - - - def setPermissions(self, files): - for f in files: - if not os.path.exists(f): - continue - - try: - if self.config['permission']['change_file']: - if os.path.isfile(f): - os.chmod(f, int(self.config['permission']['file'], 8)) - - elif os.path.isdir(f): - os.chmod(f, int(self.config['permission']['folder'], 8)) - - if self.config['permission']['change_dl'] and os.name != "nt": - uid = getpwnam(self.config['permission']['user'])[2] - gid = getgrnam(self.config['permission']['group'])[2] - os.chown(f, uid, gid) - - except Exception, e: - self.logWarning(_("Setting User and Group failed"), e) + self.log_error(e) diff --git a/module/plugins/hooks/FastixRuHook.py b/module/plugins/hooks/FastixRuHook.py index 16e30e93a..3fdb29409 100644 --- a/module/plugins/hooks/FastixRuHook.py +++ b/module/plugins/hooks/FastixRuHook.py @@ -7,21 +7,21 @@ from module.plugins.internal.MultiHook import MultiHook class FastixRuHook(MultiHook): __name__ = "FastixRuHook" __type__ = "hook" - __version__ = "0.05" + __version__ = "0.06" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Fastix.ru hook plugin""" __license__ = "GPLv3" __authors__ = [("Massimo Rosamilia", "max@spiritix.eu")] - def getHosters(self): - html = self.getURL("http://fastix.ru/api_v2", + def get_hosters(self): + html = self.load("http://fastix.ru/api_v2", get={'apikey': "5182964c3f8f9a7f0b00000a_kelmFB4n1IrnCDYuIFn2y", 'sub' : "allowed_sources"}) host_list = json_loads(html) diff --git a/module/plugins/hooks/FreeWayMeHook.py b/module/plugins/hooks/FreeWayMeHook.py index baea44540..1380433bf 100644 --- a/module/plugins/hooks/FreeWayMeHook.py +++ b/module/plugins/hooks/FreeWayMeHook.py @@ -6,27 +6,23 @@ from module.plugins.internal.MultiHook import MultiHook class FreeWayMeHook(MultiHook): __name__ = "FreeWayMeHook" __type__ = "hook" - __version__ = "0.15" + __version__ = "0.18" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """FreeWay.me hook plugin""" __license__ = "GPLv3" __authors__ = [("Nicolas Giese", "james@free-way.me")] - def getHosters(self): - # Get account data - if not self.account or not self.account.canUse(): - hostis = self.getURL("https://www.free-way.me/ajax/jd.php", get={"id": 3}).replace("\"", "").strip() - else: - self.logDebug("AccountInfo available - Get HosterList with User Pass") - (user, data) = self.account.selectAccount() - hostis = self.getURL("https://www.free-way.me/ajax/jd.php", get={"id": 3, "user": user, "pass": data['password']}).replace("\"", "").strip() - - self.logDebug("hosters: %s" % hostis) + def get_hosters(self): + user, info = self.account.select() + hostis = self.load("http://www.free-way.bz/ajax/jd.php", + get={'id' : 3, + 'user': user, + 'pass': info['login']['password']}).replace("\"", "") #@TODO: Revert to `https` in 0.4.10 return [x.strip() for x in hostis.split(",") if x.strip()] diff --git a/module/plugins/hooks/HighWayMeHook.py b/module/plugins/hooks/HighWayMeHook.py new file mode 100644 index 000000000..e9e62525d --- /dev/null +++ b/module/plugins/hooks/HighWayMeHook.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +from module.common.json_layer import json_loads +from module.plugins.internal.MultiHook import MultiHook + + +class HighWayMeHook(MultiHook): + __name__ = "HighWayMeHook" + __type__ = "hook" + __version__ = "0.04" + __status__ = "testing" + + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + + __description__ = """High-Way.me hook plugin""" + __license__ = "GPLv3" + __authors__ = [("EvolutionClip", "evolutionclip@live.de")] + + + def get_hosters(self): + json_data = json_loads(self.load("https://high-way.me/api.php", + get={'hoster': 1})) + return [element['name'] for element in json_data['hoster']] diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index f771cf232..84db4db17 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -7,14 +7,15 @@ import time from shutil import move -from module.plugins.Hook import Hook -from module.utils import fs_encode, save_join +from module.plugins.internal.Addon import Addon +from module.utils import fs_encode, save_join as fs_join -class HotFolder(Hook): +class HotFolder(Addon): __name__ = "HotFolder" __type__ = "hook" - __version__ = "0.14" + __version__ = "0.16" + __status__ = "testing" __config__ = [("folder" , "str" , "Folder to observe" , "container"), ("watch_file", "bool", "Observe link file" , False ), @@ -26,20 +27,19 @@ class HotFolder(Hook): __authors__ = [("RaNaN", "RaNaN@pyload.de")] - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 + def init(self): self.interval = 30 def periodical(self): - folder = fs_encode(self.getConfig('folder')) - file = fs_encode(self.getConfig('file')) + folder = fs_encode(self.get_config('folder')) + file = fs_encode(self.get_config('file')) try: if not os.path.isdir(os.path.join(folder, "finished")): os.makedirs(os.path.join(folder, "finished")) - if self.getConfig('watch_file'): + if self.get_config('watch_file'): with open(file, "a+") as f: f.seek(0) content = f.read().strip() @@ -50,10 +50,10 @@ class HotFolder(Hook): name = "%s_%s.txt" % (file, time.strftime("%H-%M-%S_%d%b%Y")) - with open(save_join(folder, "finished", name), "wb") as f: + with open(fs_join(folder, "finished", name), "wb") as f: f.write(content) - self.core.api.addPackage(f.name, [f.name], 1) + self.pyload.api.addPackage(f.name, [f.name], 1) for f in os.listdir(folder): path = os.path.join(folder, f) @@ -61,11 +61,11 @@ class HotFolder(Hook): if not os.path.isfile(path) or f.endswith("~") or f.startswith("#") or f.startswith("."): continue - newpath = os.path.join(folder, "finished", f if self.getConfig('keep') else "tmp_" + f) + newpath = os.path.join(folder, "finished", f if self.get_config('keep') else "tmp_" + f) move(path, newpath) - self.logInfo(_("Added %s from HotFolder") % f) - self.core.api.addPackage(f, [newpath], 1) + self.log_info(_("Added %s from HotFolder") % f) + self.pyload.api.addPackage(f, [newpath], 1) except (IOError, OSError), e: - self.logError(e) + self.log_error(e) diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py index 33fde3d20..08b1bad0c 100644 --- a/module/plugins/hooks/IRCInterface.py +++ b/module/plugins/hooks/IRCInterface.py @@ -11,42 +11,39 @@ from select import select from threading import Thread from module.Api import PackageDoesNotExists, FileDoesNotExists -from module.network.RequestFactory import getURL -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon from module.utils import formatSize -class IRCInterface(Thread, Hook): +class IRCInterface(Thread, Addon): __name__ = "IRCInterface" __type__ = "hook" - __version__ = "0.13" - - __config__ = [("host", "str", "IRC-Server Address", "Enter your server here!"), - ("port", "int", "IRC-Server Port", 6667), - ("ident", "str", "Clients ident", "pyload-irc"), - ("realname", "str", "Realname", "pyload-irc"), - ("ssl", "bool", "Use SSL", False), - ("nick", "str", "Nickname the Client will take", "pyLoad-IRC"), - ("owner", "str", "Nickname the Client will accept commands from", "Enter your nick here!"), - ("info_file", "bool", "Inform about every file finished", False), - ("info_pack", "bool", "Inform about every package finished", True), - ("captcha", "bool", "Send captcha requests", True)] + __version__ = "0.15" + __status__ = "testing" + + __config__ = [("host" , "str" , "IRC-Server Address" , "Enter your server here!"), + ("port" , "int" , "IRC-Server Port" , 6667 ), + ("ident" , "str" , "Clients ident" , "pyload-irc" ), + ("realname" , "str" , "Realname" , "pyload-irc" ), + ("ssl" , "bool", "Use SSL" , False ), + ("nick" , "str" , "Nickname the Client will take" , "pyLoad-IRC" ), + ("owner" , "str" , "Nickname the Client will accept commands from", "Enter your nick here!" ), + ("info_file", "bool", "Inform about every file finished" , False ), + ("info_pack", "bool", "Inform about every package finished" , True ), + ("captcha" , "bool", "Send captcha requests" , True )] __description__ = """Connect to irc and let owner perform different tasks""" __license__ = "GPLv3" __authors__ = [("Jeix", "Jeix@hasnomail.com")] - interval = 0 #@TODO: Remove in 0.4.10 - - def __init__(self, core, manager): Thread.__init__(self) - Hook.__init__(self, core, manager) - self.setDaemon(True) + Addon.__init__(self, core, manager) + self.set_daemon(True) - def coreReady(self): + def activate(self): self.abort = False self.more = [] self.new_package = {} @@ -54,30 +51,30 @@ class IRCInterface(Thread, Hook): self.start() - def packageFinished(self, pypack): + def package_finished(self, pypack): try: - if self.getConfig('info_pack'): + if self.get_config('info_pack'): self.response(_("Package finished: %s") % pypack.name) except Exception: pass - def downloadFinished(self, pyfile): + def download_finished(self, pyfile): try: - if self.getConfig('info_file'): + if self.get_config('info_file'): self.response( - _("Download finished: %(name)s @ %(plugin)s ") % {"name": pyfile.name, "plugin": pyfile.pluginname}) + _("Download finished: %(name)s @ %(plugin)s ") % {'name': pyfile.name, 'plugin': pyfile.pluginname}) except Exception: pass - def newCaptchaTask(self, task): - if self.getConfig('captcha') and task.isTextual(): + def captcha_task(self, task): + if self.get_config('captcha') and task.isTextual(): task.handler.append(self) task.setWaiting(60) - html = getURL("http://www.freeimagehosting.net/upload.php", - post={"attached": (pycurl.FORM_FILE, task.captchaFile)}, multipart=True) + html = self.load("http://www.freeimagehosting.net/upload.php", + post={'attached': (pycurl.FORM_FILE, task.captchaFile)}) url = re.search(r"\[img\]([^\[]+)\[/img\]\[/url\]", html).group(1) self.response(_("New Captcha Request: %s") % url) @@ -85,22 +82,22 @@ class IRCInterface(Thread, Hook): def run(self): - # connect to IRC etc. + #: Connect to IRC etc. self.sock = socket.socket() - host = self.getConfig('host') - self.sock.connect((host, self.getConfig('port'))) + host = self.get_config('host') + self.sock.connect((host, self.get_config('port'))) - if self.getConfig('ssl'): + if self.get_config('ssl'): self.sock = ssl.wrap_socket(self.sock, cert_reqs=ssl.CERT_NONE) #@TODO: support certificate - nick = self.getConfig('nick') + nick = self.get_config('nick') self.sock.send("NICK %s\r\n" % nick) self.sock.send("USER %s %s bla :%s\r\n" % (nick, host, nick)) - for t in self.getConfig('owner').split(): + for t in self.get_config('owner').split(): if t.strip().startswith("#"): self.sock.send("JOIN %s\r\n" % t.strip()) - self.logInfo(_("Connected to"), host) - self.logInfo(_("Switching to listening mode!")) + self.log_info(_("Connected to"), host) + self.log_info(_("Switching to listening mode!")) try: self.main_loop() @@ -140,36 +137,36 @@ class IRCInterface(Thread, Hook): continue msg = { - "origin": msg[0][1:], - "action": msg[1], - "target": msg[2], - "text": msg[3][1:] + 'origin': msg[0][1:], + 'action': msg[1], + 'target': msg[2], + 'text': msg[3][1:] } self.handle_events(msg) def handle_events(self, msg): - if not msg['origin'].split("!", 1)[0] in self.getConfig('owner').split(): + if not msg['origin'].split("!", 1)[0] in self.get_config('owner').split(): return - if msg['target'].split("!", 1)[0] != self.getConfig('nick'): + if msg['target'].split("!", 1)[0] is not self.get_config('nick'): return if msg['action'] != "PRIVMSG": return - # HANDLE CTCP ANTI FLOOD/BOT PROTECTION + #: HANDLE CTCP ANTI FLOOD/BOT PROTECTION if msg['text'] == "\x01VERSION\x01": - self.logDebug("Sending CTCP VERSION") + self.log_debug("Sending CTCP VERSION") self.sock.send("NOTICE %s :%s\r\n" % (msg['origin'], "pyLoad! IRC Interface")) return elif msg['text'] == "\x01TIME\x01": - self.logDebug("Sending CTCP TIME") + self.log_debug("Sending CTCP TIME") self.sock.send("NOTICE %s :%d\r\n" % (msg['origin'], time.time())) return elif msg['text'] == "\x01LAG\x01": - self.logDebug("Received CTCP LAG") #: don't know how to answer + self.log_debug("Received CTCP LAG") #: don't know how to answer return trigger = "pass" @@ -189,12 +186,12 @@ class IRCInterface(Thread, Hook): for line in res: self.response(line, msg['origin']) except Exception, e: - self.logError(e) + self.log_error(e) def response(self, msg, origin=""): if origin == "": - for t in self.getConfig('owner').split(): + for t in self.get_config('owner').split(): self.sock.send("PRIVMSG %s :%s\r\n" % (t.strip(), msg)) else: self.sock.send("PRIVMSG %s :%s\r\n" % (origin.split("!", 1)[0], msg)) @@ -207,7 +204,7 @@ class IRCInterface(Thread, Hook): def event_status(self, args): - downloads = self.core.api.statusDownloads() + downloads = self.pyload.api.statusDownloads() if not downloads: return ["INFO: There are no active downloads currently."] @@ -233,7 +230,7 @@ class IRCInterface(Thread, Hook): def event_queue(self, args): - ps = self.core.api.getQueueData() + ps = self.pyload.api.getQueueData() if not ps: return ["INFO: There are no packages in queue."] @@ -246,7 +243,7 @@ class IRCInterface(Thread, Hook): def event_collector(self, args): - ps = self.core.api.getCollectorData() + ps = self.pyload.api.getCollectorData() if not ps: return ["INFO: No packages in collector!"] @@ -263,7 +260,7 @@ class IRCInterface(Thread, Hook): info = None try: - info = self.core.api.getFileData(int(args[0])) + info = self.pyload.api.getFileData(int(args[0])) except FileDoesNotExists: return ["ERROR: Link doesn't exists."] @@ -278,7 +275,7 @@ class IRCInterface(Thread, Hook): lines = [] pack = None try: - pack = self.core.api.getPackageData(int(args[0])) + pack = self.pyload.api.getPackageData(int(args[0])) except PackageDoesNotExists: return ["ERROR: Package doesn't exists."] @@ -315,12 +312,12 @@ class IRCInterface(Thread, Hook): def event_start(self, args): - self.core.api.unpauseServer() + self.pyload.api.unpauseServer() return ["INFO: Starting downloads."] def event_stop(self, args): - self.core.api.pauseServer() + self.pyload.api.pauseServer() return ["INFO: No new downloads will be started."] @@ -336,17 +333,17 @@ class IRCInterface(Thread, Hook): count_failed = 0 try: id = int(pack) - pack = self.core.api.getPackageData(id) + pack = self.pyload.api.getPackageData(id) if not pack: return ["ERROR: Package doesn't exists."] - #TODO add links + #@TODO: add links return ["INFO: Added %d links to Package %s [#%d]" % (len(links), pack['name'], id)] except Exception: - # create new package - id = self.core.api.addPackage(pack, links, 1) + #: Create new package + id = self.pyload.api.addPackage(pack, links, 1) return ["INFO: Created new Package %s [#%d] with %d links." % (pack, id, len(links))] @@ -355,11 +352,11 @@ class IRCInterface(Thread, Hook): return ["ERROR: Use del command like this: del -p|-l <id> [...] (-p indicates that the ids are from packages, -l indicates that the ids are from links)"] if args[0] == "-p": - ret = self.core.api.deletePackages(map(int, args[1:])) + ret = self.pyload.api.deletePackages(map(int, args[1:])) return ["INFO: Deleted %d packages!" % len(args[1:])] elif args[0] == "-l": - ret = self.core.api.delLinks(map(int, args[1:])) + ret = self.pyload.api.delLinks(map(int, args[1:])) return ["INFO: Deleted %d links!" % len(args[1:])] else: @@ -372,11 +369,11 @@ class IRCInterface(Thread, Hook): id = int(args[0]) try: - info = self.core.api.getPackageInfo(id) + info = self.pyload.api.getPackageInfo(id) except PackageDoesNotExists: return ["ERROR: Package #%d does not exist." % id] - self.core.api.pushToQueue(id) + self.pyload.api.pushToQueue(id) return ["INFO: Pushed package #%d to queue." % id] @@ -385,19 +382,21 @@ class IRCInterface(Thread, Hook): return ["ERROR: Pull package from queue like this: pull <package id>."] id = int(args[0]) - if not self.core.api.getPackageData(id): + if not self.pyload.api.getPackageData(id): return ["ERROR: Package #%d does not exist." % id] - self.core.api.pullFromQueue(id) + self.pyload.api.pullFromQueue(id) return ["INFO: Pulled package #%d from queue to collector." % id] def event_c(self, args): - """ captcha answer """ + """ + Captcha answer + """ if not args: return ["ERROR: Captcha ID missing."] - task = self.core.captchaManager.getTaskByID(args[0]) + task = self.pyload.captchaManager.getTaskByID(args[0]) if not task: return ["ERROR: Captcha Task with ID %s does not exists." % args[0]] diff --git a/module/plugins/hooks/ImageTyperz.py b/module/plugins/hooks/ImageTyperz.py index f1fcacb71..42ab99027 100644 --- a/module/plugins/hooks/ImageTyperz.py +++ b/module/plugins/hooks/ImageTyperz.py @@ -7,8 +7,8 @@ import re from base64 import b64encode -from module.network.RequestFactory import getURL, getRequest -from module.plugins.Hook import Hook, threaded +from module.network.RequestFactory import getRequest as get_request +from module.plugins.internal.Hook import Hook, threaded class ImageTyperzException(Exception): @@ -17,7 +17,7 @@ class ImageTyperzException(Exception): self.err = err - def getCode(self): + def get_code(self): return self.err @@ -32,11 +32,12 @@ class ImageTyperzException(Exception): class ImageTyperz(Hook): __name__ = "ImageTyperz" __type__ = "hook" - __version__ = "0.06" + __version__ = "0.08" + __status__ = "testing" - __config__ = [("username", "str", "Username", ""), - ("passkey", "password", "Password", ""), - ("force", "bool", "Force IT even if client is connected", False)] + __config__ = [("username" , "str" , "Username" , "" ), + ("password" , "password", "Password" , "" ), + ("check_client", "bool" , "Don't use if client is connected", True)] __description__ = """Send captchas to ImageTyperz.com""" __license__ = "GPLv3" @@ -44,22 +45,16 @@ class ImageTyperz(Hook): ("zoidberg", "zoidberg@mujmail.cz")] - interval = 0 #@TODO: Remove in 0.4.10 - SUBMIT_URL = "http://captchatypers.com/Forms/UploadFileAndGetTextNEW.ashx" RESPOND_URL = "http://captchatypers.com/Forms/SetBadImage.ashx" GETCREDITS_URL = "http://captchatypers.com/Forms/RequestBalance.ashx" - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - - def getCredits(self): - res = getURL(self.GETCREDITS_URL, + def get_credits(self): + res = self.load(self.GETCREDITS_URL, post={'action': "REQUESTBALANCE", - 'username': self.getConfig('username'), - 'password': self.getConfig('passkey')}) + 'username': self.get_config('username'), + 'password': self.get_config('password')}) if res.startswith('ERROR'): raise ImageTyperzException(res) @@ -69,18 +64,18 @@ class ImageTyperz(Hook): except Exception: raise ImageTyperzException("Invalid response") - self.logInfo(_("Account balance: $%s left") % res) + self.log_info(_("Account balance: $%s left") % res) return balance def submit(self, captcha, captchaType="file", match=None): - req = getRequest() - #raise timeout threshold + req = get_request() + #: Raise timeout threshold req.c.setopt(pycurl.LOW_SPEED_TIME, 80) try: #@NOTE: Workaround multipart-post bug in HTTPRequest.py - if re.match("^\w*$", self.getConfig('passkey')): + if re.match("^\w*$", self.get_config('password')): multipart = True data = (pycurl.FORM_FILE, captcha) else: @@ -89,11 +84,12 @@ class ImageTyperz(Hook): data = f.read() data = b64encode(data) - res = req.load(self.SUBMIT_URL, - post={'action': "UPLOADCAPTCHA", - 'username': self.getConfig('username'), - 'password': self.getConfig('passkey'), "file": data}, - multipart=multipart) + res = self.load(self.SUBMIT_URL, + post={'action': "UPLOADCAPTCHA", + 'username': self.get_config('username'), + 'password': self.get_config('password'), 'file': data}, + multipart=multipart, + req=req) finally: req.close() @@ -109,50 +105,50 @@ class ImageTyperz(Hook): return ticket, result - def newCaptchaTask(self, task): + def captcha_task(self, task): if "service" in task.data: return False if not task.isTextual(): return False - if not self.getConfig('username') or not self.getConfig('passkey'): + if not self.get_config('username') or not self.get_config('password'): return False - if self.core.isClientConnected() and not self.getConfig('force'): + if self.pyload.isClientConnected() and self.get_config('check_client'): return False - if self.getCredits() > 0: + if self.get_credits() > 0: task.handler.append(self) task.data['service'] = self.__name__ task.setWaiting(100) - self._processCaptcha(task) + self._process_captcha(task) else: - self.logInfo(_("Your %s account has not enough credits") % self.__name__) + self.log_info(_("Your %s account has not enough credits") % self.__name__) - def captchaInvalid(self, task): - if task.data['service'] == self.__name__ and "ticket" in task.data: - res = getURL(self.RESPOND_URL, + def captcha_invalid(self, task): + if task.data['service'] is self.__name__ and "ticket" in task.data: + res = self.load(self.RESPOND_URL, post={'action': "SETBADIMAGE", - 'username': self.getConfig('username'), - 'password': self.getConfig('passkey'), + 'username': self.get_config('username'), + 'password': self.get_config('password'), 'imageid': task.data['ticket']}) if res == "SUCCESS": - self.logInfo(_("Bad captcha solution received, requested refund")) + self.log_info(_("Bad captcha solution received, requested refund")) else: - self.logError(_("Bad captcha solution received, refund request failed"), res) + self.log_error(_("Bad captcha solution received, refund request failed"), res) @threaded - def _processCaptcha(self, task): + def _process_captcha(self, task): c = task.captchaFile try: ticket, result = self.submit(c) except ImageTyperzException, e: - task.error = e.getCode() + task.error = e.get_code() return task.data['ticket'] = ticket diff --git a/module/plugins/hooks/JustPremium.py b/module/plugins/hooks/JustPremium.py index f66747f82..69a6a851b 100644 --- a/module/plugins/hooks/JustPremium.py +++ b/module/plugins/hooks/JustPremium.py @@ -2,13 +2,14 @@ import re -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon -class JustPremium(Hook): +class JustPremium(Addon): __name__ = "JustPremium" __type__ = "hook" - __version__ = "0.22" + __version__ = "0.24" + __status__ = "testing" __config__ = [("excluded", "str", "Exclude hosters (comma separated)", ""), ("included", "str", "Include hosters (comma separated)", "")] @@ -20,28 +21,24 @@ class JustPremium(Hook): ("immenz" , "immenz@gmx.net" )] - interval = 0 #@TODO: Remove in 0.4.10 + def init(self): + self.event_map = {'linksAdded': "links_added"} - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - self.event_list = ["linksAdded"] + def links_added(self, links, pid): + hosterdict = self.pyload.pluginManager.hosterPlugins + linkdict = self.pyload.api.checkURLs(links) - - def linksAdded(self, links, pid): - hosterdict = self.core.pluginManager.hosterPlugins - linkdict = self.core.api.checkURLs(links) - - premiumplugins = set(account.type for account in self.core.api.getAccounts(False) \ + premiumplugins = set(account.type for account in self.pyload.api.getAccounts(False) \ if account.valid and account.premium) - multihosters = set(hoster for hoster in self.core.pluginManager.hosterPlugins \ + multihosters = set(hoster for hoster in self.pyload.pluginManager.hosterPlugins \ if 'new_name' in hosterdict[hoster] \ and hosterdict[hoster]['new_name'] in premiumplugins) excluded = map(lambda domain: "".join(part.capitalize() for part in re.split(r'(\.|\d+)', domain) if part != '.'), - self.getConfig('excluded').replace(' ', '').replace(',', '|').replace(';', '|').split('|')) + self.get_config('excluded').replace(' ', '').replace(',', '|').replace(';', '|').split('|')) included = map(lambda domain: "".join(part.capitalize() for part in re.split(r'(\.|\d+)', domain) if part != '.'), - self.getConfig('included').replace(' ', '').replace(',', '|').replace(';', '|').split('|')) + self.get_config('included').replace(' ', '').replace(',', '|').replace(';', '|').split('|')) hosterlist = (premiumplugins | multihosters).union(excluded).difference(included) @@ -50,7 +47,7 @@ class JustPremium(Hook): return for pluginname in set(linkdict.keys()) - hosterlist: - self.logInfo(_("Remove links of plugin: %s") % pluginname) + self.log_info(_("Remove links of plugin: %s") % pluginname) for link in linkdict[pluginname]: - self.logDebug("Remove link: %s" % link) + self.log_debug("Remove link: %s" % link) links.remove(link) diff --git a/module/plugins/hooks/LinkdecrypterComHook.py b/module/plugins/hooks/LinkdecrypterComHook.py index b2eaece62..6930afdb5 100644 --- a/module/plugins/hooks/LinkdecrypterComHook.py +++ b/module/plugins/hooks/LinkdecrypterComHook.py @@ -8,7 +8,8 @@ from module.plugins.internal.MultiHook import MultiHook class LinkdecrypterComHook(MultiHook): __name__ = "LinkdecrypterComHook" __type__ = "hook" - __version__ = "1.06" + __version__ = "1.07" + __status__ = "testing" __config__ = [("activated" , "bool" , "Activated" , True ), ("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), @@ -21,9 +22,9 @@ class LinkdecrypterComHook(MultiHook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - def getHosters(self): + def get_hosters(self): list = re.search(r'>Supported\(\d+\)</b>: <i>(.[\w.\-, ]+)', - self.getURL("http://linkdecrypter.com/", decode=True).replace("(g)", "")).group(1).split(', ') + self.load("http://linkdecrypter.com/").replace("(g)", "")).group(1).split(', ') try: list.remove("download.serienjunkies.org") except ValueError: diff --git a/module/plugins/hooks/LinksnappyComHook.py b/module/plugins/hooks/LinksnappyComHook.py index 72282575b..e46e480d6 100644 --- a/module/plugins/hooks/LinksnappyComHook.py +++ b/module/plugins/hooks/LinksnappyComHook.py @@ -7,21 +7,21 @@ from module.plugins.internal.MultiHook import MultiHook class LinksnappyComHook(MultiHook): __name__ = "LinksnappyComHook" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.05" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Linksnappy.com hook plugin""" __license__ = "GPLv3" __authors__ = [("stickell", "l.stickell@yahoo.it")] - def getHosters(self): - json_data = self.getURL("http://gen.linksnappy.com/lseAPI.php", get={'act': "FILEHOSTS"}) + def get_hosters(self): + json_data = self.load("http://gen.linksnappy.com/lseAPI.php", get={'act': "FILEHOSTS"}) json_data = json_loads(json_data) return json_data['return'].keys() diff --git a/module/plugins/hooks/MegaDebridEuHook.py b/module/plugins/hooks/MegaDebridEuHook.py index 0de7b4dcf..04f0be86f 100644 --- a/module/plugins/hooks/MegaDebridEuHook.py +++ b/module/plugins/hooks/MegaDebridEuHook.py @@ -7,27 +7,27 @@ from module.plugins.internal.MultiHook import MultiHook class MegaDebridEuHook(MultiHook): __name__ = "MegaDebridEuHook" __type__ = "hook" - __version__ = "0.05" + __version__ = "0.06" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Mega-debrid.eu hook plugin""" __license__ = "GPLv3" __authors__ = [("D.Ducatel", "dducatel@je-geek.fr")] - def getHosters(self): - reponse = self.getURL("http://www.mega-debrid.eu/api.php", get={'action': "getHosters"}) + def get_hosters(self): + reponse = self.load("http://www.mega-debrid.eu/api.php", get={'action': "getHosters"}) json_data = json_loads(reponse) if json_data['response_code'] == "ok": host_list = [element[0] for element in json_data['hosters']] else: - self.logError(_("Unable to retrieve hoster list")) - host_list = list() + self.log_error(_("Unable to retrieve hoster list")) + host_list = [] return host_list diff --git a/module/plugins/hooks/MegaRapidoNetHook.py b/module/plugins/hooks/MegaRapidoNetHook.py index e113b305e..4956427ff 100644 --- a/module/plugins/hooks/MegaRapidoNetHook.py +++ b/module/plugins/hooks/MegaRapidoNetHook.py @@ -8,7 +8,8 @@ from module.plugins.internal.MultiHook import MultiHook class MegaRapidoNetHook(MultiHook): __name__ = "MegaRapidoNetHook" __type__ = "hook" - __version__ = "0.02" + __version__ = "0.03" + __status__ = "testing" __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), @@ -20,15 +21,15 @@ class MegaRapidoNetHook(MultiHook): __authors__ = [("Kagenoshin", "kagenoshin@gmx.ch")] - def getHosters(self): - hosters = {'1fichier' : [],#leave it there are so many possible addresses? + def get_hosters(self): + hosters = {'1fichier' : [], # leave it there are so many possible addresses? '1st-files' : ['1st-files.com'], '2shared' : ['2shared.com'], '4shared' : ['4shared.com', '4shared-china.com'], 'asfile' : ['http://asfile.com/'], 'bitshare' : ['bitshare.com'], 'brupload' : ['brupload.net'], - 'crocko' : ['crocko.com','easy-share.com'], + 'crocko' : ['crocko.com', 'easy-share.com'], 'dailymotion' : ['dailymotion.com'], 'depfile' : ['depfile.com'], 'depositfiles': ['depositfiles.com', 'dfiles.eu'], @@ -38,12 +39,12 @@ class MegaRapidoNetHook(MultiHook): 'extmatrix' : ['extmatrix.com'], 'facebook' : [], 'file4go' : ['file4go.com'], - 'filecloud' : ['filecloud.io','ifile.it','mihd.net'], + 'filecloud' : ['filecloud.io', 'ifile.it', 'mihd.net'], 'filefactory' : ['filefactory.com'], 'fileom' : ['fileom.com'], 'fileparadox' : ['fileparadox.in'], 'filepost' : ['filepost.com', 'fp.io'], - 'filerio' : ['filerio.in','filerio.com','filekeen.com'], + 'filerio' : ['filerio.in', 'filerio.com', 'filekeen.com'], 'filesflash' : ['filesflash.com'], 'firedrive' : ['firedrive.com', 'putlocker.com'], 'flashx' : [], @@ -51,7 +52,7 @@ class MegaRapidoNetHook(MultiHook): 'gigasize' : ['gigasize.com'], 'hipfile' : ['hipfile.com'], 'junocloud' : ['junocloud.me'], - 'letitbit' : ['letitbit.net','shareflare.net'], + 'letitbit' : ['letitbit.net', 'shareflare.net'], 'mediafire' : ['mediafire.com'], 'mega' : ['mega.co.nz'], 'megashares' : ['megashares.com'], @@ -75,7 +76,7 @@ class MegaRapidoNetHook(MultiHook): hoster_list = [] - for item in hosters.itervalues(): + for item in hosters.values(): hoster_list.extend(item) return hoster_list diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 941938920..a76a578bf 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -6,14 +6,15 @@ import os import re import traceback -from module.plugins.Hook import Hook, threaded -from module.utils import save_join +from module.plugins.internal.Addon import Addon, threaded +from module.utils import save_join as fs_join -class MergeFiles(Hook): +class MergeFiles(Addon): __name__ = "MergeFiles" __type__ = "hook" - __version__ = "0.14" + __version__ = "0.16" + __status__ = "testing" __config__ = [("activated", "bool", "Activated", True)] @@ -22,20 +23,14 @@ class MergeFiles(Hook): __authors__ = [("and9000", "me@has-no-mail.com")] - interval = 0 #@TODO: Remove in 0.4.10 - BUFFER_SIZE = 4096 - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - @threaded - def packageFinished(self, pack): + def package_finished(self, pack): files = {} fid_dict = {} - for fid, data in pack.getChildren().iteritems(): + for fid, data in pack.getChildren().items(): if re.search("\.\d{3}$", data['name']): if data['name'][:-4] not in files: files[data['name'][:-4]] = [] @@ -43,24 +38,24 @@ class MergeFiles(Hook): files[data['name'][:-4]].sort() fid_dict[data['name']] = fid - download_folder = self.config['general']['download_folder'] + download_folder = self.pyload.config.get("general", "download_folder") - if self.config['general']['folder_per_package']: - download_folder = save_join(download_folder, pack.folder) + if self.pyload.config.get("general", "folder_per_package"): + download_folder = fs_join(download_folder, pack.folder) - for name, file_list in files.iteritems(): - self.logInfo(_("Starting merging of"), name) + for name, file_list in files.items(): + self.log_info(_("Starting merging of"), name) - with open(save_join(download_folder, name), "wb") as final_file: + with open(fs_join(download_folder, name), "wb") as final_file: for splitted_file in file_list: - self.logDebug("Merging part", splitted_file) + self.log_debug("Merging part", splitted_file) - pyfile = self.core.files.getFile(fid_dict[splitted_file]) + pyfile = self.pyload.files.getFile(fid_dict[splitted_file]) pyfile.setStatus("processing") try: - with open(save_join(download_folder, splitted_file), "rb") as s_file: + with open(fs_join(download_folder, splitted_file), "rb") as s_file: size_written = 0 s_file_size = int(os.path.getsize(os.path.join(download_folder, splitted_file))) while True: @@ -71,7 +66,7 @@ class MergeFiles(Hook): pyfile.setProgress((size_written * 100) / s_file_size) else: break - self.logDebug("Finished merging part", splitted_file) + self.log_debug("Finished merging part", splitted_file) except Exception, e: traceback.print_exc() @@ -81,4 +76,4 @@ class MergeFiles(Hook): pyfile.setStatus("finished") pyfile.release() - self.logInfo(_("Finished merging of"), name) + self.log_info(_("Finished merging of"), name) diff --git a/module/plugins/hooks/MultiHome.py b/module/plugins/hooks/MultiHome.py index a26d139c0..929ab9a25 100644 --- a/module/plugins/hooks/MultiHome.py +++ b/module/plugins/hooks/MultiHome.py @@ -2,64 +2,61 @@ import time -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon -class MultiHome(Hook): +class MultiHome(Addon): __name__ = "MultiHome" __type__ = "hook" - __version__ = "0.12" + __version__ = "0.14" + __status__ = "testing" __config__ = [("interfaces", "str", "Interfaces", "None")] - __description__ = """Ip address changer""" + __description__ = """IP address changer""" __license__ = "GPLv3" __authors__ = [("mkaay", "mkaay@mkaay.de")] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 + def init(self): self.register = {} self.interfaces = [] - self.parseInterfaces(self.getConfig('interfaces').split(";")) + self.parse_interfaces(self.get_config('interfaces').split(";")) if not self.interfaces: - self.parseInterfaces([self.config['download']['interface']]) - self.setConfig("interfaces", self.toConfig()) + self.parse_interfaces([self.pyload.config.get("download", "interface")]) + self.set_config("interfaces", self.to_config()) - def toConfig(self): + def to_config(self): return ";".join(i.adress for i in self.interfaces) - def parseInterfaces(self, interfaces): + def parse_interfaces(self, interfaces): for interface in interfaces: if not interface or str(interface).lower() == "none": continue self.interfaces.append(Interface(interface)) - def coreReady(self): - requestFactory = self.core.requestFactory + def activate(self): + requestFactory = self.pyload.requestFactory oldGetRequest = requestFactory.getRequest - def getRequest(pluginName, account=None): - iface = self.bestInterface(pluginName, account) + def get_request(pluginName, account=None): + iface = self.best_interface(pluginName, account) if iface: iface.useFor(pluginName, account) requestFactory.iface = lambda: iface.adress - self.logDebug("Using address", iface.adress) + self.log_debug("Using address", iface.adress) return oldGetRequest(pluginName, account) - requestFactory.getRequest = getRequest + requestFactory.getRequest = get_request - def bestInterface(self, pluginName, account): + def best_interface(self, pluginName, account): best = None for interface in self.interfaces: if not best or interface.lastPluginAccess(pluginName, account) < best.lastPluginAccess(pluginName, account): @@ -74,13 +71,13 @@ class Interface(object): self.history = {} - def lastPluginAccess(self, pluginName, account): + def last_plugin_access(self, pluginName, account): if (pluginName, account) in self.history: return self.history[(pluginName, account)] return 0 - def useFor(self, pluginName, account): + def use_for(self, pluginName, account): self.history[(pluginName, account)] = time.time() diff --git a/module/plugins/hooks/MultihostersComHook.py b/module/plugins/hooks/MultihostersComHook.py index 7b5e49c49..ec1cf9c85 100644 --- a/module/plugins/hooks/MultihostersComHook.py +++ b/module/plugins/hooks/MultihostersComHook.py @@ -6,12 +6,13 @@ from module.plugins.hooks.ZeveraComHook import ZeveraComHook class MultihostersComHook(ZeveraComHook): __name__ = "MultihostersComHook" __type__ = "hook" - __version__ = "0.02" + __version__ = "0.03" + __status__ = "testing" - __config__ = [("mode" , "all;listed;unlisted", "Use for plugins (if supported)" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed", "bool" , "Revert to standard download if download fails", False), - ("interval" , "int" , "Reload interval in hours (0 to disable)" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Multihosters.com hook plugin""" __license__ = "GPLv3" diff --git a/module/plugins/hooks/MultishareCzHook.py b/module/plugins/hooks/MultishareCzHook.py index 6052b7673..30f1e21b5 100644 --- a/module/plugins/hooks/MultishareCzHook.py +++ b/module/plugins/hooks/MultishareCzHook.py @@ -8,13 +8,13 @@ from module.plugins.internal.MultiHook import MultiHook class MultishareCzHook(MultiHook): __name__ = "MultishareCzHook" __type__ = "hook" - __version__ = "0.07" + __version__ = "0.08" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """MultiShare.cz hook plugin""" __license__ = "GPLv3" @@ -24,6 +24,6 @@ class MultishareCzHook(MultiHook): HOSTER_PATTERN = r'<img class="logo-shareserveru"[^>]*?alt="(.+?)"></td>\s*<td class="stav">[^>]*?alt="OK"' - def getHosters(self): - html = self.getURL("http://www.multishare.cz/monitoring/") + def get_hosters(self): + html = self.load("http://www.multishare.cz/monitoring/") return re.findall(self.HOSTER_PATTERN, html) diff --git a/module/plugins/hooks/MyfastfileComHook.py b/module/plugins/hooks/MyfastfileComHook.py index 20a1cfac2..1eedd9238 100644 --- a/module/plugins/hooks/MyfastfileComHook.py +++ b/module/plugins/hooks/MyfastfileComHook.py @@ -7,22 +7,22 @@ from module.plugins.internal.MultiHook import MultiHook class MyfastfileComHook(MultiHook): __name__ = "MyfastfileComHook" __type__ = "hook" - __version__ = "0.05" + __version__ = "0.06" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Myfastfile.com hook plugin""" __license__ = "GPLv3" __authors__ = [("stickell", "l.stickell@yahoo.it")] - def getHosters(self): - json_data = self.getURL("http://myfastfile.com/api.php", get={'hosts': ""}, decode=True) - self.logDebug("JSON data", json_data) + def get_hosters(self): + json_data = self.load("http://myfastfile.com/api.php", get={'hosts': ""}) + self.log_debug("JSON data", json_data) json_data = json_loads(json_data) return json_data['hosts'] diff --git a/module/plugins/hooks/NoPremiumPlHook.py b/module/plugins/hooks/NoPremiumPlHook.py index b5a007ff9..7dbdf6a68 100644 --- a/module/plugins/hooks/NoPremiumPlHook.py +++ b/module/plugins/hooks/NoPremiumPlHook.py @@ -7,23 +7,23 @@ from module.plugins.internal.MultiHook import MultiHook class NoPremiumPlHook(MultiHook): __name__ = "NoPremiumPlHook" __type__ = "hook" - __version__ = "0.03" + __version__ = "0.04" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """NoPremium.pl hook plugin""" __license__ = "GPLv3" __authors__ = [("goddie", "dev@nopremium.pl")] - def getHosters(self): - hostings = json_loads(self.getURL("https://www.nopremium.pl/clipboard.php?json=3").strip()) - hostings_domains = [domain for row in hostings for domain in row["domains"] if row["sdownload"] == "0"] + def get_hosters(self): + hostings = json_loads(self.load("https://www.nopremium.pl/clipboard.php?json=3").strip()) + hostings_domains = [domain for row in hostings for domain in row['domains'] if row['sdownload'] == "0"] - self.logDebug(hostings_domains) + self.log_debug(hostings_domains) return hostings_domains diff --git a/module/plugins/hooks/OverLoadMeHook.py b/module/plugins/hooks/OverLoadMeHook.py index d608a2ecd..5398fc17d 100644 --- a/module/plugins/hooks/OverLoadMeHook.py +++ b/module/plugins/hooks/OverLoadMeHook.py @@ -6,24 +6,20 @@ from module.plugins.internal.MultiHook import MultiHook class OverLoadMeHook(MultiHook): __name__ = "OverLoadMeHook" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.05" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 ), - ("ssl" , "bool" , "Use HTTPS" , True )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Over-Load.me hook plugin""" __license__ = "GPLv3" __authors__ = [("marley", "marley@over-load.me")] - def getHosters(self): - https = "https" if self.getConfig('ssl') else "http" - html = self.getURL(https + "://api.over-load.me/hoster.php", - get={'auth': "0001-cb1f24dadb3aa487bda5afd3b76298935329be7700cd7-5329be77-00cf-1ca0135f"}).replace("\"", "").strip() - self.logDebug("Hosterlist", html) - + def get_hosters(self): + html = self.load("https://api.over-load.me/hoster.php", + get={'auth': "0001-cb1f24dadb3aa487bda5afd3b76298935329be7700cd7-5329be77-00cf-1ca0135f"}).replace("\"", "").strip() return [x.strip() for x in html.split(",") if x.strip()] diff --git a/module/plugins/hooks/PremiumToHook.py b/module/plugins/hooks/PremiumToHook.py index ef2a84223..bcd7a7aab 100644 --- a/module/plugins/hooks/PremiumToHook.py +++ b/module/plugins/hooks/PremiumToHook.py @@ -6,13 +6,13 @@ from module.plugins.internal.MultiHook import MultiHook class PremiumToHook(MultiHook): __name__ = "PremiumToHook" __type__ = "hook" - __version__ = "0.08" + __version__ = "0.11" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Premium.to hook plugin""" __license__ = "GPLv3" @@ -21,7 +21,9 @@ class PremiumToHook(MultiHook): ("stickell", "l.stickell@yahoo.it")] - def getHosters(self): - html = self.getURL("http://premium.to/api/hosters.php", - get={'username': self.account.username, 'password': self.account.password}) + def get_hosters(self): + user, info = self.account.select() + html = self.load("http://premium.to/api/hosters.php", + get={'username': user, + 'password': info['login']['password']}) return [x.strip() for x in html.replace("\"", "").split(";")] diff --git a/module/plugins/hooks/PremiumizeMeHook.py b/module/plugins/hooks/PremiumizeMeHook.py index e081fb389..9a9a380af 100644 --- a/module/plugins/hooks/PremiumizeMeHook.py +++ b/module/plugins/hooks/PremiumizeMeHook.py @@ -7,32 +7,34 @@ from module.plugins.internal.MultiHook import MultiHook class PremiumizeMeHook(MultiHook): __name__ = "PremiumizeMeHook" __type__ = "hook" - __version__ = "0.17" + __version__ = "0.20" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Premiumize.me hook plugin""" __license__ = "GPLv3" __authors__ = [("Florian Franzen", "FlorianFranzen@gmail.com")] - def getHosters(self): - # Get account data - user, data = self.account.selectAccount() + def get_hosters(self): + #: Get account data + user, info = self.account.select() - # Get supported hosters list from premiumize.me using the - # json API v1 (see https://secure.premiumize.me/?show=api) - answer = self.getURL("https://api.premiumize.me/pm-api/v1.php", - get={'method': "hosterlist", 'params[login]': user, 'params[pass]': data['password']}) + #: Get supported hosters list from premiumize.me using the + #: json API v1 (see https://secure.premiumize.me/?show=api) + answer = self.load("http://api.premiumize.me/pm-api/v1.php", #@TODO: Revert to `https` in 0.4.10 + get={'method' : "hosterlist", + 'params[login]': user, + 'params[pass]' : info['login']['password']}) data = json_loads(answer) - # If account is not valid thera are no hosters available + #: If account is not valid thera are no hosters available if data['status'] != 200: return [] - # Extract hosters from json file + #: Extract hosters from json file return data['result']['hosterlist'] diff --git a/module/plugins/hooks/PutdriveComHook.py b/module/plugins/hooks/PutdriveComHook.py index c3ebf4ff3..d206aaf88 100644 --- a/module/plugins/hooks/PutdriveComHook.py +++ b/module/plugins/hooks/PutdriveComHook.py @@ -6,12 +6,13 @@ from module.plugins.hooks.ZeveraComHook import ZeveraComHook class PutdriveComHook(ZeveraComHook): __name__ = "PutdriveComHook" __type__ = "hook" - __version__ = "0.01" + __version__ = "0.02" + __status__ = "testing" - __config__ = [("mode" , "all;listed;unlisted", "Use for plugins (if supported)" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed", "bool" , "Revert to standard download if download fails", False), - ("interval" , "int" , "Reload interval in hours (0 to disable)" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Putdrive.com hook plugin""" __license__ = "GPLv3" diff --git a/module/plugins/hooks/RPNetBizHook.py b/module/plugins/hooks/RPNetBizHook.py index 10332948d..5d26b7f09 100644 --- a/module/plugins/hooks/RPNetBizHook.py +++ b/module/plugins/hooks/RPNetBizHook.py @@ -7,30 +7,32 @@ from module.plugins.internal.MultiHook import MultiHook class RPNetBizHook(MultiHook): __name__ = "RPNetBizHook" __type__ = "hook" - __version__ = "0.14" + __version__ = "0.16" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """RPNet.biz hook plugin""" __license__ = "GPLv3" __authors__ = [("Dman", "dmanugm@gmail.com")] - def getHosters(self): - # Get account data - user, data = self.account.selectAccount() + def get_hosters(self): + #: Get account data + user, info = self.account.select() - res = self.getURL("https://premium.rpnet.biz/client_api.php", - get={'username': user, 'password': data['password'], 'action': "showHosterList"}) + res = self.load("https://premium.rpnet.biz/client_api.php", + get={'username': user, + 'password': info['login']['password'], + 'action' : "showHosterList"}) hoster_list = json_loads(res) - # If account is not valid thera are no hosters available + #: If account is not valid thera are no hosters available if 'error' in hoster_list: return [] - # Extract hosters from json file + #: Extract hosters from json file return hoster_list['hosters'] diff --git a/module/plugins/hooks/RapideoPlHook.py b/module/plugins/hooks/RapideoPlHook.py index 0400f07ba..130f73851 100644 --- a/module/plugins/hooks/RapideoPlHook.py +++ b/module/plugins/hooks/RapideoPlHook.py @@ -7,23 +7,23 @@ from module.plugins.internal.MultiHook import MultiHook class RapideoPlHook(MultiHook): __name__ = "RapideoPlHook" __type__ = "hook" - __version__ = "0.03" + __version__ = "0.04" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Rapideo.pl hook plugin""" __license__ = "GPLv3" __authors__ = [("goddie", "dev@rapideo.pl")] - def getHosters(self): - hostings = json_loads(self.getURL("https://www.rapideo.pl/clipboard.php?json=3").strip()) - hostings_domains = [domain for row in hostings for domain in row["domains"] if row["sdownload"] == "0"] + def get_hosters(self): + hostings = json_loads(self.load("https://www.rapideo.pl/clipboard.php?json=3").strip()) + hostings_domains = [domain for row in hostings for domain in row['domains'] if row['sdownload'] == "0"] - self.logDebug(hostings_domains) + self.log_debug(hostings_domains) return hostings_domains diff --git a/module/plugins/hooks/RealdebridComHook.py b/module/plugins/hooks/RealdebridComHook.py index aa0c9f640..01b9d165e 100644 --- a/module/plugins/hooks/RealdebridComHook.py +++ b/module/plugins/hooks/RealdebridComHook.py @@ -6,22 +6,19 @@ from module.plugins.internal.MultiHook import MultiHook class RealdebridComHook(MultiHook): __name__ = "RealdebridComHook" __type__ = "hook" - __version__ = "0.46" + __version__ = "0.47" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 ), - ("ssl" , "bool" , "Use HTTPS" , True )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Real-Debrid.com hook plugin""" __license__ = "GPLv3" __authors__ = [("Devirex Hazzard", "naibaf_11@yahoo.de")] - def getHosters(self): - https = "https" if self.getConfig('ssl') else "http" - html = self.getURL(https + "://real-debrid.com/api/hosters.php").replace("\"", "").strip() - + def get_hosters(self): + html = self.load("https://real-debrid.com/api/hosters.php").replace("\"", "").strip() return [x.strip() for x in html.split(",") if x.strip()] diff --git a/module/plugins/hooks/RehostToHook.py b/module/plugins/hooks/RehostToHook.py index a2415129a..7bb27e820 100644 --- a/module/plugins/hooks/RehostToHook.py +++ b/module/plugins/hooks/RehostToHook.py @@ -6,22 +6,22 @@ from module.plugins.internal.MultiHook import MultiHook class RehostToHook(MultiHook): __name__ = "RehostToHook" __type__ = "hook" - __version__ = "0.50" + __version__ = "0.51" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Rehost.to hook plugin""" __license__ = "GPLv3" __authors__ = [("RaNaN", "RaNaN@pyload.org")] - def getHosters(self): - user, data = self.account.selectAccount() - html = self.getURL("http://rehost.to/api.php", + def get_hosters(self): + user, info = self.account.select() + html = self.load("http://rehost.to/api.php", get={'cmd' : "get_supported_och_dl", - 'long_ses': self.account.getAccountInfo(user)['session']}) + 'long_ses': self.account.get_data(user)['session']}) return [x.strip() for x in html.replace("\"", "").split(",")] diff --git a/module/plugins/hooks/RestartFailed.py b/module/plugins/hooks/RestartFailed.py index 865af2a6b..6c3388e3a 100644 --- a/module/plugins/hooks/RestartFailed.py +++ b/module/plugins/hooks/RestartFailed.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon -class RestartFailed(Hook): +class RestartFailed(Addon): __name__ = "RestartFailed" __type__ = "hook" - __version__ = "1.58" + __version__ = "1.60" + __status__ = "testing" __config__ = [("interval", "int", "Check interval in minutes", 90)] @@ -18,28 +19,27 @@ class RestartFailed(Hook): MIN_CHECK_INTERVAL = 15 * 60 #: 15 minutes - # def pluginConfigChanged(self, plugin, name, value): + # def plugin_config_changed(self, plugin, name, value): # if name == "interval": # interval = value * 60 - # if self.MIN_CHECK_INTERVAL <= interval != self.interval: - # self.core.scheduler.removeJob(self.cb) + # if self.MIN_CHECK_INTERVAL <= interval is not self.interval: + # self.pyload.scheduler.removeJob(self.cb) # self.interval = interval - # self.initPeriodical() + # self.init_periodical() # else: - # self.logDebug("Invalid interval value, kept current") + # self.log_debug("Invalid interval value, kept current") def periodical(self): - self.logDebug(_("Restart failed downloads")) - self.core.api.restartFailed() + self.log_debug("Restart failed downloads") + self.pyload.api.restartFailed() - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - # self.event_list = ["pluginConfigChanged"] + def init(self): + # self.event_map = {'pluginConfigChanged': "plugin_config_changed"} self.interval = self.MIN_CHECK_INTERVAL - def coreReady(self): - # self.pluginConfigChanged(self.__name__, "interval", self.getConfig('interval')) - self.interval = max(self.MIN_CHECK_INTERVAL, self.getConfig('interval') * 60) + def activate(self): + # self.plugin_config_changed(self.__name__, "interval", self.get_config('interval')) + self.interval = max(self.MIN_CHECK_INTERVAL, self.get_config('interval') * 60) diff --git a/module/plugins/hooks/SimplyPremiumComHook.py b/module/plugins/hooks/SimplyPremiumComHook.py index 116e3a76e..6fbd75c8a 100644 --- a/module/plugins/hooks/SimplyPremiumComHook.py +++ b/module/plugins/hooks/SimplyPremiumComHook.py @@ -7,21 +7,21 @@ from module.plugins.internal.MultiHook import MultiHook class SimplyPremiumComHook(MultiHook): __name__ = "SimplyPremiumComHook" __type__ = "hook" - __version__ = "0.05" + __version__ = "0.06" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Simply-Premium.com hook plugin""" __license__ = "GPLv3" __authors__ = [("EvolutionClip", "evolutionclip@live.de")] - def getHosters(self): - json_data = self.getURL("http://www.simply-premium.com/api/hosts.php", get={'format': "json", 'online': 1}) + def get_hosters(self): + json_data = self.load("http://www.simply-premium.com/api/hosts.php", get={'format': "json", 'online': 1}) json_data = json_loads(json_data) host_list = [element['regex'] for element in json_data['result']] diff --git a/module/plugins/hooks/SimplydebridComHook.py b/module/plugins/hooks/SimplydebridComHook.py index 01629df99..0da7ec719 100644 --- a/module/plugins/hooks/SimplydebridComHook.py +++ b/module/plugins/hooks/SimplydebridComHook.py @@ -6,19 +6,19 @@ from module.plugins.internal.MultiHook import MultiHook class SimplydebridComHook(MultiHook): __name__ = "SimplydebridComHook" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.05" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Simply-Debrid.com hook plugin""" __license__ = "GPLv3" __authors__ = [("Kagenoshin", "kagenoshin@gmx.ch")] - def getHosters(self): - html = self.getURL("http://simply-debrid.com/api.php", get={'list': 1}) + def get_hosters(self): + html = self.load("http://simply-debrid.com/api.php", get={'list': 1}) return [x.strip() for x in html.rstrip(';').replace("\"", "").split(";")] diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index 7901ca540..a1ddc3094 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -7,14 +7,14 @@ import urlparse from types import MethodType from module.PyFile import PyFile -from module.plugins.Hook import Hook -from module.plugins.Plugin import SkipDownload +from module.plugins.internal.Addon import Addon -class SkipRev(Hook): +class SkipRev(Addon): __name__ = "SkipRev" __type__ = "hook" - __version__ = "0.29" + __version__ = "0.33" + __status__ = "testing" __config__ = [("mode" , "Auto;Manual", "Choose recovery archives to skip" , "Auto"), ("revtokeep", "int" , "Number of recovery archives to keep for package", 0 )] @@ -24,30 +24,19 @@ class SkipRev(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - @staticmethod - def _setup(self): - self.pyfile.plugin._setup() + def _init(self): + self.pyfile.plugin._init() if self.pyfile.hasStatus("skipped"): - raise SkipDownload(self.pyfile.statusname or self.pyfile.pluginname) + self.skip(self.pyfile.statusname or self.pyfile.pluginname) def _name(self, pyfile): - if hasattr(pyfile.pluginmodule, "getInfo"): #@NOTE: getInfo is deprecated in 0.4.10 - return pyfile.pluginmodule.getInfo([pyfile.url]).next()[0] - else: - self.logWarning("Unable to grab file name") - return urlparse.urlparse(urllib.unquote(pyfile.url)).path.split('/')[-1] + return pyfile.pluginclass.get_info(pyfile.url)['name'] def _pyfile(self, link): - return PyFile(self.core.files, + return PyFile(self.pyload.files, link.fid, link.url, link.name, @@ -59,47 +48,46 @@ class SkipRev(Hook): link.order) - def downloadPreparing(self, pyfile): + def download_preparing(self, pyfile): name = self._name(pyfile) if pyfile.statusname is _("unskipped") or not name.endswith(".rev") or not ".part" in name: return - revtokeep = -1 if self.getConfig('mode') == "Auto" else self.getConfig('revtokeep') + revtokeep = -1 if self.get_config('mode') == "Auto" else self.get_config('revtokeep') if revtokeep: status_list = (1, 4, 8, 9, 14) if revtokeep < 0 else (1, 3, 4, 8, 9, 14) pyname = re.compile(r'%s\.part\d+\.rev$' % name.rsplit('.', 2)[0].replace('.', '\.')) - queued = [True for link in self.core.api.getPackageData(pyfile.package().id).links \ + queued = [True for link in self.pyload.api.getPackageData(pyfile.package().id).links \ if link.status not in status_list and pyname.match(link.name)].count(True) - if not queued or queued < revtokeep: #: keep one rev at least in auto mode + if not queued or queued < revtokeep: #: Keep one rev at least in auto mode return pyfile.setCustomStatus("SkipRev", "skipped") - if not hasattr(pyfile.plugin, "_setup"): - # Work-around: inject status checker inside the preprocessing routine of the plugin - pyfile.plugin._setup = pyfile.plugin.setup - pyfile.plugin.setup = MethodType(self._setup, pyfile.plugin) + if not hasattr(pyfile.plugin, "_init"): + #: Work-around: inject status checker inside the preprocessing routine of the plugin + pyfile.plugin._init = pyfile.plugin.init + pyfile.plugin.init = MethodType(self._init, pyfile.plugin) - def downloadFailed(self, pyfile): - #: Check if pyfile is still "failed", - # maybe might has been restarted in meantime + def download_failed(self, pyfile): + #: Check if pyfile is still "failed", maybe might has been restarted in meantime if pyfile.status != 8 or pyfile.name.rsplit('.', 1)[-1].strip() not in ("rar", "rev"): return - revtokeep = -1 if self.getConfig('mode') == "Auto" else self.getConfig('revtokeep') + revtokeep = -1 if self.get_config('mode') == "Auto" else self.get_config('revtokeep') if not revtokeep: return pyname = re.compile(r'%s\.part\d+\.rev$' % pyfile.name.rsplit('.', 2)[0].replace('.', '\.')) - for link in self.core.api.getPackageData(pyfile.package().id).links: - if link.status is 4 and pyname.match(link.name): + for link in self.pyload.api.getPackageData(pyfile.package().id).links: + if link.status == 4 and pyname.match(link.name): pylink = self._pyfile(link) if revtokeep > -1 or pyfile.name.endswith(".rev"): @@ -107,6 +95,6 @@ class SkipRev(Hook): else: pylink.setCustomStatus(_("unskipped"), "queued") - self.core.files.save() + self.pyload.files.save() pylink.release() return diff --git a/module/plugins/hooks/SmoozedComHook.py b/module/plugins/hooks/SmoozedComHook.py index 24b7c8df0..b9825b223 100644 --- a/module/plugins/hooks/SmoozedComHook.py +++ b/module/plugins/hooks/SmoozedComHook.py @@ -6,19 +6,19 @@ from module.plugins.internal.MultiHook import MultiHook class SmoozedComHook(MultiHook): __name__ = "SmoozedComHook" __type__ = "hook" - __version__ = "0.03" + __version__ = "0.04" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Smoozed.com hook plugin""" __license__ = "GPLv3" __authors__ = [("", "")] - def getHosters(self): - user, data = self.account.selectAccount() - return self.account.getAccountInfo(user)["hosters"] + def get_hosters(self): + user, info = self.account.select() + return self.account.get_data(user)['hosters'] diff --git a/module/plugins/hooks/UnSkipOnFail.py b/module/plugins/hooks/UnSkipOnFail.py index 9059d0350..d467b8a01 100644 --- a/module/plugins/hooks/UnSkipOnFail.py +++ b/module/plugins/hooks/UnSkipOnFail.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- from module.PyFile import PyFile -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon -class UnSkipOnFail(Hook): +class UnSkipOnFail(Addon): __name__ = "UnSkipOnFail" __type__ = "hook" - __version__ = "0.07" + __version__ = "0.09" + __status__ = "testing" __config__ = [("activated", "bool", "Activated", True)] @@ -16,46 +17,38 @@ class UnSkipOnFail(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - - def downloadFailed(self, pyfile): - #: Check if pyfile is still "failed", - # maybe might has been restarted in meantime + def download_failed(self, pyfile): + #: Check if pyfile is still "failed", maybe might has been restarted in meantime if pyfile.status != 8: return msg = _("Looking for skipped duplicates of: %s (pid:%s)") - self.logInfo(msg % (pyfile.name, pyfile.package().id)) + self.log_info(msg % (pyfile.name, pyfile.package().id)) - link = self.findDuplicate(pyfile) + link = self.find_duplicate(pyfile) if link: - self.logInfo(_("Queue found duplicate: %s (pid:%s)") % (link.name, link.packageID)) + self.log_info(_("Queue found duplicate: %s (pid:%s)") % (link.name, link.packageID)) #: Change status of "link" to "new_status". - # "link" has to be a valid FileData object, - # "new_status" has to be a valid status name - # (i.e. "queued" for this Plugin) - # It creates a temporary PyFile object using - # "link" data, changes its status, and tells - # the core.files-manager to save its data. + #: "link" has to be a valid FileData object, + #: "new_status" has to be a valid status name + #: (i.e. "queued" for this Plugin) + #: It creates a temporary PyFile object using + #: "link" data, changes its status, and tells + #: The pyload.files-manager to save its data. pylink = self._pyfile(link) pylink.setCustomStatus(_("unskipped"), "queued") - self.core.files.save() + self.pyload.files.save() pylink.release() else: - self.logInfo(_("No duplicates found")) + self.log_info(_("No duplicates found")) - def findDuplicate(self, pyfile): - """ Search all packages for duplicate links to "pyfile". + def find_duplicate(self, pyfile): + """Search all packages for duplicate links to "pyfile". Duplicates are links that would overwrite "pyfile". To test on duplicity the package-folder and link-name of twolinks are compared (link.name). @@ -64,28 +57,28 @@ class UnSkipOnFail(Hook): the data for "pyfile" iotselöf. It does MOT check the link's status. """ - queue = self.core.api.getQueue() #: get packages (w/o files, as most file data is useless here) + queue = self.pyload.api.getQueue() #: Get packages (w/o files, as most file data is useless here) for package in queue: - #: check if package-folder equals pyfile's package folder - if package.folder != pyfile.package().folder: + #: Check if package-folder equals pyfile's package folder + if package.folder is not pyfile.package().folder: continue - #: now get packaged data w/ files/links - pdata = self.core.api.getPackageData(package.pid) + #: Now get packaged data w/ files/links + pdata = self.pyload.api.getPackageData(package.pid) for link in pdata.links: - #: check if link is "skipped" + #: Check if link == "skipped" if link.status != 4: continue - #: check if link name collides with pdata's name - #: AND at last check if it is not pyfile itself - if link.name == pyfile.name and link.fid != pyfile.id: + #: Check if link name collides with pdata's name + #: and at last check if it is not pyfile itself + if link.name is pyfile.name and link.fid is not pyfile.id: return link def _pyfile(self, link): - return PyFile(self.core.files, + return PyFile(self.pyload.files, link.fid, link.url, link.name, diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 98d602226..117da0633 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -2,34 +2,23 @@ from __future__ import with_statement +import operator import os import re import sys import time +import traceback -from operator import itemgetter +from module.plugins.internal.Addon import Expose, Addon, threaded +from module.plugins.internal.Plugin import exists +from module.utils import fs_encode, save_join as fs_join -from module.network.RequestFactory import getURL -from module.plugins.Hook import Expose, Hook, threaded -from module.utils import save_join - -# Case-sensitive os.path.exists -def exists(path): - if os.path.exists(path): - if os.name == 'nt': - dir, name = os.path.split(path) - return name in os.listdir(dir) - else: - return True - else: - return False - - -class UpdateManager(Hook): +class UpdateManager(Addon): __name__ = "UpdateManager" __type__ = "hook" - __version__ = "0.52" + __version__ = "0.55" + __status__ = "testing" __config__ = [("activated" , "bool", "Activated" , True ), ("checkinterval", "int" , "Check interval in hours" , 8 ), @@ -39,7 +28,7 @@ class UpdateManager(Hook): ("reloadplugins", "bool", "Monitor plugin code changes in debug mode", True ), ("nodebugupdate", "bool", "Don't update plugins in debug mode" , False)] - __description__ = """ Check for updates """ + __description__ = """Check for updates""" __license__ = "GPLv3" __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] @@ -50,26 +39,26 @@ class UpdateManager(Hook): MIN_CHECK_INTERVAL = 3 * 60 * 60 #: 3 hours - def coreReady(self): + def activate(self): if self.checkonstart: - self.core.api.pauseServer() + self.pyload.api.pauseServer() self.update() if self.do_restart is False: - self.core.api.unpauseServer() + self.pyload.api.unpauseServer() - self.initPeriodical() + self.init_periodical() - def setup(self): + def init(self): self.info = {'pyload': False, 'version': None, 'plugins': False, 'last_check': time.time()} - self.mtimes = {} #: store modification time for each plugin + self.mtimes = {} #: Store modification time for each plugin - self.event_list = ["allDownloadsProcessed"] + self.event_map = {'allDownloadsProcessed': "all_downloads_processed"} self.interval = 10 - if self.getConfig('checkonstart'): - self.core.api.pauseServer() + if self.get_config('checkonstart'): + self.pyload.api.pauseServer() self.checkonstart = True else: self.checkonstart = False @@ -77,32 +66,43 @@ class UpdateManager(Hook): self.do_restart = False - def allDownloadsProcessed(self): + def all_downloads_processed(self): if self.do_restart is True: - self.logWarning(_("Downloads are done, restarting pyLoad to reload the updated plugins")) - self.core.api.restart() + self.log_warning(_("Downloads are done, restarting pyLoad to reload the updated plugins")) + self.pyload.api.restart() def periodical(self): - if self.core.debug: - if self.getConfig('reloadplugins'): - self.autoreloadPlugins() + if self.pyload.debug: + if self.get_config('reloadplugins'): + self.autoreload_plugins() - if self.getConfig('nodebugupdate'): + if self.get_config('nodebugupdate'): return - if self.getConfig('checkperiod') \ - and time.time() - max(self.MIN_CHECK_INTERVAL, self.getConfig('checkinterval') * 60 * 60) > self.info['last_check']: + if self.get_config('checkperiod') \ + and time.time() - max(self.MIN_CHECK_INTERVAL, self.get_config('checkinterval') * 60 * 60) > self.info['last_check']: self.update() + #: Deprecated method, use `autoreload_plugins` instead @Expose - def autoreloadPlugins(self): - """ reload and reindex all modified plugins """ + def autoreloadPlugins(self, *args, **kwargs): + """ + See `autoreload_plugins` + """ + return self.autoreload_plugins(*args, **kwargs) + + + @Expose + def autoreload_plugins(self): + """ + Reload and reindex all modified plugins + """ modules = filter( lambda m: m and (m.__name__.startswith("module.plugins.") or m.__name__.startswith("userplugins.")) and - m.__name__.count(".") >= 2, sys.modules.itervalues() + m.__name__.count(".") >= 2, sys.modules.values() ) reloads = [] @@ -110,12 +110,12 @@ class UpdateManager(Hook): for m in modules: root, type, name = m.__name__.rsplit(".", 2) id = (type, name) - if type in self.core.pluginManager.plugins: + if type in self.pyload.pluginManager.plugins: f = m.__file__.replace(".pyc", ".py") if not os.path.isfile(f): continue - mtime = os.stat(f).st_mtime + mtime = os.path.getmtime(f) if id not in self.mtimes: self.mtimes[id] = mtime @@ -123,29 +123,31 @@ class UpdateManager(Hook): reloads.append(id) self.mtimes[id] = mtime - return True if self.core.pluginManager.reloadPlugins(reloads) else False + return True if self.pyload.pluginManager.reloadPlugins(reloads) else False def server_response(self): try: - return getURL(self.SERVER_URL, get={'v': self.core.api.getServerVersion()}).splitlines() + return self.load(self.SERVER_URL, + get={'v': self.pyload.api.getServerVersion()}).splitlines() except Exception: - self.logWarning(_("Unable to retrieve server to get updates")) + self.log_warning(_("Unable to retrieve server to get updates")) @Expose @threaded def update(self): - """ check for updates """ - - if self._update() is 2 and self.getConfig('autorestart'): - if not self.core.api.statusDownloads(): - self.core.api.restart() + """ + Check for updates + """ + if self._update() == 2 and self.get_config('autorestart'): + if not self.pyload.api.statusDownloads(): + self.pyload.api.restart() else: self.do_restart = True - self.logWarning(_("Downloads are active, will restart once the download is done")) - self.core.api.pauseServer() + self.log_warning(_("Downloads are active, will restart once the download is done")) + self.pyload.api.pauseServer() def _update(self): @@ -157,30 +159,31 @@ class UpdateManager(Hook): exitcode = 0 elif data[0] == "None": - self.logInfo(_("No new pyLoad version available")) - exitcode = self._updatePlugins(data[1:]) + self.log_info(_("No new pyLoad version available")) + exitcode = self._update_plugins(data[1:]) elif onlyplugin: exitcode = 0 else: - self.logInfo(_("*** New pyLoad Version %s available ***") % data[0]) - self.logInfo(_("*** Get it here: https://github.com/pyload/pyload/releases ***")) + self.log_info(_("*** New pyLoad Version %s available ***") % data[0]) + self.log_info(_("*** Get it here: https://github.com/pyload/pyload/releases ***")) self.info['pyload'] = True self.info['version'] = data[0] exitcode = 3 - # Exit codes: - # -1 = No plugin updated, new pyLoad version available - # 0 = No plugin updated - # 1 = Plugins updated - # 2 = Plugins updated, but restart required + #: Exit codes: + #: -1 = No plugin updated, new pyLoad version available + #: 0 = No plugin updated + #: 1 = Plugins updated + #: 2 = Plugins updated, but restart required return exitcode - def _updatePlugins(self, data): - """ check for plugin updates """ - + def _update_plugins(self, data): + """ + Check for plugin updates + """ exitcode = 0 updated = [] @@ -202,7 +205,7 @@ class UpdateManager(Hook): if blacklist: type_plugins = [(plugin['type'], plugin['name'].rsplit('.', 1)[0]) for plugin in blacklist] - # Protect UpdateManager from self-removing + #: Protect UpdateManager from self-removing try: type_plugins.remove(("hook", "UpdateManager")) except ValueError: @@ -210,17 +213,17 @@ class UpdateManager(Hook): for t, n in type_plugins: for idx, plugin in enumerate(updatelist): - if n == plugin['name'] and t == plugin['type']: + if n is plugin['name'] and t is plugin['type']: updatelist.pop(idx) break - for t, n in self.removePlugins(sorted(type_plugins)): - self.logInfo(_("Removed blacklisted plugin: [%(type)s] %(name)s") % { + for t, n in self.remove_plugins(sorted(type_plugins)): + self.log_info(_("Removed blacklisted plugin: [%(type)s] %(name)s") % { 'type': t, 'name': n, }) - for plugin in sorted(updatelist, key=itemgetter("type", "name")): + for plugin in sorted(updatelist, key=operator.itemgetter("type", "name")): filename = plugin['name'] prefix = plugin['type'] version = plugin['version'] @@ -236,7 +239,7 @@ class UpdateManager(Hook): else: type = prefix - plugins = getattr(self.core.pluginManager, "%sPlugins" % type) + plugins = getattr(self.pyload.pluginManager, "%sPlugins" % type) oldver = float(plugins[name]['v']) if name in plugins else None newver = float(version) @@ -248,62 +251,74 @@ class UpdateManager(Hook): else: continue - self.logInfo(_(msg) % {'type' : type, + self.log_info(_(msg) % {'type' : type, 'name' : name, 'oldver': oldver, 'newver': newver}) try: - content = getURL(url % plugin) + content = self.load(url % plugin, decode=False) m = VERSION.search(content) if m and m.group(2) == version: - with open(save_join("userplugins", prefix, filename), "wb") as f: - f.write(content) + with open(fs_join("userplugins", prefix, filename), "wb") as f: + f.write(fs_encode(content)) updated.append((prefix, name)) else: - raise Exception, _("Version mismatch") + raise Exception(_("Version mismatch")) except Exception, e: - self.logError(_("Error updating plugin: %s") % filename, e) + self.log_error(_("Error updating plugin: %s") % filename, e) + if self.pyload.debug: + traceback.print_exc() if updated: - self.logInfo(_("*** Plugins updated ***")) + self.log_info(_("*** Plugins updated ***")) - if self.core.pluginManager.reloadPlugins(updated): + if self.pyload.pluginManager.reloadPlugins(updated): exitcode = 1 else: - self.logWarning(_("pyLoad restart required to reload the updated plugins")) + self.log_warning(_("pyLoad restart required to reload the updated plugins")) self.info['plugins'] = True exitcode = 2 self.manager.dispatchEvent("plugin_updated", updated) else: - self.logInfo(_("No plugin updates available")) + self.log_info(_("No plugin updates available")) - # Exit codes: - # 0 = No plugin updated - # 1 = Plugins updated - # 2 = Plugins updated, but restart required + #: Exit codes: + #: 0 = No plugin updated + #: 1 = Plugins updated + #: 2 = Plugins updated, but restart required return exitcode + #: Deprecated method, use `remove_plugins` instead @Expose - def removePlugins(self, type_plugins): - """ delete plugins from disk """ + def removePlugins(self, *args, **kwargs): + """ + See `remove_plugins` + """ + return self.remove_plugins(*args, **kwargs) + + @Expose + def remove_plugins(self, type_plugins): + """ + Delete plugins from disk + """ if not type_plugins: return removed = set() - self.logDebug("Requested deletion of plugins: %s" % type_plugins) + self.log_debug("Requested deletion of plugins: %s" % type_plugins) for type, name in type_plugins: rootplugins = os.path.join(pypath, "module", "plugins") for dir in ("userplugins", rootplugins): - py_filename = save_join(dir, type, name + ".py") + py_filename = fs_join(dir, type, name + ".py") pyc_filename = py_filename + "c" if type == "hook": @@ -311,7 +326,7 @@ class UpdateManager(Hook): self.manager.deactivateHook(name) except Exception, e: - self.logDebug(e) + self.log_debug(e) for filename in (py_filename, pyc_filename): if not exists(filename): @@ -321,10 +336,12 @@ class UpdateManager(Hook): os.remove(filename) except OSError, e: - self.logError(_("Error removing: %s") % filename, e) + self.log_warning(_("Error removing: %s") % filename, e) + if self.pyload.debug: + traceback.print_exc() else: id = (type, name) removed.add(id) - return list(removed) #: return a list of the plugins successfully removed + return list(removed) #: Return a list of the plugins successfully removed diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 5f9fd5212..52f542268 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -2,31 +2,37 @@ import pycurl -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon +from module.plugins.internal.Plugin import encode -class UserAgentSwitcher(Hook): +class UserAgentSwitcher(Addon): __name__ = "UserAgentSwitcher" __type__ = "hook" - __version__ = "0.07" + __version__ = "0.11" + __status__ = "testing" - __config__ = [("activated", "bool", "Activated" , True ), - ("useragent", "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")] + __config__ = [("activated" , "bool", "Activated" , True ), + ("connecttimeout", "int" , "Connection timeout in seconds" , 60 ), + ("maxredirs" , "int" , "Maximum number of redirects to follow" , 10 ), + ("useragent" , "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")] __description__ = """Custom user-agent""" __license__ = "GPLv3" __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - interval = 0 #@TODO: Remove in 0.4.10 + def download_preparing(self, pyfile): + connecttimeout = self.get_config('connecttimeout') + maxredirs = self.get_config('maxredirs') + useragent = self.get_config('useragent') + if connecttimeout: + pyfile.plugin.req.http.c.setopt(pycurl.CONNECTTIMEOUT, connecttimeout) - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 + if maxredirs: + pyfile.plugin.req.http.c.setopt(pycurl.MAXREDIRS, maxredirs) - - def downloadPreparing(self, pyfile): - useragent = self.getConfig('useragent').encode("utf8", "replace") #@TODO: Remove `encode` in 0.4.10 if useragent: - self.logDebug("Use custom user-agent string: " + useragent) - pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, useragent) + self.log_debug("Use custom user-agent string: " + useragent) + pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, encode(useragent)) diff --git a/module/plugins/hooks/WindowsPhoneNotify.py b/module/plugins/hooks/WindowsPhoneNotify.py index 8f66761f6..900d94a04 100644 --- a/module/plugins/hooks/WindowsPhoneNotify.py +++ b/module/plugins/hooks/WindowsPhoneNotify.py @@ -3,13 +3,14 @@ import httplib import time -from module.plugins.Hook import Hook, Expose +from module.plugins.internal.Addon import Addon, Expose -class WindowsPhoneNotify(Hook): +class WindowsPhoneNotify(Addon): __name__ = "WindowsPhoneNotify" __type__ = "hook" - __version__ = "0.10" + __version__ = "0.12" + __status__ = "testing" __config__ = [("push-id" , "str" , "Push ID" , "" ), ("push-url" , "str" , "Push url" , "" ), @@ -28,62 +29,58 @@ class WindowsPhoneNotify(Hook): ("Walter Purcaro", "vuolter@gmail.com" )] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - self.event_list = ["allDownloadsProcessed", "plugin_updated"] + def init(self): + self.event_list = ["plugin_updated"] + self.event_map = {'allDownloadsProcessed': "all_downloads_processed"} self.last_notify = 0 self.notifications = 0 def plugin_updated(self, type_plugins): - if not self.getConfig('notifyupdate'): + if not self.get_config('notifyupdate'): return self.notify(_("Plugins updated"), str(type_plugins)) - def coreReady(self): - self.key = (self.getConfig('push-id'), self.getConfig('push-url')) + def activate(self): + self.key = (self.get_config('push-id'), self.get_config('push-url')) - def coreExiting(self): - if not self.getConfig('notifyexit'): + def exit(self): + if not self.get_config('notifyexit'): return - if self.core.do_restart: + if self.pyload.do_restart: self.notify(_("Restarting pyLoad")) else: self.notify(_("Exiting pyLoad")) - def newCaptchaTask(self, task): - if not self.getConfig('notifycaptcha'): + def captcha_task(self, task): + if not self.get_config('notifycaptcha'): return self.notify(_("Captcha"), _("New request waiting user input")) - def packageFinished(self, pypack): - if self.getConfig('notifypackage'): + def package_finished(self, pypack): + if self.get_config('notifypackage'): self.notify(_("Package finished"), pypack.name) - def allDownloadsProcessed(self): - if not self.getConfig('notifyprocessed'): + def all_downloads_processed(self): + if not self.get_config('notifyprocessed'): return - if any(True for pdata in self.core.api.getQueue() if pdata.linksdone < pdata.linkstotal): + 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")) - def getXmlData(self, msg): + def get_xml_data(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) @@ -99,21 +96,21 @@ class WindowsPhoneNotify(Hook): if not id or not url: return - if self.core.isClientConnected() and not self.getConfig('ignoreclient'): + if self.pyload.isClientConnected() and not self.get_config('ignoreclient'): return elapsed_time = time.time() - self.last_notify - if elapsed_time < self.getConf("sendtimewait"): + if elapsed_time < self.get_config("sendtimewait"): return if elapsed_time > 60: self.notifications = 0 - elif self.notifications >= self.getConf("sendpermin"): + elif self.notifications >= self.get_config("sendpermin"): return - request = self.getXmlData("%s: %s" % (event, msg) if msg else event) + request = self.get_xml_data("%s: %s" % (event, msg) if msg else event) webservice = httplib.HTTP(url) webservice.putrequest("POST", id) diff --git a/module/plugins/hooks/XFileSharingPro.py b/module/plugins/hooks/XFileSharingPro.py index 92d89dc01..7567a31a3 100644 --- a/module/plugins/hooks/XFileSharingPro.py +++ b/module/plugins/hooks/XFileSharingPro.py @@ -2,13 +2,14 @@ import re -from module.plugins.Hook import Hook +from module.plugins.internal.Hook import Hook class XFileSharingPro(Hook): __name__ = "XFileSharingPro" __type__ = "hook" - __version__ = "0.38" + __version__ = "0.42" + __status__ = "testing" __config__ = [("activated" , "bool", "Activated" , True ), ("use_hoster_list" , "bool", "Load listed hosters only" , False), @@ -22,50 +23,51 @@ class XFileSharingPro(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - interval = 0 #@TODO: Remove in 0.4.10 regexp = {'hoster' : (r'https?://(?:www\.)?(?:\w+\.)*?(?P<DOMAIN>(?:[\d.]+|[\w\-^_]{3,}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)/(?:embed-)?\w{12}(?:\W|$)', r'https?://(?:[^/]+\.)?(?P<DOMAIN>%s)/(?:embed-)?\w+'), 'crypter': (r'https?://(?:www\.)?(?:\w+\.)*?(?P<DOMAIN>(?:[\d.]+|[\w\-^_]{3,}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)/(?:user|folder)s?/\w+', r'https?://(?:[^/]+\.)?(?P<DOMAIN>%s)/(?:user|folder)s?/\w+')} HOSTER_BUILTIN = [#WORKING HOSTERS: - "backin.net", "eyesfile.ca", "file4safe.com", "fileband.com", "filedwon.com", "fileparadox.in", - "filevice.com", "hostingbulk.com", "junkyvideo.com", "linestorage.com", "ravishare.com", "ryushare.com", - "salefiles.com", "sendmyway.com", "sharesix.com", "thefile.me", "verzend.be", "xvidstage.com", - #NOT TESTED: - "101shared.com", "4upfiles.com", "filemaze.ws", "filenuke.com", "linkzhost.com", "mightyupload.com", - "rockdizfile.com", "sharebeast.com", "sharerepo.com", "shareswift.com", "uploadbaz.com", "uploadc.com", - "vidbull.com", "worldbytez.com", "zalaa.com", "zomgupload.com", - #NOT WORKING: + "ani-stream.com", "backin.net", "cloudsix.me", "eyesfile.ca", "file4safe.com", + "fileband.com", "filedwon.com", "fileparadox.in", "filevice.com", + "hostingbulk.com", "junkyvideo.com", "linestorage.com", "ravishare.com", + "ryushare.com", "salefiles.com", "sendmyway.com", "sharebeast.com", + "sharesix.com", "thefile.me", "verzend.be", "worldbytez.com", "xvidstage.com", + #: NOT TESTED: + "101shared.com", "4upfiles.com", "filemaze.ws", "filenuke.com", + "linkzhost.com", "mightyupload.com", "rockdizfile.com", "sharerepo.com", + "shareswift.com", "uploadbaz.com", "uploadc.com", "vidbull.com", + "zalaa.com", "zomgupload.com", + #: NOT WORKING: "amonshare.com", "banicrazy.info", "boosterking.com", "host4desi.com", "laoupload.com", "rd-fs.com"] CRYPTER_BUILTIN = ["junocloud.me", "rapidfileshare.net"] - # def pluginConfigChanged(self, plugin, name, value): - # self.loadPattern() + # def plugin_config_changed(self, plugin, name, value): + # self.load_pattern() - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - # self.event_list = ["pluginConfigChanged"] + # def init(self): + # self.event_map = {'pluginConfigChanged': "plugin_config_changed"} - def coreReady(self): - self.loadPattern() + def activate(self): + self.load_pattern() - def loadPattern(self): - use_builtin_list = self.getConfig('use_builtin_list') + def load_pattern(self): + use_builtin_list = self.get_config('use_builtin_list') for type, plugin in (("hoster", "XFileSharingPro"), ("crypter", "XFileSharingProFolder")): - every_plugin = not self.getConfig("use_%s_list" % type) + every_plugin = not self.get_config("use_%s_list" % type) if every_plugin: - self.logInfo(_("Handling any %s I can!") % type) + self.log_info(_("Handling any %s I can!") % type) pattern = self.regexp[type][0] else: - plugins = self.getConfig('%s_list' % type) + plugins = self.get_config('%s_list' % type) plugin_set = set(plugins.replace(' ', '').replace('\\', '').replace('|', ',').replace(';', ',').lower().split(',')) if use_builtin_list: @@ -74,42 +76,42 @@ class XFileSharingPro(Hook): plugin_set -= set(('', u'')) if not plugin_set: - self.logInfo(_("No %s to handle") % type) + self.log_info(_("No %s to handle") % type) self._unload(type, plugin) return match_list = '|'.join(sorted(plugin_set)) len_match_list = len(plugin_set) - self.logInfo(_("Handling %d %s%s: %s") % (len_match_list, + self.log_info(_("Handling %d %s%s: %s") % (len_match_list, type, "" if len_match_list == 1 else "s", match_list.replace('|', ', '))) pattern = self.regexp[type][1] % match_list.replace('.', '\.') - dict = self.core.pluginManager.plugins[type][plugin] + dict = self.pyload.pluginManager.plugins[type][plugin] dict['pattern'] = pattern dict['re'] = re.compile(pattern) - self.logDebug("Loaded %s pattern: %s" % (type, pattern)) + self.log_debug("Loaded %s pattern: %s" % (type, pattern)) def _unload(self, type, plugin): - dict = self.core.pluginManager.plugins[type][plugin] + dict = self.pyload.pluginManager.plugins[type][plugin] dict['pattern'] = r'^unmatchable$' dict['re'] = re.compile(dict['pattern']) - def unload(self): - # self.unloadHoster("BasePlugin") + def deactivate(self): + # self.unload_hoster("BasePlugin") for type, plugin in (("hoster", "XFileSharingPro"), ("crypter", "XFileSharingProFolder")): self._unload(type, plugin) - def unloadHoster(self, hoster): - hdict = self.core.pluginManager.hosterPlugins[hoster] + def unload_hoster(self, hoster): + hdict = self.pyload.pluginManager.hosterPlugins[hoster] if "new_name" in hdict and hdict['new_name'] == "XFileSharingPro": if "module" in hdict: hdict.pop('module', None) @@ -123,10 +125,10 @@ class XFileSharingPro(Hook): return False - # def downloadFailed(self, pyfile): + # def download_failed(self, pyfile): # if pyfile.pluginname == "BasePlugin" \ # and pyfile.hasStatus("failed") \ - # and not self.getConfig('use_hoster_list') \ - # and self.unloadHoster("BasePlugin"): - # self.logDebug("Unloaded XFileSharingPro from BasePlugin") + # and not self.get_config('use_hoster_list') \ + # and self.unload_hoster("BasePlugin"): + # self.log_debug("Unloaded XFileSharingPro from BasePlugin") # pyfile.setStatus("queued") diff --git a/module/plugins/hooks/XMPPInterface.py b/module/plugins/hooks/XMPPInterface.py index b61428392..50dd40774 100644 --- a/module/plugins/hooks/XMPPInterface.py +++ b/module/plugins/hooks/XMPPInterface.py @@ -12,15 +12,16 @@ from module.plugins.hooks.IRCInterface import IRCInterface class XMPPInterface(IRCInterface, JabberClient): __name__ = "XMPPInterface" __type__ = "hook" - __version__ = "0.11" + __version__ = "0.12" + __status__ = "testing" - __config__ = [("jid", "str", "Jabber ID", "user@exmaple-jabber-server.org"), - ("pw", "str", "Password", ""), - ("tls", "bool", "Use TLS", False), - ("owners", "str", "List of JIDs accepting commands from", "me@icq-gateway.org;some@msn-gateway.org"), - ("info_file", "bool", "Inform about every file finished", False), - ("info_pack", "bool", "Inform about every package finished", True), - ("captcha", "bool", "Send captcha requests", True)] + __config__ = [("jid" , "str" , "Jabber ID" , "user@exmaple-jabber-server.org" ), + ("pw" , "str" , "Password" , "" ), + ("tls" , "bool", "Use TLS" , False ), + ("owners" , "str" , "List of JIDs accepting commands from", "me@icq-gateway.org;some@msn-gateway.org"), + ("info_file", "bool", "Inform about every file finished" , False ), + ("info_pack", "bool", "Inform about every package finished" , True ), + ("captcha" , "bool", "Send captcha requests" , True )] __description__ = """Connect to jabber and let owner perform different tasks""" __license__ = "GPLv3" @@ -33,22 +34,22 @@ class XMPPInterface(IRCInterface, JabberClient): def __init__(self, core, manager): IRCInterface.__init__(self, core, manager) - self.jid = JID(self.getConfig('jid')) - password = self.getConfig('pw') + self.jid = JID(self.get_config('jid')) + password = self.get_config('pw') - # if bare JID is provided add a resource -- it is required + #: If bare JID is provided add a resource -- it is required if not self.jid.resource: self.jid = JID(self.jid.node, self.jid.domain, "pyLoad") - if self.getConfig('tls'): + if self.get_config('tls'): tls_settings = streamtls.TLSSettings(require=True, verify_peer=False) auth = ("sasl:PLAIN", "sasl:DIGEST-MD5") else: tls_settings = None auth = ("sasl:DIGEST-MD5", "digest") - # setup client with provided connection information - # and identity data + #: Setup client with provided connection information + #: And identity data JabberClient.__init__(self, self.jid, password, disco_name="pyLoad XMPP Client", disco_type="bot", tls_settings=tls_settings, auth_methods=auth) @@ -59,75 +60,81 @@ class XMPPInterface(IRCInterface, JabberClient): ] - def coreReady(self): + def activate(self): self.new_package = {} self.start() - def packageFinished(self, pypack): + def package_finished(self, pypack): try: - if self.getConfig('info_pack'): + if self.get_config('info_pack'): self.announce(_("Package finished: %s") % pypack.name) except Exception: pass - def downloadFinished(self, pyfile): + def download_finished(self, pyfile): try: - if self.getConfig('info_file'): + if self.get_config('info_file'): self.announce( - _("Download finished: %(name)s @ %(plugin)s") % {"name": pyfile.name, "plugin": pyfile.pluginname}) + _("Download finished: %(name)s @ %(plugin)s") % {'name': pyfile.name, 'plugin': pyfile.pluginname}) except Exception: pass def run(self): - # connect to IRC etc. + #: Connect to IRC etc. self.connect() try: self.loop() except Exception, ex: - self.logError(ex) + self.log_error(ex) def stream_state_changed(self, state, arg): - """This one is called when the state of stream connecting the component + """ + This one is called when the state of stream connecting the component to a server changes. This will usually be used to let the user - know what is going on.""" - self.logDebug("*** State changed: %s %r ***" % (state, arg)) + know what is going on. + """ + self.log_debug("*** State changed: %s %r ***" % (state, arg)) def disconnected(self): - self.logDebug("Client was disconnected") + self.log_debug("Client was disconnected") def stream_closed(self, stream): - self.logDebug("Stream was closed", stream) + self.log_debug("Stream was closed", stream) def stream_error(self, err): - self.logDebug("Stream Error", err) + self.log_debug("Stream Error", err) def get_message_handlers(self): - """Return list of (message_type, message_handler) tuples. + """ + Return list of (message_type, message_handler) tuples. The handlers returned will be called when matching message is received - in a client session.""" + in a client session. + """ return [("normal", self.message)] def message(self, stanza): - """Message handler for the component.""" + """ + Message handler for the component. + """ subject = stanza.get_subject() body = stanza.get_body() t = stanza.get_type() - self.logDebug("Message from %s received." % unicode(stanza.get_from())) - self.logDebug("Body: %s Subject: %s Type: %s" % (body, subject, t)) + self.log_debug("Message from %s received." % stanza.get_from()) + self.log_debug("Body: %s Subject: %s Type: %s" % (body, subject, t)) if t == "headline": - # 'headline' messages should never be replied to + #: 'headline' messages should never be replied to return True if subject: subject = u"Re: " + subject @@ -135,11 +142,11 @@ class XMPPInterface(IRCInterface, JabberClient): to_jid = stanza.get_from() from_jid = stanza.get_to() - #j = JID() + # j = JID() to_name = to_jid.as_utf8() from_name = from_jid.as_utf8() - names = self.getConfig('owners').split(";") + names = self.get_config('owners').split(";") if to_name in names or to_jid.node + "@" + to_jid.domain in names: messages = [] @@ -168,7 +175,7 @@ class XMPPInterface(IRCInterface, JabberClient): messages.append(m) except Exception, e: - self.logError(e) + self.log_error(e) return messages @@ -181,9 +188,11 @@ class XMPPInterface(IRCInterface, JabberClient): def announce(self, message): - """ send message to all owners""" - for user in self.getConfig('owners').split(";"): - self.logDebug("Send message to", user) + """ + Send message to all owners + """ + for user in self.get_config('owners').split(";"): + self.log_debug("Send message to", user) to_jid = JID(user) @@ -200,51 +209,62 @@ class XMPPInterface(IRCInterface, JabberClient): stream.send(m) - def beforeReconnecting(self, ip): + def before_reconnect(self, ip): self.disconnect() - def afterReconnecting(self, ip): + def after_reconnect(self, ip): self.connect() class VersionHandler(object): - """Provides handler for a version query. + """ + Provides handler for a version query. This class will answer version query and announce 'jabber:iq:version' namespace - in the client's disco#info results.""" - + in the client's disco#info results. + """ implements(IIqHandlersProvider, IFeaturesProvider) def __init__(self, client): - """Just remember who created this.""" + """ + Just remember who created this. + """ self.client = client def get_features(self): - """Return namespace which should the client include in its reply to a - disco#info query.""" + """ + Return namespace which should the client include in its reply to a + disco#info query. + """ return ["jabber:iq:version"] def get_iq_get_handlers(self): - """Return list of tuples (element_name, namespace, handler) describing - handlers of <iq type='get'/> stanzas""" + """ + Return list of tuples (element_name, namespace, handler) describing + handlers of <iq type='get'/> stanzas + """ return [("query", "jabber:iq:version", self.get_version)] def get_iq_set_handlers(self): - """Return empty list, as this class provides no <iq type='set'/> stanza handler.""" + """ + Return empty list, as this class provides no <iq type='set'/> stanza handler. + """ return [] def get_version(self, iq): - """Handler for jabber:iq:version queries. + """ + Handler for jabber:iq:version queries. jabber:iq:version queries are not supported directly by PyXMPP, so the XML node is accessed directly through the libxml2 API. This should be - used very carefully!""" + used very carefully! + """ iq = iq.make_result_response() q = iq.new_query("jabber:iq:version") q.newTextChild(q.ns(), "name", "Echo component") diff --git a/module/plugins/hooks/ZeveraComHook.py b/module/plugins/hooks/ZeveraComHook.py index 21c1741d2..395c67802 100644 --- a/module/plugins/hooks/ZeveraComHook.py +++ b/module/plugins/hooks/ZeveraComHook.py @@ -6,13 +6,13 @@ from module.plugins.internal.MultiHook import MultiHook class ZeveraComHook(MultiHook): __name__ = "ZeveraComHook" __type__ = "hook" - __version__ = "0.05" + __version__ = "0.06" + __status__ = "testing" - __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), - ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), - ("revertfailed" , "bool" , "Revert to standard download if fails", True ), - ("reload" , "bool" , "Reload plugin list" , True ), - ("reloadinterval", "int" , "Reload interval in hours" , 12 )] + __config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)", "" ), + ("reload" , "bool" , "Reload plugin list" , True ), + ("reloadinterval", "int" , "Reload interval in hours" , 12 )] __description__ = """Zevera.com hook plugin""" __license__ = "GPLv3" @@ -20,6 +20,6 @@ class ZeveraComHook(MultiHook): ("Walter Purcaro", "vuolter@gmail.com" )] - def getHosters(self): + def get_hosters(self): html = self.account.api_response(pyreq.getHTTPRequest(timeout=120), cmd="gethosters") return [x.strip() for x in html.split(",")] |