From dc2ff4da3317b4fa473da8c300e25f1e336b3695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Dudzi=C5=84ski?= Date: Mon, 10 Nov 2025 17:11:54 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Show=20item=20download=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tiddl/cli/commands/download/downloader.py | 14 ++++++++++---- tiddl/cli/commands/download/output.py | 19 +++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/tiddl/cli/commands/download/downloader.py b/tiddl/cli/commands/download/downloader.py index 313c5c8..fe95252 100644 --- a/tiddl/cli/commands/download/downloader.py +++ b/tiddl/cli/commands/download/downloader.py @@ -122,8 +122,10 @@ class Downloader: result_message = "[cyan]Overwrited" if self.skip_existing: - self.rich_output.console.print( - f"[yellow]Exists [{vibrant_color}][link={existing_file_path.as_uri()}]{item.title}[/link]" + self.rich_output.show_item_result( + result_message="[yellow]Exists", + item_description=f"[{vibrant_color}]{item.title}", + item_path=existing_file_path, ) return existing_file_path, False @@ -200,10 +202,14 @@ class Downloader: except Exception as exc: log.error(f"{should_extract_flac=}, {exc=}") - self.rich_output.download_finish( + task = self.rich_output.download_finish( task_id=task_id, - item_link=download_path.as_uri(), + ) + + self.rich_output.show_item_result( result_message=result_message, + item_description=task.description, + item_path=download_path, ) return download_path, True diff --git a/tiddl/cli/commands/download/output.py b/tiddl/cli/commands/download/output.py index 4d61e8f..e8aad5e 100644 --- a/tiddl/cli/commands/download/output.py +++ b/tiddl/cli/commands/download/output.py @@ -1,3 +1,5 @@ +from pathlib import Path + from rich.console import Console, Group from rich.progress import ( Progress, @@ -76,17 +78,26 @@ class RichOutput: def download_advance(self, task_id: TaskID, size: float): self.download_progress.update(task_id=task_id, advance=size, refresh=True) - def download_finish(self, task_id: TaskID, item_link: str, result_message: str): + def download_finish(self, task_id: TaskID) -> Task: task = self.download_progress._tasks.get(task_id) assert task is not None self.download_progress.remove_task(task_id=task_id) self.total_progress.advance(self.total_task, advance=1) - self.console.print( - f"{result_message} [link={item_link}]{task.description}[/link]" - ) self.total_downloads += 1 + return task + def show_stats(self): self.console.print(f"[green]Total downloads: {self.total_downloads}") + + def show_item_result( + self, result_message: str, item_description: str, item_path: Path | None + ): + if item_path: + description = f"[link={item_path.as_uri()}]{item_description}[/link] [link={item_path.parent.as_uri()}]{item_path.parent}[/link]" + else: + description = item_description + + self.console.print(f"{result_message} {description}")