From 405aa7a9953481a39a4f08f3677fbe9e1523f997 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 3 Oct 2010 20:53:22 +0200 Subject: time settings for accounts --- module/AccountManager.py | 15 +++++------- module/FileDatabase.py | 5 ++-- module/plugins/Account.py | 29 +++++++++++++++++------ module/plugins/accounts/HotfileCom.py | 3 +-- module/plugins/accounts/UploadedTo.py | 2 +- module/plugins/hoster/HotfileCom.py | 3 ++- module/web/pyload/views.py | 37 ++++++++++++++++++++++-------- module/web/templates/default/settings.html | 21 ++++++++++------- 8 files changed, 75 insertions(+), 40 deletions(-) (limited to 'module') diff --git a/module/AccountManager.py b/module/AccountManager.py index 7ef986600..5dedacf3c 100644 --- a/module/AccountManager.py +++ b/module/AccountManager.py @@ -103,14 +103,11 @@ class AccountManager(): elif line.startswith("@"): option = line[1:].split() - self.accounts[plugin][name]["options"].append(tuple(option)) + self.accounts[plugin][name]["options"][option[0]] = [option[1]] if len(option) < 3 else option[1:] elif ":" in line: - name, sep,pw = line.partition(":") - self.accounts[plugin][name] = {"password": pw, "options": [], "valid": True} - - - + name, sep, pw = line.partition(":") + self.accounts[plugin][name] = {"password": pw, "options": {}, "valid": True} #---------------------------------------------------------------------- def saveAccounts(self): """save all account information""" @@ -124,8 +121,8 @@ class AccountManager(): for name,data in accounts.iteritems(): f.write("\n\t%s:%s\n" % (name,data["password"]) ) - for option in data["options"]: - f.write("\t@%s\n" % " ".join(option) ) + for option, values in data["options"].iteritems(): + f.write("\t@%s %s\n" % (option, " ".join(values))) f.close() @@ -137,7 +134,7 @@ class AccountManager(): self.accounts[name] = {} #---------------------------------------------------------------------- - def updateAccount(self, plugin , user, password, options): + def updateAccount(self, plugin , user, password=None, options={}): """add or update account""" if self.accounts.has_key(plugin): p = self.getAccountPlugin(plugin) diff --git a/module/FileDatabase.py b/module/FileDatabase.py index 793a4a69e..6e6537f38 100644 --- a/module/FileDatabase.py +++ b/module/FileDatabase.py @@ -62,13 +62,12 @@ def formatSize(size): size = int(size) steps = 0 sizes = ["B", "KB", "MB", "GB", "TB"] - + while size > 1000: size /= 1024.0 steps += 1 - - return "%.2f %s" % (size, sizes[steps]) + return "%.2f %s" % (size, sizes[steps]) ######################################################################## class FileHandler: diff --git a/module/plugins/Account.py b/module/plugins/Account.py index 16f2a7b92..8c400f6e5 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -60,10 +60,12 @@ class Account(): for user, data in self.accounts.iteritems(): self._login(user, data) - def updateAccounts(self, user, password, options): + def updateAccounts(self, user, password=None, options={}): if self.accounts.has_key(user): - self.accounts[user]["password"] = password - self.accounts[user]["options"] = options + if password: + self.accounts[user]["password"] = password + if options: + self.accounts[user]["options"].update(options) self.accounts[user]["valid"] = True else: self.accounts[user] = {"password" : password, "options": options, "valid": True} @@ -109,12 +111,18 @@ class Account(): def getAccountRequest(self, user=None): if not user: user, data = self.selectAccount() + if not user: + return None + req = self.core.requestFactory.getRequest(self.__name__, user) return req def getAccountCookies(self, user=None): if not user: user, data = self.selectAccount() + if not user: + return None + cj = self.core.requestFactory.getCookieJar(self.__name__, user) return cj @@ -126,13 +134,20 @@ class Account(): usable = [] for user,data in self.accounts.iteritems(): if not data["valid"]: continue - for option, value in data["options"]: - pass - #@TODO comparate time option + + if data["options"].has_key("time"): + time = data["options"]["time"][0] + try: + start, end = time.split("-") + if not self.core.compare_time(start.split(":"), end.split(":")): + continue + except: + self.core.log.error(_("Your Time %s has wrong format, use: 1:22-3:44") % time) + usable.append((user, data)) - if not usable: return None + if not usable: return None, None return choice(usable) def canUse(self): diff --git a/module/plugins/accounts/HotfileCom.py b/module/plugins/accounts/HotfileCom.py index 83551949d..f623e56f1 100644 --- a/module/plugins/accounts/HotfileCom.py +++ b/module/plugins/accounts/HotfileCom.py @@ -19,7 +19,6 @@ from module.plugins.Account import Account from time import strptime, mktime -from urllib import unquote import hashlib class HotfileCom(Account): @@ -69,7 +68,7 @@ class HotfileCom(Account): post.update({"action": method}) post.update({"username":user, "passwordmd5dig":pwhash, "digest":digest}) - return unquote(req.load("http://api.hotfile.com/", post=post)).strip() + return req.load("http://api.hotfile.com/", post=post) def login(self, user, data): req = self.getAccountRequest(user) diff --git a/module/plugins/accounts/UploadedTo.py b/module/plugins/accounts/UploadedTo.py index 9b51f5aad..4c45fb6fc 100644 --- a/module/plugins/accounts/UploadedTo.py +++ b/module/plugins/accounts/UploadedTo.py @@ -41,7 +41,7 @@ class UploadedTo(Account): return tmp def login(self, user, data): - req = self.getAccountRequest() + req = self.getAccountRequest(user) page = req.load("http://uploaded.to/login", post={ "email" : user, "password" : data["password"]}, cookies=True) if "Login failed!" in page: self.wrongPassword() diff --git a/module/plugins/hoster/HotfileCom.py b/module/plugins/hoster/HotfileCom.py index 3b88efe1f..228f31649 100644 --- a/module/plugins/hoster/HotfileCom.py +++ b/module/plugins/hoster/HotfileCom.py @@ -56,7 +56,7 @@ class HotfileCom(Hoster): elif self.account and login: return self.account.apiCall(method, post, self.user) post.update({"action": method}) - return unquote(self.load("http://api.hotfile.com/", post=post)).strip() + return self.load("http://api.hotfile.com/", post=post) def process(self, pyfile): self.wantReconnect = False @@ -81,6 +81,7 @@ class HotfileCom(Hoster): self.freeDownload() else: dl = self.account.apiCall("getdirectdownloadlink", {"link":self.pyfile.url}, self.user) + dl = unquote(dl).strip() self.download(dl) def downloadHTML(self): diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py index 678884790..523fe60ea 100644 --- a/module/web/pyload/views.py +++ b/module/web/pyload/views.py @@ -24,6 +24,18 @@ from django.utils.translation import ugettext as _ def get_sort_key(item): return item[1]["order"] +def formatSize(size): + """formats size of bytes""" + size = int(size) + steps = 0 + sizes = ["B", "KB", "MB", "GB", "TB"] + + while size > 1000: + size /= 1024.0 + steps += 1 + + return "%.2f %s" % (size, sizes[steps]) + def check_server(function): def _dec(view_func): def _view(request, * args, ** kwargs): @@ -303,23 +315,25 @@ def config(request): elif sec == "Accounts": if ";" in okey: action, name = okey.split(";") - if action == "delete": settings.PYLOAD.remove_account(skey, name) - elif action == "password": - - for acc in accs[skey]: - if acc["login"] == name and value.strip(): - settings.PYLOAD.update_account(skey, name, value) - elif okey == "newacc" and value: + if okey == "newacc" and value: # add account pw = request.POST.get("Accounts|%s|newpw" % skey) settings.PYLOAD.update_account(skey, value, pw) - - + + for pluginname, accdata in accs.iteritems(): + for data in accdata: + newpw = request.POST.get("Accounts|%s|password;%s" % (pluginname, data["login"]), "").strip() + time = request.POST.get("Accounts|%s|time;%s" % (pluginname, data["login"]), "").strip() + + if newpw or (time and (not data["options"].has_key("time") or time != data["options"]["time"][0])): + settings.PYLOAD.update_account(pluginname, data["login"], newpw, {"time": [time]}) + + if errors: messages.append(_("Error occured when setting the following options:")) messages.append("") @@ -334,6 +348,8 @@ def config(request): data["trafficleft"] = _("unlimited") elif not data["trafficleft"]: data["trafficleft"] = _("not available") + else: + data["trafficleft"] = formatSize(data["trafficleft"]) if data["validuntil"] == -1: data["validuntil"] = _("unlimited") @@ -342,6 +358,9 @@ def config(request): else: t = localtime(data["validuntil"]) data["validuntil"] = strftime("%d-%m-%Y",t) + + if data["options"].has_key("time"): + data["time"] = data["options"]["time"][0] return render_to_response(join(settings.TEMPLATE, 'settings.html'), RequestContext(request, {'conf': {'Plugin':plugin, 'General':conf, 'Accounts': accs}, 'errors': messages}, [status_proc])) diff --git a/module/web/templates/default/settings.html b/module/web/templates/default/settings.html index f23027210..09fe2e8b1 100644 --- a/module/web/templates/default/settings.html +++ b/module/web/templates/default/settings.html @@ -133,33 +133,38 @@ - + {% trans "Status:" %} - {% if account.valid %} + {% trans "valid" %} {% else %} + {% trans "not valid" %} {% endif %} -  | + {% trans "Valid until:" %} {{ account.validuntil }} -  | + {% trans "Traffic left:" %} {{ account.trafficleft }} -  | + + + {% trans "Time:" %} + + {% trans "Delete? " %} - + @@ -170,14 +175,14 @@ - + - + -- cgit v1.2.3