diff options
-rw-r--r-- | module/plugins/Account.py | 82 | ||||
-rw-r--r-- | module/plugins/AccountManager.py | 7 | ||||
-rw-r--r-- | module/plugins/accounts/RehostTo.py | 37 | ||||
-rw-r--r-- | module/plugins/accounts/UploadedTo.py | 2 | ||||
-rw-r--r-- | module/plugins/hooks/RealdebridCom.py | 2 | ||||
-rw-r--r-- | module/plugins/hooks/RehostTo.py | 84 | ||||
-rw-r--r-- | module/plugins/hoster/RealdebridCom.py | 2 | ||||
-rw-r--r-- | module/plugins/hoster/RehostTo.py | 37 | ||||
-rw-r--r-- | module/web/json_app.py | 16 | ||||
-rw-r--r-- | module/web/pyload_app.py | 1 | ||||
-rw-r--r-- | module/web/templates/default/settings.html | 2 | ||||
-rwxr-xr-x | pyLoadCore.py | 17 |
12 files changed, 245 insertions, 44 deletions
diff --git a/module/plugins/Account.py b/module/plugins/Account.py index 2d4642411..c5d7930e9 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -17,7 +17,6 @@ @author: mkaay """ -import re from random import choice from time import time from traceback import print_exc @@ -27,6 +26,7 @@ from module.utils import compare_time, parseFileSize class WrongPassword(Exception): pass + class Account(): __name__ = "Account" __version__ = "0.2" @@ -37,7 +37,10 @@ class Account(): # after that time [in minutes] pyload will relogin the account login_timeout = 600 - + # account data will be reloaded after this time + info_threshold = 600 + + def __init__(self, manager, accounts): self.manager = manager self.core = manager.core @@ -45,6 +48,10 @@ class Account(): self.infos = {} # cache for account information self.timestamps = {} self.setAccounts(accounts) + self.setup() + + def setup(self): + pass def login(self, user, data, req): pass @@ -55,51 +62,67 @@ class Account(): 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")}) + 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 except Exception, e: - self.core.log.warning(_("Could not login with %(plugin)s account %(user)s | %(msg)s") % {"plugin" :self.__name__, "user": user, "msg": e}) + self.core.log.warning( + _("Could not login with %(plugin)s account %(user)s | %(msg)s") % {"plugin": self.__name__, "user": user + , "msg": e}) data["valid"] = False if self.core.debug: print_exc() finally: if req: req.close() - + def relogin(self, user): req = self.getAccountRequest(user) if req: req.cj.clear() req.close() + if self.infos.has_key(user): + del self.infos[user] #delete old information + self._login(user, self.accounts[user]) - + def setAccounts(self, accounts): self.accounts = accounts for user, data in self.accounts.iteritems(): self._login(user, data) self.infos[user] = {} - + def updateAccounts(self, user, password=None, options={}): + """ updates account and return true if anything changed """ + if self.accounts.has_key(user): + self.accounts[user]["valid"] = True #do not remove or accounts will not login if password: self.accounts[user]["password"] = password + self.relogin(user) + return True if options: + before = self.accounts[user]["options"] self.accounts[user]["options"].update(options) - self.accounts[user]["valid"] = True + return self.accounts[user]["options"] != before else: - self.accounts[user] = {"password" : password, "options": options, "valid": True} + self.accounts[user] = {"password": password, "options": options, "valid": True} + self._login(user, self.accounts[user]) + return True - self._login(user, self.accounts[user]) - def removeAccount(self, user): if self.accounts.has_key(user): del self.accounts[user] if self.infos.has_key(user): del self.infos[user] - + if self.timestamps.has_key(user): + del self.timestamps[user] + def getAccountInfo(self, name, force=False): """ return dict with infos, do not overwrite this method! """ data = Account.loadAccountInfo(self, name) + if force or not self.infos.has_key(name): self.core.log.debug("Get %s Account Info for %s" % (self.__name__, name)) req = self.getAccountRequest(name) @@ -114,11 +137,15 @@ class Account(): if req: req.close() self.core.log.debug("Account Info: %s" % str(infos)) + + infos["timestamp"] = time() self.infos[name] = infos + elif self.infos[name].has_key("timestamp") and self.infos[name]["timestamp"] + self.info_threshold * 60 < time(): + self.scheduleRefresh(name) data.update(self.infos[name]) return data - + def isPremium(self, user): info = self.getAccountInfo(user) return info["premium"] @@ -133,12 +160,13 @@ class Account(): "trafficleft": None, # in kb, -1 for unlimited "maxtraffic": None, "premium": True, #useful for free accounts + "timestamp": 0, #time this info was retrieved "type": self.__name__, - } + } def getAllAccounts(self, force=False): return [self.getAccountInfo(user, force) for user, data in self.accounts.iteritems()] - + def getAccountRequest(self, user=None): if not user: user, data = self.selectAccount() @@ -163,7 +191,7 @@ class Account(): def selectAccount(self): """ returns an valid account name and data""" usable = [] - for user,data in self.accounts.iteritems(): + for user, data in self.accounts.iteritems(): if not data["valid"]: continue if data["options"].has_key("time") and data["options"]["time"]: @@ -184,15 +212,14 @@ class Account(): if self.infos[user]["trafficleft"] == 0: continue - usable.append((user, data)) if not usable: return None, None return choice(usable) - + def canUse(self): return False if self.selectAccount() == (None, None) else True - + def parseTraffic(self, string): #returns kbyte return parseFileSize(string) / 1024 @@ -201,16 +228,25 @@ class Account(): def empty(self, user): if self.infos.has_key(user): - self.core.log.warning(_("%(plugin)s Account %(user)s has not enough traffic, checking again in 30min") % {"plugin" : self.__name__, "user": user}) + self.core.log.warning(_("%(plugin)s Account %(user)s has not enough traffic, checking again in 30min") % { + "plugin": self.__name__, "user": user}) + self.infos[user].update({"trafficleft": 0}) - self.core.scheduler.addJob(30*60, self.getAccountInfo, [user]) + self.scheduleRefresh(user, 30 * 60) def expired(self, user): if self.infos.has_key(user): - self.core.log.warning(_("%(plugin)s Account %(user)s is expired, checking again in 1h") % {"plugin" : self.__name__, "user": user}) + 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]) + self.scheduleRefresh(user, 60 * 60) + def scheduleRefresh(self, user, time=0, force=True): + """ add task to refresh account info to sheduler """ + self.core.log.debug("Scheduled Account refresh for %s:%s in %s seconds." % (self.__name__, user, time)) + self.core.scheduler.addJob(time, self.getAccountInfo, [user, force]) def checkLogin(self, user): """ checks if user is still logged in """ diff --git a/module/plugins/AccountManager.py b/module/plugins/AccountManager.py index 7299ff643..e4c858a43 100644 --- a/module/plugins/AccountManager.py +++ b/module/plugins/AccountManager.py @@ -143,12 +143,11 @@ class AccountManager(): """add or update account""" if self.accounts.has_key(plugin): p = self.getAccountPlugin(plugin) - p.updateAccounts(user, password, options) + updated = p.updateAccounts(user, password, options) #since accounts is a ref in plugin self.accounts doesnt need to be updated here self.saveAccounts() - p.getAllAccounts(force=True) - self.core.scheduler.addJob(0, self.core.accountManager.getAccountInfos) + if updated: p.scheduleRefresh(user, force=False) #---------------------------------------------------------------------- def removeAccount(self, plugin, user): @@ -159,8 +158,6 @@ class AccountManager(): p.removeAccount(user) self.saveAccounts() - p.getAllAccounts(force=True) - self.core.scheduler.addJob(0, self.core.accountManager.getAccountInfos) def getAccountInfos(self, force=True, refresh=False): diff --git a/module/plugins/accounts/RehostTo.py b/module/plugins/accounts/RehostTo.py new file mode 100644 index 000000000..e1cb2668f --- /dev/null +++ b/module/plugins/accounts/RehostTo.py @@ -0,0 +1,37 @@ +from module.plugins.Account import Account + + +class RehostTo(Account): + __name__ = "RehostTo" + __version__ = "0.1" + __type__ = "account" + __description__ = """Rehost.to account plugin""" + __author_name__ = ("RaNaN") + __author_mail__ = ("RaNaN@pyload.org") + + + def loadAccountInfo(self, user, req): + + data = self.getAccountData(user) + page = req.load("http://rehost.to/api.php?cmd=login&user=%s&pass=%s" % (user, data["password"])) + data = [x.split("=") for x in page.split(",")] + ses = data[0][1] + long_ses = data[1][1] + + page = req.load("http://rehost.to/api.php?cmd=get_premium_credits&long_ses=%s" % long_ses) + traffic, valid = page.split(",") + + account_info = {"trafficleft": int(traffic) * 1024, + "validuntil": int(valid), + "long_ses": long_ses, + "ses": ses} + + return account_info + + def login(self, user, data, req): + page = req.load("http://rehost.to/api.php?cmd=login&user=%s&pass=%s" % (user, data["password"])) + + if "Login failed." in page: + self.wrongPassword() + + diff --git a/module/plugins/accounts/UploadedTo.py b/module/plugins/accounts/UploadedTo.py index 63092a3cb..5fcc77498 100644 --- a/module/plugins/accounts/UploadedTo.py +++ b/module/plugins/accounts/UploadedTo.py @@ -45,7 +45,7 @@ class UploadedTo(Account): return {"validuntil":validuntil, "trafficleft":traffic, "maxtraffic":50*1024*1024} else: - return {"premium" : False} + return {"premium" : False, "validuntil" : -1} def login(self, user, data, req): page = req.load("http://uploaded.to/io/login", post={ "id" : user, "pw" : data["password"], "_" : ""}) diff --git a/module/plugins/hooks/RealdebridCom.py b/module/plugins/hooks/RealdebridCom.py index e42ab42af..e415f8e05 100644 --- a/module/plugins/hooks/RealdebridCom.py +++ b/module/plugins/hooks/RealdebridCom.py @@ -56,7 +56,7 @@ class RealdebridCom(Hook): module = self.core.pluginManager.getPlugin("RealdebridCom") klass = getattr(module, "RealdebridCom") #inject real debrid plugin - self.core.log.debug("Real-Debrid: Supported Hosters: %s" % ", ".join(sorted(supported))) + self.core.log.debug("Real-Debrid: Overwritten Hosters: %s" % ", ".join(sorted(supported))) for hoster in supported: dict = self.core.pluginManager.hosterPlugins[hoster] dict["new_module"] = module diff --git a/module/plugins/hooks/RehostTo.py b/module/plugins/hooks/RehostTo.py new file mode 100644 index 000000000..324ef9b91 --- /dev/null +++ b/module/plugins/hooks/RehostTo.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +import re + +from module.network.RequestFactory import getURL +from module.plugins.Hook import Hook + +from module.utils import removeChars + +class RehostTo(Hook): + __name__ = "RehostTo" + __version__ = "0.4" + __type__ = "hook" + + __config__ = [("activated", "bool", "Activated", "False")] + + __description__ = """rehost.to hook plugin""" + __author_name__ = ("RaNaN") + __author_mail__ = ("RaNaN@pyload.org") + + interval = 0 + hosters = [] + + replacements = [("freakshare.net", "freakshare.com")] + + def getHostersCached(self): + if not self.hosters: + + page = getURL("http://rehost.to/api.php?cmd=get_supported_och_dl&long_ses=%s" % self.long_ses) + + self.hosters = [x.strip() for x in page.replace("\"", "").split(",")] + + for rep in self.replacements: + if rep[0] in self.hosters: + self.hosters.remove(rep[0]) + self.hosters.append(rep[1]) + + return self.hosters + + def coreReady(self): + + self.account = self.core.accountManager.getAccountPlugin("RehostTo") + + user = self.account.selectAccount()[0] + + if not user: + self.log.error("Rehost.to: "+ _("Please add your rehost.to account first and restart pyLoad")) + return + + data = self.account.getAccountInfo(user) + self.ses = data["ses"] + self.long_ses = data["long_ses"] + + pluginMap = {} + for name in self.core.pluginManager.hosterPlugins.keys(): + pluginMap[name.lower()] = name + + supported = [] + new_supported = [] + + for hoster in self.getHostersCached(): + name = removeChars(hoster.lower(), "-.") + + if pluginMap.has_key(name): + supported.append(pluginMap[name]) + else: + new_supported.append(hoster) + + module = self.core.pluginManager.getPlugin("RehostTo") + klass = getattr(module, "RehostTo") + #inject real debrid plugin + self.core.log.debug("Rehost.to: Overwritten Hosters: %s" % ", ".join(sorted(supported))) + for hoster in supported: + dict = self.core.pluginManager.hosterPlugins[hoster] + dict["new_module"] = module + dict["new_name"] = "RehostTo" + + self.core.log.debug("Rehost.to: New Hosters: %s" % ", ".join(sorted(new_supported))) + + #create new regexp + regexp = r".*(%s).*" % "|".join([klass.__pattern__] + [x.replace(".", "\\.") for x in new_supported]) + + dict = self.core.pluginManager.hosterPlugins["RehostTo"] + dict["pattern"] = regexp + dict["re"] = re.compile(regexp)
\ No newline at end of file diff --git a/module/plugins/hoster/RealdebridCom.py b/module/plugins/hoster/RealdebridCom.py index dc5b9098b..5db81b713 100644 --- a/module/plugins/hoster/RealdebridCom.py +++ b/module/plugins/hoster/RealdebridCom.py @@ -24,7 +24,7 @@ class RealdebridCom(Hoster): def process(self, pyfile):
if not self.account:
- self.log.error(_("Please enter your Real-debrid account"))
+ self.log.error(_("Please enter your Real-debrid account or deactivate this plugin"))
self.fail("No Real-debrid account provided")
self.log.debug("Real-Debrid: Old URL: %s" % pyfile.url)
diff --git a/module/plugins/hoster/RehostTo.py b/module/plugins/hoster/RehostTo.py new file mode 100644 index 000000000..2755facb7 --- /dev/null +++ b/module/plugins/hoster/RehostTo.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import re +from urllib import quote, unquote +from module.plugins.Hoster import Hoster + +class RehostTo(Hoster): + __name__ = "RehostTo" + __version__ = "0.1" + __type__ = "hoster" + + __pattern__ = r"https?://.*rehost.to\..*" + __description__ = """rehost.com hoster plugin""" + __author_name__ = ("RaNaN") + __author_mail__ = ("RaNaN@pyload.org") + + def getFilename(self, url): + return unquote(url.rsplit("/", 1)[1]) + + def setup(self): + self.chunkLimit = 3 + self.resumeDownload = True + + def process(self, pyfile): + if not self.account: + self.log.error(_("Please enter your rehost.to account or deactivate this plugin")) + self.fail("No rehost.to account provided") + + data = self.account.getAccountInfo(self.user) + long_ses = data["long_ses"] + + self.log.debug("Rehost.to: Old URL: %s" % pyfile.url) + new_url = "http://rehost.to/process_download.php?user=cookie&pass=%s&dl=%s" % (long_ses, quote(pyfile.url, "")) + + + self.download(new_url, disposition=True)
\ No newline at end of file diff --git a/module/web/json_app.py b/module/web/json_app.py index 36ecf22aa..9e9536a40 100644 --- a/module/web/json_app.py +++ b/module/web/json_app.py @@ -392,17 +392,25 @@ def add_account(): @route("/json/update_accounts", method="POST") @login_required("settings") def update_accounts(): + deleted = [] #dont update deleted accs or they will be created again + for name, value in request.POST.iteritems(): + value = value.strip() + if not value: continue + tmp, user = name.split(";") plugin, action = tmp.split("|") - if action == "password" and value: + if (plugin, user) in deleted: continue + + if action == "password": PYLOAD.update_account(plugin, user, value) - elif action == "time" and value and "-" in value: + elif action == "time" and "-" in value: PYLOAD.update_account(plugin, user, options={"time": [value]}) - elif action == "limitdl" and value and value.isdigit(): + elif action == "limitdl" and value.isdigit(): PYLOAD.update_account(plugin, user, options={"limitDL": [value]}) - elif action == "delete" and value: + elif action == "delete": + deleted.append((plugin,user)) PYLOAD.remove_account(plugin, user) diff --git a/module/web/pyload_app.py b/module/web/pyload_app.py index 0caf2ece3..47e80c96a 100644 --- a/module/web/pyload_app.py +++ b/module/web/pyload_app.py @@ -282,7 +282,6 @@ def folder(): def config(): conf = PYLOAD.get_config() plugin = PYLOAD.get_plugin_config() - accs = PYLOAD.get_accounts() conf_menu = [] plugin_menu = [] diff --git a/module/web/templates/default/settings.html b/module/web/templates/default/settings.html index 776089c47..4c8f0d63e 100644 --- a/module/web/templates/default/settings.html +++ b/module/web/templates/default/settings.html @@ -145,7 +145,7 @@ <td> <input id="{{plugin}}|password;{{account.login}}" name="{{plugin}}|password;{{account.login}}" - type="password" value="{{account.password}}" size="14"/> + type="password" value="{{account.password}}" size="12"/> </td> <td> {% if account.valid %} diff --git a/pyLoadCore.py b/pyLoadCore.py index be06dc5ee..d9f795026 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -297,7 +297,7 @@ class Core(object): self.do_restart = False self.shuttedDown = False - self.log.info("pyLoad %s" % CURRENT_VERSION) + self.log.info(_("Starting") + " pyLoad %s" % CURRENT_VERSION) self.log.info(_("Using home directory: %s") % getcwd()) self.writePidFile() @@ -359,12 +359,6 @@ class Core(object): self.log.info(_("Free space: %s") % formatSize(spaceLeft)) - self.threadManager.pause = False - #self.threadManager.start() - - self.running = True - self.hookManager.coreReady() - self.config.save() #save so config files gets filled link_file = join(pypath, "links.txt") @@ -386,6 +380,15 @@ class Core(object): self.log.info(_("Activating Accounts...")) self.accountManager.getAccountInfos() + + self.threadManager.pause = False + self.running = True + + self.log.info(_("Activating Plugins...")) + self.hookManager.coreReady() + + self.log.info(_("pyLoad is up and running")) + while True: sleep(2) if self.do_restart: |