Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: reorder properties

NTFSvolumee7666b54a50d
diff --git a/cyberdrop_dl/ui/progress/deque_progress.py b/cyberdrop_dl/ui/progress/deque_progress.py
index f75a4116a..a17c90723 100644
--- a/cyberdrop_dl/ui/progress/deque_progress.py
+++ b/cyberdrop_dl/ui/progress/deque_progress.py
@@ -17,15 +17,16 @@ class DequeProgress(ABC):
progress: Progress
title: str
type_str: str = "Files"
+ color = "plum3"
+ progress_str = "[{color}]{description}"
+ overflow_str = "[{color}]... And {number} Other {type_str}"
+ queue_str = "[{color}]... And {number} {type_str} In {title} Queue"
def __init__(self, visible_tasks_limit: int) -> None:
self.overflow = Progress("[progress.description]{task.description}")
self.queue = Progress("[progress.description]{task.description}")
self.progress_group = Group(self.progress, self.overflow, self.queue)
- self.color = "plum3"
- self.progress_str = "[{color}]{description}"
- self.overflow_str = "[{color}]... And {number} Other {type_str}"
- self.queue_str = "[{color}]... And {number} {type_str} In {title} Queue"
+
self.overflow_task_id = self.overflow.add_task(
self.overflow_str.format(color=self.color, number=0, type_str=self.type_str),
visible=False,
@@ -37,6 +38,9 @@ class DequeProgress(ABC):
self.tasks: deque[TaskID] = deque([])
self._tasks_visibility_limit = visible_tasks_limit
+ @abstractmethod
+ def get_queue_length(self) -> int: ...
+
@property
def visible_tasks(self) -> Sequence[TaskID]:
if len(self.tasks) > self._tasks_visibility_limit:
@@ -59,22 +63,42 @@ class DequeProgress(ABC):
"""Returns the progress bar."""
return Panel(self.progress_group, title=self.title, border_style="green", padding=(1, 1))
- @abstractmethod
- def get_queue_length(self) -> int: ...
+ def add_task(self, description: str, total: float | None = None) -> TaskID:
+ """Adds a new task to the progress bar."""
+ task_id = self.progress.add_task(
+ self.progress_str.format(color=self.color, description=description),
+ total=total,
+ visible=self.has_visible_capacity(),
+ )
+ self.tasks.append(task_id)
+ self.redraw()
+ return task_id
+
+ def remove_task(self, task_id: TaskID) -> None:
+ """Removes a task from the progress bar."""
+ if task_id not in self.tasks:
+ msg = "Task ID not found"
+ raise ValueError(msg)
+
+ self.tasks.remove(task_id)
+ self.progress.remove_task(task_id)
+ self.redraw()
def redraw(self) -> None:
"""Redraws the progress bar."""
for task in self.visible_tasks:
self.progress.update(task, visible=True)
+ invisible_tasks_len = self.invisible_tasks_len
+
self.overflow.update(
self.overflow_task_id,
description=self.overflow_str.format(
color=self.color,
- number=self.invisible_tasks_len,
+ number=invisible_tasks_len,
type_str=self.type_str,
),
- visible=self.invisible_tasks_len > 0,
+ visible=invisible_tasks_len > 0,
)
queue_length = self.get_queue_length()
@@ -86,24 +110,3 @@ class DequeProgress(ABC):
),
visible=queue_length > 0,
)
-
- def add_task(self, description: str, total: float | None = None) -> TaskID:
- """Adds a new task to the progress bar."""
- task_id = self.progress.add_task(
- self.progress_str.format(color=self.color, description=description),
- total=total,
- visible=self.has_visible_capacity(),
- )
- self.tasks.append(task_id)
- self.redraw()
- return task_id
-
- def remove_task(self, task_id: TaskID) -> None:
- """Removes a task from the progress bar."""
- if task_id not in self.tasks:
- msg = "Task ID not found"
- raise ValueError(msg)
-
- self.tasks.remove(task_id)
- self.progress.remove_task(task_id)
- self.redraw()
diff --git a/cyberdrop_dl/ui/progress/file_progress.py b/cyberdrop_dl/ui/progress/file_progress.py
index 0751a8181..f5e9bd741 100644
--- a/cyberdrop_dl/ui/progress/file_progress.py
+++ b/cyberdrop_dl/ui/progress/file_progress.py
@@ -28,6 +28,8 @@ def adjust_title(s: str, length: int = 40, placeholder: str = "...") -> str:
class FileProgress(DequeProgress):
"""Class that manages the download progress of individual files."""
+ title = "Downloads"
+
def __init__(self, visible_tasks_limit: int, manager: Manager) -> None:
self.manager = manager
self.progress = Progress(
@@ -42,7 +44,6 @@ class FileProgress(DequeProgress):
"━",
TimeRemainingColumn(),
)
- self.title = "Downloads"
self.downloaded_data = ByteSize(0)
super().__init__(visible_tasks_limit)
diff --git a/cyberdrop_dl/ui/progress/scraping_progress.py b/cyberdrop_dl/ui/progress/scraping_progress.py
index 6b94adab9..b49f873e0 100644
--- a/cyberdrop_dl/ui/progress/scraping_progress.py
+++ b/cyberdrop_dl/ui/progress/scraping_progress.py
@@ -15,11 +15,12 @@ if TYPE_CHECKING:
class ScrapingProgress(DequeProgress):
"""Class that manages the download progress of individual files."""
+ title = "Scraping"
+ type_str = "URLs"
+
def __init__(self, visible_tasks_limit: int, manager: Manager) -> None:
self.manager = manager
self.progress = Progress(SpinnerColumn(), "[progress.description]{task.description}")
- self.title = "Scraping"
- self.type_str = "URLs"
super().__init__(visible_tasks_limit)
def get_queue_length(self) -> int: