mirror of
https://github.com/oskvr37/tiddl.git
synced 2026-06-13 04:05:08 +03:00
💄 Show item download path
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user