def event_status(self, args): downloads = self.pyload.api.status_downloads() if not downloads: return ["INFO: There are no active downloads currently."] temp_progress = "" lines = ["ID - Name - Status - Speed - ETA - Progress"] for data in downloads: if data.status == 5: temp_progress = data.format_wait else: temp_progress = "{}% ({})".format(data.percent, data.format_size) lines.append( "#{} - {} - {} - {} - {} - {}".format( data.fid, data.name, data.statusmsg, "{}".format(format_speed(data.speed)), "{}".format(data.format_eta), temp_progress, ) ) return lines
def links(): api = flask.current_app.config["PYLOAD_API"] try: links = api.status_downloads() ids = [] for link in links: ids.append(link["fid"]) if link["status"] == 12: formatted_eta = link["format_eta"] formatted_speed = format_speed(link["speed"]) link["info"] = f"{formatted_eta} @ {formatted_speed}" elif link["status"] == 5: link["percent"] = 0 link["size"] = 0 link["bleft"] = 0 link["info"] = api._("waiting {}").format(link["format_wait"]) else: link["info"] = "" return jsonify(links=links, ids=ids) except Exception as exc: flask.abort(500) return jsonify(False)
def render_header(self, line): """ prints download status. """ # print(updated information) # print("\033[J" #clear screen) # self.println(1, blue("py") + yellow("Load") + white(self._(" Command Line Interface"))) # self.println(2, "") # self.println(3, white(self._("{} Downloads:").format(len(data)))) data = self.client.status_downloads() speed = 0 println(line, white(self._("{} Downloads:").format(len(data)))) line += 1 for download in data: if download.status == 12: #: downloading percent = download.percent z = percent // 4 speed += download.speed println(line, cyan(download.name)) line += 1 println( line, blue("[") + yellow(z * "#" + (25 - z) * " ") + blue("] ") + green(str(percent) + "%") + self._(" Speed: ") + green(format_speed(download.speed)) + self._(" Size: ") + green(download.format_size) + self._(" Finished in: ") + green(download.format_eta) + self._(" ID: ") + green(download.fid), ) line += 1 if download.status == 5: println(line, cyan(download.name)) line += 1 println(line, self._("waiting: ") + green(download.format_wait)) line += 1 println(line, "") line += 1 status = self.client.status_server() if status.pause: paused = self._("Status:") + " " + red(self._("paused")) else: paused = self._("Status:") + " " + red(self._("running")) println( line, f'{paused} {self._("total Speed")}: {red(format_speed(speed))} {self._("Files in queue")}: {red(status.queue)} {self._("Total")}: {red(status.total)}', ) return line + 1
def dashboard(): api = flask.current_app.config["PYLOAD_API"] links = api.status_downloads() for link in links: if link["status"] == 12: current_size = link["size"] - link["bleft"] formatted_speed = format_speed(link["speed"]) link["info"] = f"{current_size} KiB @ {formatted_speed}" return render_template("dashboard.html", res=links)
def event_status(self, args): downloads = self.pyload.api.status_downloads() if not downloads: return ["INFO: There are no active downloads currently."] temp_progress = "" lines = ["ID - Name - Status - Speed - ETA - Progress"] for data in downloads: if data.status == 5: temp_progress = data.format_wait else: temp_progress = "{}% ({})".format(data.percent, data.format_size) lines.append("#{} - {} - {} - {} - {} - {}".format( data.fid, data.name, data.statusmsg, "{}".format(format_speed(data.speed)), "{}".format(data.format_eta), temp_progress, )) return lines
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 file: content = file.read() rid = self.client.check_online_status_container( [], os.path.basename(file.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 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 file: content = file.read() rid = self.client.check_online_status_container( [], os.path.basename(file.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()