diff options
-rw-r--r-- | module/AccountManager.py | 16 | ||||
-rw-r--r-- | module/PluginThread.py | 1 | ||||
-rw-r--r-- | module/plugins/accounts/RapidshareCom.py | 51 | ||||
-rw-r--r-- | module/plugins/accounts/UploadedTo.py | 35 | ||||
-rw-r--r-- | module/web/pyload/views.py | 25 | ||||
-rw-r--r-- | module/web/templates/default/settings.html | 55 | ||||
-rwxr-xr-x | pyLoadCore.py | 12 |
7 files changed, 139 insertions, 56 deletions
diff --git a/module/AccountManager.py b/module/AccountManager.py index 0122b0223..fc122e760 100644 --- a/module/AccountManager.py +++ b/module/AccountManager.py @@ -51,7 +51,14 @@ class AccountManager(): else: return None - + def getAccountPlugins(self): + """ get all account instances""" + + plugins = [] + for plugin in self.accounts.keys(): + plugins.append(self.getAccountPlugin(plugin)) + + return plugins #---------------------------------------------------------------------- def loadAccounts(self): """loads all accounts available""" @@ -107,7 +114,7 @@ class AccountManager(): f = open("accounts.conf", "wb") f.write("version: " + str(ACC_VERSION) + "\n") - + for plugin, accounts in self.accounts.iteritems(): f.write("\n") f.write(plugin+":\n") @@ -145,11 +152,12 @@ class AccountManager(): #---------------------------------------------------------------------- def removeAccount(self, plugin, user): """remove account""" + if self.accounts.has_key(plugin): p = self.getAccountPlugin(plugin) p.removeAccount(user) - if self.accounts.has_key(user): - del self.accounts[user] + if self.accounts[plugin].has_key(user): + del self.accounts[plugin][user] self.saveAccounts() diff --git a/module/PluginThread.py b/module/PluginThread.py index c666e7875..f727aa7f0 100644 --- a/module/PluginThread.py +++ b/module/PluginThread.py @@ -70,6 +70,7 @@ class DownloadThread(PluginThread): self.m.log.info(_("Download starts: %s" % pyfile.name)) try: + self.m.core.hookManager.downloadStarts(pyfile) pyfile.plugin.preprocessing(self) except NotImplementedError: diff --git a/module/plugins/accounts/RapidshareCom.py b/module/plugins/accounts/RapidshareCom.py index 052470ada..7f5fff84d 100644 --- a/module/plugins/accounts/RapidshareCom.py +++ b/module/plugins/accounts/RapidshareCom.py @@ -28,31 +28,34 @@ class RapidshareCom(Account): __author_mail__ = ("mkaay@mkaay.de") def getAccountInfo(self, user): - data = None - for account in self.accounts.items(): - if account[0] == user: - data = account[1] - if not data: - return - req = self.core.requestFactory.getRequest(self.__name__, user) - api_url_base = "http://api.rapidshare.com/cgi-bin/rsapi.cgi" - api_param_prem = {"sub": "getaccountdetails_v1", "type": "prem", "login": user, "password": data["password"], "withcookie": 1} - src = req.load(api_url_base, cookies=False, get=api_param_prem) - if src.startswith("ERROR"): - return - fields = src.split("\n") - info = {} - for t in fields: - if not t.strip(): - continue - k, v = t.split("=") - info[k] = v + try: + data = None + for account in self.accounts.items(): + if account[0] == user: + data = account[1] + if not data: + return + req = self.core.requestFactory.getRequest(self.__name__, user) + api_url_base = "http://api.rapidshare.com/cgi-bin/rsapi.cgi" + api_param_prem = {"sub": "getaccountdetails_v1", "type": "prem", "login": user, "password": data["password"], "withcookie": 1} + src = req.load(api_url_base, cookies=False, get=api_param_prem) + if src.startswith("ERROR"): + return + fields = src.split("\n") + info = {} + for t in fields: + if not t.strip(): + continue + k, v = t.split("=") + info[k] = v + + out = Account.getAccountInfo(self, user) + tmp = {"validuntil":None, "login":str(info["accountid"]), "trafficleft":int(info["tskb"]), "type":self.__name__} + out.update(tmp) - out = Account.getAccountInfo(self, user) - tmp = {"validuntil":None, "login":str(info["accountid"]), "trafficleft":int(info["tskb"]), "type":self.__name__} - out.update(tmp) - - return out + return out + except: + return Account.getAccountInfo(self, user) def login(self, user, data): req = self.core.requestFactory.getRequest(self.__name__, user) diff --git a/module/plugins/accounts/UploadedTo.py b/module/plugins/accounts/UploadedTo.py index d2aa22b22..926f91255 100644 --- a/module/plugins/accounts/UploadedTo.py +++ b/module/plugins/accounts/UploadedTo.py @@ -30,22 +30,25 @@ class UploadedTo(Account): __author_mail__ = ("mkaay@mkaay.de") def getAccountInfo(self, user): - data = None - for account in self.accounts.items(): - if account[0] == user: - data = account[1] - if not data: - return - req = self.core.requestFactory.getRequest(self.__name__, user) - html = req.load("http://uploaded.to/", cookies=True) - raw_traffic = re.search(r"Traffic left: </span><span class=.*?>(.*?)</span>", html).group(1) - raw_valid = re.search(r"Valid until: </span> <span class=.*?>(.*?)</span>", html).group(1) - traffic = int(self.parseTraffic(raw_traffic)) - validuntil = int(mktime(strptime(raw_valid.strip(), "%d-%m-%Y %H:%M"))) - out = Account.getAccountInfo(self, user) - tmp = {"login":user, "validuntil":validuntil, "trafficleft":traffic, "type":self.__name__} - out.update(tmp) - return out + try: + data = None + for account in self.accounts.items(): + if account[0] == user: + data = account[1] + if not data: + return + req = self.core.requestFactory.getRequest(self.__name__, user) + html = req.load("http://uploaded.to/", cookies=True) + raw_traffic = re.search(r"Traffic left: </span><span class=.*?>(.*?)</span>", html).group(1) + raw_valid = re.search(r"Valid until: </span> <span class=.*?>(.*?)</span>", html).group(1) + traffic = int(self.parseTraffic(raw_traffic)) + validuntil = int(mktime(strptime(raw_valid.strip(), "%d-%m-%Y %H:%M"))) + out = Account.getAccountInfo(self, user) + tmp = {"login":user, "validuntil":validuntil, "trafficleft":traffic, "type":self.__name__} + out.update(tmp) + return out + except: + return Account.getAccountInfo(self, user) def login(self, user, data): req = self.core.requestFactory.getRequest(self.__name__, user) diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py index b8cbacf30..880ec7843 100644 --- a/module/web/pyload/views.py +++ b/module/web/pyload/views.py @@ -300,6 +300,7 @@ def collector(request): def config(request): conf = settings.PYLOAD.get_config() plugin = settings.PYLOAD.get_plugin_config() + accs = settings.PYLOAD.get_accounts() messages = [] for section in chain(conf.itervalues(), plugin.itervalues()): @@ -343,6 +344,26 @@ def config(request): continue else: continue + + 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 acc["password"] != value: + settings.PYLOAD.update_account(skey, name, value) + + elif okey == "newacc" and value: + # add account + + pw = request.POST.get("Accounts|%s|newpw" % skey) + + settings.PYLOAD.update_account(skey, value, pw) + if errors: messages.append(_("Error occured when setting the following options:")) @@ -351,4 +372,6 @@ def config(request): else: messages.append(_("All options were set correctly.")) - return render_to_response(join(settings.TEMPLATE, 'settings.html'), RequestContext(request, {'conf': {'Plugin':plugin, 'General':conf}, 'errors': messages}, [status_proc])) + accs = settings.PYLOAD.get_accounts() + + 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 208549813..e9a40ff3a 100644 --- a/module/web/templates/default/settings.html +++ b/module/web/templates/default/settings.html @@ -77,17 +77,23 @@ <ul id="tabs" class="tabs"> {% for configname, config in conf.iteritems %} <span id="g_{{configname}}"> - {% for skey, section in config.iteritems %} - <li><a href="#{{configname}}{{skey}}">{{section.desc}}</a></li> - {% endfor %} + {% ifnotequal configname "Accounts" %} + {% for skey, section in config.iteritems %} + <li><a href="#{{configname}}{{skey}}">{{section.desc}}</a></li> + {% endfor %} + {% else %} + {% for skey, section in config.iteritems %} + <li><a href="#{{configname}}{{skey}}">{{skey}}</a></li> + {% endfor %} + {% endifnotequal %} </span> {% endfor %} </ul> </div> <form id="horizontalForm" action="" method="POST"> {% for configname, config in conf.iteritems %} + {% ifnotequal configname "Accounts" %} {% for skey, section in config.iteritems %} - <div class="tabContent" id="{{configname}}{{skey}}"> <table class="settable"> {% for okey, option in section.items %} @@ -118,6 +124,47 @@ </table> </div> {% endfor %} + {% else %} + <!-- Accounts --> + {% for plugin, accounts in config.iteritems %} + <div class="tabContent" id="{{configname}}{{plugin}}"> + <table class="settable"> + {% for account in accounts %} + <tr> + <td><label for="{{configname}}|{{plugin}}|password;{{account.login}}" style="color:#424242;">{{account.login}}:</label></td> + <td> + <input id="{{plugin}}|delete;{{account.login}}" name="{{configname}}|{{plugin}}|password;{{account.login}}" type="password" value="{{account.password}}"/> + </td> + <td> + {% trans "Delete? " %} + <input id="{{plugin}}|delete;{{account.login}}" name="{{configname}}|{{plugin}}|delete;{{account.login}}" type="checkbox" value="True"/> + + </td> + </tr> + + {% endfor %} + <tr><td> </td></tr> + + <tr> + <td><label for="{{configname}}|{{plugin}}|{{account.login}}" style="color:#424242;">{% trans "New account:" %}</label></td> + + <td> + <input id="{{plugin}}|newacc" name="{{configname}}|{{plugin}}|newacc" type="text"/> + </td> + </tr> + <tr> + <td><label for="{{configname}}|{{plugin}}|{{account.name}}" style="color:#424242;">{% trans "New password:" %}</label></td> + + <td> + <input id="{{config}}|{{plugin}}" name="{{configname}}|{{plugin}}|newpw" type="password"/> + </td> + </tr> + + </table> + </div> + {% endfor %} + + {% endifnotequal %} {% endfor %} {% if conf %} <input class="submit" type="submit" value="{% trans "Submit" %}" /> diff --git a/pyLoadCore.py b/pyLoadCore.py index db46571d5..0c28b4a1b 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -611,20 +611,18 @@ class ServerMethods(): return self.core.pullManager.getEvents(uuid) def get_accounts(self): - plugins = self.core.pluginManager.getAccountPlugins() - data = [] + plugins = self.core.accountManager.getAccountPlugins() + data = {} for p in plugins: - data.extend(p.getAllAccounts()) + data[p.__name__] = p.getAllAccounts() return data def update_account(self, plugin, account, password, options=[]): """ create and update account """ - plugins = self.core.pluginManager.getAccountPlugins() - self.core.pluginManager.updateAccount(plugin, account, password, options) + self.core.accountManager.updateAccount(plugin, account, password, options) def remove_account(self, plugin, account): - plugins = self.core.pluginManager.getAccountPlugins() - self.core.pluginManager.removeAccount(plugin, account) + self.core.accountManager.removeAccount(plugin, account) def set_priority(self, id, priority): p = self.core.files.getPackage(id) |