def handle_premium(self, pyfile): current_millis = int(time.time() * 1000) self.req.http.c.setopt(pycurl.HTTPHEADER, ["X-Requested-With: XMLHttpRequest"]) self.data = self.load( "http://www.nitrobit.net/ajax/unlock.php", get={ "password": self.account.info["login"]["password"], "file": self.info["pattern"]["ID"], "keep": "false", "_": current_millis, }, ) m = re.search(r'id="unlockedTick".+?alt="(\d+)"', self.data) if m is not None: validuntil = time.time() + float(m.group(1)) self.log_info( self._("Account valid until {}").format( time.strftime("%d/%m/%Y"), time.gmtime(validuntil))) m = re.search(r'id="dailyVolume" value="(\d+)?/(\d+)"', self.data) if m is not None: trafficleft = int(m.group(2)) - int((m.group(1) or "0")) self.log_info( self._("Daily traffic left {}").format( format.size(trafficleft))) m = re.search(self.LINK_PREMIUM_PATTERN, self.data) if m is not None: self.link = m.group(1)
def out_of_traffic(self): if not self.account: return False traffic = self.account.get_data("trafficleft") if traffic is None: return True elif traffic == -1: return False else: size = self.pyfile.size self.log_info( self._("Filesize: {}").format(format.size(size)), self._("Traffic left for user `{}`: {}").format( self.account.user, format.size(traffic) ), ) return size > traffic
def _update_size(self): size = self.info.get("size") if size > 0: # TODO: Fix int conversion in 0.6.x self.pyfile.size = int(self.info.get("size")) else: size = self.pyfile.size if size: self.log_info( self._("Link size: {} ({} bytes)").format( format.size(size), size)) else: self.log_info(self._("Link size: N/D"))
def info(): api = flask.current_app.config["PYLOAD_API"] conf = api.get_config_dict() extra = os.uname() if hasattr(os, "uname") else tuple() context = { "python": sys.version, "os": " ".join((os.name, sys.platform) + extra), "version": api.get_server_version(), "folder": PKGDIR, "config": api.get_userdir(), "download": conf["general"]["storage_folder"]["value"], "freespace": format.size(api.free_space()), "webif": conf["webui"]["port"]["value"], "language": conf["general"]["language"]["value"], } return render_template("info.html", **context)
def print_online_check(self, client, rid): while True: time.sleep(1) result = client.poll_results(rid) for url, status in result.data.items(): if status.status == 2: check = "Online" elif status.status == 1: check = "Offline" else: check = "Unknown" print( "{:-45} {:-12}\t {:-15}\t {}".format( status.name, format.size(status.size), status.plugin, check ) ) if result.rid == -1: break
def settings(): api = flask.current_app.config["PYLOAD_API"] conf = api.get_config() plugin = api.get_plugin_config() conf_menu = [] plugin_menu = [] for entry in sorted(conf.keys()): conf_menu.append((entry, conf[entry].description)) for entry in sorted(plugin.keys()): plugin_menu.append((entry, plugin[entry].description)) accs = [] for data in api.get_accounts(False): if data.trafficleft == -1: trafficleft = "unlimited" elif not data.trafficleft: trafficleft = "not available" else: trafficleft = format.size(data.trafficleft) if data.validuntil == -1: validuntil = "unlimited" elif not data.validuntil: validuntil = "not available" else: t = time.localtime(data.validuntil) validuntil = time.strftime("%d.%m.%Y", t) if "time" in data.options: try: _time = data.options["time"][0] except Exception: _time = "" else: _time = "" if "limit_dl" in data.options: try: limitdl = data.options["limit_dl"][0] except Exception: limitdl = "0" else: limitdl = "0" accs.append({ "type": data.type, "login": data.login, "valid": data.valid, "premium": data.premium, "trafficleft": trafficleft, "validuntil": validuntil, "limitdl": limitdl, "time": _time, }) context = { "conf": { "plugin": plugin_menu, "general": conf_menu, "accs": accs }, "types": api.get_account_types(), } return render_template("settings.html", **context)
def process_command(self): command = self.command[0] args = [] if len(self.command) > 1: args = self.command[1:] if command == "status": files = self.client.status_downloads() if not files: print("No downloads running.") for download in files: if download.status == 12: #: downloading formatted_speed = format.speed(download.speed) downloaded_size = format.size(download.size - download.bleft) print(print_status(download)) print( f"\t_downloading: {download.format_eta} @ {formatted_speed}\t {downloaded_size} ({download.percent}%%)" ) elif download.status == 5: print(print_status(download)) print(f"\t_waiting: {download.format_wait}") else: print(print_status(download)) elif command == "queue": print_packages(self.client.get_queue_data()) elif command == "collector": print_packages(self.client.get_collector_data()) elif command == "add": if len(args) < 2: print( self._( "Please use this syntax: add <Package name> <link> <link2>..." ) ) return self.client.add_package(args[0], args[1:], Destination.QUEUE) elif command == "add_coll": if len(args) < 2: print( self._( "Please use this syntax: add <Package name> <link> <link2>..." ) ) return self.client.add_package(args[0], args[1:], Destination.COLLECTOR) elif command == "del_file": self.client.delete_files(int(x) for x in args) print("Files deleted.") elif command == "del_package": self.client.delete_packages(int(x) for x in args) print("Packages deleted.") elif command == "move": for pid in args: pack = self.client.get_package_info(int(pid)) self.client.move_package((pack.dest + 1) % 2, pack.pid) elif command == "check": print(self._("Checking {} links:").format(len(args))) print() rid = self.client.check_online_status(args).rid self.print_online_check(self.client, rid) elif command == "check_container": path = args[0] if not os.path.exists(path): print(self._("File does not exists.")) return with open(path, mode="rb") as fp: content = fp.read() rid = self.client.check_online_status_container( [], os.path.basename(fp.name), content ).rid self.print_online_check(self.client, rid) elif command == "pause": self.client.pause() elif command == "unpause": self.client.unpause() elif command == "toggle": self.client.api.toggle_pause() elif command == "kill": self.client.kill() elif command == "restart_file": for x in args: self.client.restart_file(int(x)) print("Files restarted.") elif command == "restart_package": for pid in args: self.client.restart_package(int(pid)) print("Packages restarted.") else: print_commands()
def formatsize(*args, **kwargs): return format.size(*args, **kwargs)
def _cmd_freespace(self, args): b = format.size(int(self.pyload.api.free_space())) return ["INFO: Free space is {}.".format(b)]