summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/Account.py16
-rw-r--r--module/plugins/Plugin.py28
2 files changed, 31 insertions, 13 deletions
diff --git a/module/plugins/Account.py b/module/plugins/Account.py
index e8ca26749..2d4642411 100644
--- a/module/plugins/Account.py
+++ b/module/plugins/Account.py
@@ -34,12 +34,16 @@ class Account():
__description__ = """Account Plugin"""
__author_name__ = ("mkaay")
__author_mail__ = ("mkaay@mkaay.de")
+
+ # after that time [in minutes] pyload will relogin the account
+ login_timeout = 600
def __init__(self, manager, accounts):
self.manager = manager
self.core = manager.core
self.accounts = {}
self.infos = {} # cache for account information
+ self.timestamps = {}
self.setAccounts(accounts)
def login(self, user, data, req):
@@ -49,6 +53,7 @@ class Account():
req = self.getAccountRequest(user)
try:
self.login(user, data, req)
+ self.timestamps[user] = time()
except WrongPassword:
self.core.log.warning(_("Could not login with %(plugin)s account %(user)s | %(msg)s") % {"plugin": self.__name__, "user": user, "msg": _("Wrong Password")})
data["valid"] = False
@@ -205,3 +210,14 @@ class Account():
self.core.log.warning(_("%(plugin)s Account %(user)s is expired, checking again in 1h") % {"plugin" : self.__name__, "user": user})
self.infos[user].update({"validuntil": time() - 1})
self.core.scheduler.addJob(60*60, self.getAccountInfo, [user])
+
+
+ def checkLogin(self, user):
+ """ checks if user is still logged in """
+ if self.timestamps.has_key(user):
+ if self.timestamps[user] + self.login_timeout * 60 < time():
+ self.core.log.debug("Reached login timeout for %s:%s" % (self.__name__, user))
+ self.relogin(user)
+ return False
+
+ return True \ No newline at end of file
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index e23e9558f..1c5061432 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -28,7 +28,7 @@ from os import makedirs
from os import chmod
from os import stat
from os import name as os_name
-from os.path import exists, join, dirname
+from os.path import exists, join
if os.name != "nt":
from os import chown
@@ -46,25 +46,22 @@ def chunks(iterable, size):
yield item
item = list(islice(it, size))
-def dec(func):
- def new(*args):
- if args[0].pyfile.abort:
- raise Abort
- return func(*args)
- return new
class Abort(Exception):
""" raised when aborted """
class Fail(Exception):
""" raised when failed """
-
+
class Reconnect(Exception):
""" raised when reconnected """
class Retry(Exception):
""" raised when start again from beginning """
+class SkipDownload(Exception):
+ """ raised when download should be skipped """
+
class Plugin(object):
__name__ = "Plugin"
__version__ = "0.4"
@@ -139,7 +136,9 @@ class Plugin(object):
""" handles important things to do before starting """
self.thread = thread
- if not self.account:
+ if self.account:
+ self.account.checkLogin()
+ else:
self.req.clearCookies()
self.setup()
@@ -177,10 +176,6 @@ class Plugin(object):
""" sets a config value """
self.config.setPlugin(self.__name__, option, value)
- def removeConf(self, option):
- """ removes a config value """
- raise NotImplementedError
-
def getConf(self, option):
""" gets a config value """
return self.config.getPlugin(self.__name__, option)
@@ -353,6 +348,8 @@ class Plugin(object):
def download(self, url, get={}, post={}, ref=True, cookies=True, disposition=False):
""" downloads the url content to disk """
+ self.checkForSameFiles()
+
self.pyfile.setStatus("downloading")
download_folder = self.config['general']['download_folder']
@@ -441,6 +438,11 @@ class Plugin(object):
def getPassword(self):
return self.pyfile.package().password
+
+ def checkForSameFiles(self):
+ """ checks if same file was/is downloaded within same package and raise exception """
+ pass
+
def clean(self):
""" clean everything and remove references """
if hasattr(self, "pyfile"):