Skip to content

Bulk asynchronous downloader for multiple file hosts

fix: UI not clearing properly

NTFSvolume54c4200ade51
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.py
index c3affe7d1..e848aba99 100644
--- a/cyberdrop_dl/main.py
+++ b/cyberdrop_dl/main.py
@@ -70,10 +70,6 @@ async def runtime(manager: Manager) -> None:
async def post_runtime(manager: Manager) -> None:
"""Actions to complete after main runtime, and before ui shutdown"""
- # Skip clearing console if running with no UI
- if not manager.args_manager.no_ui:
- Console().clear()
-
await log_spacer(20)
await log_with_color(f"Running Post-Download Processes For Config: {manager.config_manager.loaded_config}...\n", "green", 20)
#checking and removing dupes
@@ -91,8 +87,6 @@ async def post_runtime(manager: Manager) -> None:
if manager.config_manager.settings_data['Runtime_Options']['update_last_forum_post']:
await manager.log_manager.update_last_forum_post()
- await manager.progress_manager.print_stats()
-
async def director(manager: Manager) -> None:
"""Runs the program and handles the UI"""
@@ -175,15 +169,18 @@ async def director(manager: Manager) -> None:
except Exception:
await log("\nAn error occurred, please report this to the developer:", 50, exc_info=True)
exit(1)
-
+
+ await log_spacer(20)
+ await manager.progress_manager.print_stats()
if not manager.args_manager.all_configs or not list(set(configs) - set(configs_ran)):
break
+ await log_spacer(20)
await log("Checking for Updates...", 20)
await check_latest_pypi()
+ await log_spacer(20)
await log("Closing Program...", 20)
await manager.close()
- await log_spacer(20)
await log_with_color("Finished downloading. Enjoy :)", 'green', 20)
diff --git a/cyberdrop_dl/managers/live_manager.py b/cyberdrop_dl/managers/live_manager.py
index 90c91f443..0dccfc101 100644
--- a/cyberdrop_dl/managers/live_manager.py
+++ b/cyberdrop_dl/managers/live_manager.py
@@ -1,70 +1,61 @@
+from __future__ import annotations
from contextlib import asynccontextmanager
-
+from typing import TYPE_CHECKING
from rich.live import Live
+from rich.console import Console
from cyberdrop_dl.managers.console_manager import console
from cyberdrop_dl.utils.utilities import log
+if TYPE_CHECKING:
+ from cyberdrop_dl.managers.manager import Manager
+ from rich.layout import Layout
+
class LiveManager:
- def __init__(self, manager):
+ def __init__(self, manager: Manager):
self.manager = manager
self.live = Live(auto_refresh=True,
refresh_per_second=self.manager.config_manager.global_settings_data['UI_Options'][
'refresh_rate'], console=console)
@asynccontextmanager
- async def get_main_live(self, stop=False):
+ async def get_live(self, layout: Layout, stop=False):
try:
if self.manager.args_manager.no_ui:
yield
else:
self.live.start()
- self.live.update(self.manager.progress_manager.layout, refresh=True)
+ self.live.update(layout, refresh=True)
yield self.live
if stop:
self.live.stop()
+ if not self.manager.args_manager.no_ui:
+ Console().clear()
except Exception as e:
- await log(f"Issue with rich live {e}", level=10, exc_info=True)
+ await log(f"Issue with rich live {e}", level=10, exc_info=True)
+
+ @asynccontextmanager
+ async def get_main_live(self, stop=False):
+ "main UI startup and context manager"
+ layout = self.manager.progress_manager.layout
+ async with self.get_live(layout, stop=stop) as live:
+ yield live
@asynccontextmanager
async def get_remove_file_via_hash_live(self, stop=False):
- try:
- if self.manager.args_manager.no_ui:
- yield
- else:
- self.live.start()
- self.live.update(self.manager.progress_manager.hash_remove_layout, refresh=True)
- yield
- if stop:
- self.live.stop()
- except Exception as e:
- await log(f"Issue with rich live {e}", level=10, exc_info=True)
+ layout = self.manager.progress_manager.hash_remove_layout
+ async with self.get_live(layout, stop=stop) as live:
+ yield live
@asynccontextmanager
async def get_hash_live(self, stop=False):
- try:
- if self.manager.args_manager.no_ui:
- yield
- else:
- self.live.start()
- self.live.update(self.manager.progress_manager.hash_layout, refresh=True)
- yield
- if stop:
- self.live.stop()
- except Exception as e:
- await log(f"Issue with rich live {e}", level=10, exc_info=True)
+ layout = self.manager.progress_manager.hash_layout
+ async with self.get_live(layout, stop=stop) as live:
+ yield live
@asynccontextmanager
async def get_sort_live(self, stop=False):
- try:
- if self.manager.args_manager.no_ui:
- yield
- else:
- self.live.start()
- self.live.update(self.manager.progress_manager.sort_layout, refresh=True)
- yield
- if stop:
- self.live.stop()
- except Exception as e:
- await log(f"Issue with rich live {e}", level=10, exc_info=True)
+ layout = self.manager.progress_manager.sort_layout
+ async with self.get_live(layout, stop=stop) as live:
+ yield live