diff options
Diffstat (limited to 'pyload/plugin/Plugin.py')
-rw-r--r-- | pyload/plugin/Plugin.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/pyload/plugin/Plugin.py b/pyload/plugin/Plugin.py index c14155751..cedab3b4f 100644 --- a/pyload/plugin/Plugin.py +++ b/pyload/plugin/Plugin.py @@ -61,38 +61,49 @@ class Base(object): #: Core instance self.core = core + def _log(self, type, args): msg = " | ".join([encode(str(a)).strip() for a in args if a]) logger = getattr(self.core.log, type) logger("%s: %s" % (self.__class__.__name__, msg or _("%s MARK" % type.upper()))) + def logDebug(self, *args): if self.core.debug: return self._log("debug", args) + def logInfo(self, *args): return self._log("info", args) + def logWarning(self, *args): return self._log("warning", args) + def logError(self, *args): return self._log("error", args) + def logCritical(self, *args): return self._log("critical", args) + def grtPluginType(self): return getattr(self, "_%s__type" % self.__class__.__name__) + def getPluginConfSection(self): return "%s_%s" % (self.__class__.__name__, getattr(self, "_%s__type" % self.__class__.__name__)) #: Deprecated method + + def setConf(self, option, value): """ see `setConfig` """ self.setConfig(option, value) + def setConfig(self, option, value): """ Set config value for current plugin @@ -103,10 +114,13 @@ class Base(object): self.core.config.setPlugin(self.getPluginConfSection(), option, value) #: Deprecated method + + def getConf(self, option): """ see `getConfig` """ return self.core.config.getPlugin(self.getPluginConfSection(), option) + def getConfig(self, option): """ Returns config value for current plugin @@ -115,24 +129,29 @@ class Base(object): """ return self.core.config.getPlugin(self.getPluginConfSection(), option) + def setStorage(self, key, value): """ Saves a value persistently to the database """ self.core.db.setStorage(self.getPluginConfSection(), key, value) + def store(self, key, value): """ same as `setStorage` """ self.core.db.setStorage(self.getPluginConfSection(), key, value) + def getStorage(self, key=None, default=None): """ Retrieves saved value or dict of all saved entries if key is None """ if key: return self.core.db.getStorage(self.getPluginConfSection(), key) or default return self.core.db.getStorage(self.getPluginConfSection(), key) + def retrieve(self, *args, **kwargs): """ same as `getStorage` """ return self.getStorage(*args, **kwargs) + def delStorage(self, key): """ Delete entry in db """ self.core.db.delStorage(self.__class__.__name__, key) @@ -158,6 +177,7 @@ class Plugin(Base): info = {} #: file info dict + def __init__(self, pyfile): Base.__init__(self, pyfile.m.core) @@ -224,22 +244,27 @@ class Plugin(Base): self.init() + def getChunkCount(self): if self.chunkLimit <= 0: return self.core.config['download']['chunks'] return min(self.core.config['download']['chunks'], self.chunkLimit) + def __call__(self): return self.__class__.__name__ + def init(self): """initialize the plugin (in addition to `__init__`)""" pass + def setup(self): """ setup for enviroment and other things, called before downloading (possibly more than one time)""" pass + def preprocessing(self, thread): """ handles important things to do before starting """ self.thread = thread @@ -255,16 +280,19 @@ class Plugin(Base): return self.process(self.pyfile) + def process(self, pyfile): """the 'main' method of every plugin, you **have to** overwrite it""" raise NotImplementedError + def resetAccount(self): """ dont use account and retry download """ self.account = None self.req = self.core.requestFactory.getRequest(self.__class__.__name__) self.retry() + def checksum(self, local_file=None): """ return codes: @@ -278,11 +306,13 @@ class Plugin(Base): return True, 10 + def setReconnect(self, reconnect): reconnect = bool(reconnect) self.logDebug("Set wantReconnect to: %s (previous: %s)" % (reconnect, self.wantReconnect)) self.wantReconnect = reconnect + def setWait(self, seconds, reconnect=None): """Set a specific wait time later used with `wait` @@ -300,6 +330,7 @@ class Plugin(Base): if reconnect is not None: self.setReconnect(reconnect) + def wait(self, seconds=None, reconnect=None): """ waits the time previously set """ @@ -345,16 +376,19 @@ class Plugin(Base): pyfile.status = status + def fail(self, reason): """ fail and give reason """ raise Fail(reason) + def abort(self, reason=""): """ abort and give reason """ if reason: self.pyfile.error = str(reason) raise Abort + def error(self, reason="", type=""): if not reason and not type: type = "unknown" @@ -365,18 +399,21 @@ class Plugin(Base): raise Fail(msg) + def offline(self, reason=""): """ fail and indicate file is offline """ if reason: self.pyfile.error = str(reason) raise Fail("offline") + def tempOffline(self, reason=""): """ fail and indicates file ist temporary offline, the core may take consequences """ if reason: self.pyfile.error = str(reason) raise Fail("temp. offline") + def retry(self, max_tries=5, wait_time=1, reason=""): """Retries and begin again from the beginning @@ -392,16 +429,19 @@ class Plugin(Base): self.retries += 1 raise Retry(reason) + def invalidCaptcha(self): self.logError(_("Invalid captcha")) if self.cTask: self.cTask.invalid() + def correctCaptcha(self): self.logInfo(_("Correct captcha")) if self.cTask: self.cTask.correct() + def decryptCaptcha(self, url, get={}, post={}, cookies=False, forceUser=False, imgtype='jpg', result_type='textual', timeout=290): """ Loads a captcha and decrypts it with ocr, plugin, user input @@ -472,6 +512,7 @@ class Plugin(Base): return result + def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, decode=False, follow_location=True, save_cookies=True): """Load content at url and returns it @@ -539,6 +580,7 @@ class Plugin(Base): return res + def download(self, url, get={}, post={}, ref=True, cookies=True, disposition=False): """Downloads the content at url to download folder @@ -628,6 +670,7 @@ class Plugin(Base): self.lastDownload = filename return self.lastDownload + def checkDownload(self, rules, api_size=0, max_size=50000, delete=True, read_size=0): """ checks the content of the last downloaded file, re match is saved to `lastCheck` @@ -668,12 +711,14 @@ class Plugin(Base): self.lastCheck = m return name + def getPassword(self): """ get the password the user provided in the package""" password = self.pyfile.package().password if not password: return "" return password + def checkForSameFiles(self, starting=False): """ checks if same file was/is downloaded within same package @@ -705,6 +750,7 @@ class Plugin(Base): self.logDebug("File %s not skipped, because it does not exists." % self.pyfile.name) + def clean(self): """ clean everything and remove references """ if hasattr(self, "pyfile"): |