diff --git a/uldlib/cmd.py b/uldlib/cmd.py index ef10872..93a411b 100644 --- a/uldlib/cmd.py +++ b/uldlib/cmd.py @@ -19,6 +19,8 @@ def run(): help="URL from Uloz.to (tip: enter in 'quotes' because the URL contains ! sign)") parser.add_argument('--parts', metavar='N', type=int, default=20, help='Number of parts that will be downloaded in parallel') + parser.add_argument('--parts-progress', default=False, action='store_true', + help='Show progress of parts while being downloaded') parser.add_argument('--output', metavar='DIRECTORY', type=str, default="./", help='Target directory') parser.add_argument('--auto-captcha', default=False, action="store_true", @@ -32,7 +34,7 @@ def run(): args = parser.parse_args() # TODO: implement other frontends and allow to choose from them - frontend = ConsoleFrontend() + frontend = ConsoleFrontend(args) tfull_available = importlib.util.find_spec('tensorflow.lite') tflite_available = importlib.util.find_spec('tflite_runtime') diff --git a/uldlib/frontend.py b/uldlib/frontend.py index 39e203f..7709124 100644 --- a/uldlib/frontend.py +++ b/uldlib/frontend.py @@ -47,17 +47,19 @@ def run(self, parts: List[DownloadPart], stop_event: threading.Event, terminate_ class ConsoleFrontend(Frontend): cli_initialized: bool + show_parts_progress: bool last_log: Tuple[str, LogLevel] last_captcha_log: Tuple[str, LogLevel] last_captcha_stats: Dict[str, int] - def __init__(self): + def __init__(self, args): self.cli_initialized = False self.last_log = ("", LogLevel.INFO) self.last_captcha_log = ("", LogLevel.INFO) self.last_captcha_stats = None + self.show_parts_progress = args.parts_progress def captcha_log(self, msg: str, level: LogLevel = LogLevel.INFO): self.last_captcha_log = (msg, level) @@ -153,13 +155,7 @@ def _loop(self, info: DownloadInfo, parts: List[DownloadPart], stop_event: threa lines.append(self._color(line, level)) s += size - # Print parts - for (line, part) in zip(lines, parts): - self._print( - colors.blue(f"[Part {part.id}]") + f"\t{line}", - y=(part.id + CLI_STATUS_STARTLINE)) - - y = info.parts + CLI_STATUS_STARTLINE + y = CLI_STATUS_STARTLINE # Print CAPTCHA/TOR status (msg, level) = self.last_captcha_log @@ -211,6 +207,13 @@ def _loop(self, info: DownloadInfo, parts: List[DownloadPart], stop_event: threa ) y += 1 + # Print parts + if self.show_parts_progress: + for (line, part) in zip(lines, parts): + self._print( + colors.blue(f"[Part {part.id}]") + f"\t{line}", + y=(y + part.id)) + time.sleep(0.5) if self.cli_initialized: