Skip to content

Bulk asynchronous downloader for multiple file hosts

use same console

datawhores40b925cff08e
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.py
index bcf34d31b..9e48da590 100644
--- a/cyberdrop_dl/main.py
+++ b/cyberdrop_dl/main.py
@@ -5,7 +5,6 @@ import os
import sys
import traceback
-from rich.live import Live
from cyberdrop_dl.managers.manager import Manager
from cyberdrop_dl.scraper.scraper import ScrapeMapper
@@ -13,6 +12,8 @@ from cyberdrop_dl.ui.ui import program_ui
from cyberdrop_dl.utils.sorting import Sorter
from cyberdrop_dl.utils.utilities import check_latest_pypi, log_with_color, check_partials_and_empty_folders, log
from cyberdrop_dl.clients.hash_client import HashClient
+from cyberdrop_dl.managers.console_manager import ConsoleManager
+
def startup() -> Manager:
"""
@@ -31,7 +32,7 @@ def startup() -> Manager:
return manager
except KeyboardInterrupt:
- print("\nExiting...")
+ ConsoleManager().console.print(e)
exit(0)
@@ -41,8 +42,15 @@ async def runtime(manager: Manager) -> None:
# NEW CODE
async with asyncio.TaskGroup() as task_group:
- manager.task_group = task_group
- await scrape_mapper.start()
+ try:
+ manager.task_group = task_group
+ await scrape_mapper.start()
+ except Exception as e:
+ ConsoleManager().console.print(e)
+ ConsoleManager().console.print(traceback.format_exc())
+ exit(1)
+
+
async def post_runtime(manager: Manager) -> None:
"""Actions to complete after main runtime, and before ui shutdown"""
@@ -115,9 +123,9 @@ async def director(manager: Manager) -> None:
await runtime(manager)
await post_runtime(manager)
except Exception as e:
- print("\nAn error occurred, please report this to the developer")
- print(e)
- print(traceback.format_exc())
+ ConsoleManager().console.print("\nAn error occurred, please report this to the developer")
+ ConsoleManager().console.print(e)
+ ConsoleManager().console.print(traceback.format_exc())
exit(1)
clear_screen_proc = await asyncio.create_subprocess_shell('cls' if os.name == 'nt' else 'clear')
@@ -167,7 +175,7 @@ def main():
try:
asyncio.run(director(manager))
except KeyboardInterrupt:
- print("\nTrying to Exit...")
+ console.print("\nTrying to Exit...")
with contextlib.suppress(Exception):
asyncio.run(manager.close())
exit(1)
diff --git a/cyberdrop_dl/managers/console_manager.py b/cyberdrop_dl/managers/console_manager.py
new file mode 100644
index 000000000..c90c2ecdb
--- /dev/null
+++ b/cyberdrop_dl/managers/console_manager.py
@@ -0,0 +1,9 @@
+from rich.console import Console
+console=Console()
+class ConsoleManager:
+ def __init__(self):
+ pass
+
+ @property
+ def console(self):
+ return console
diff --git a/cyberdrop_dl/managers/live_manager.py b/cyberdrop_dl/managers/live_manager.py
index c7b973c04..18bc4b054 100644
--- a/cyberdrop_dl/managers/live_manager.py
+++ b/cyberdrop_dl/managers/live_manager.py
@@ -1,12 +1,13 @@
from rich.live import Live
from contextlib import contextmanager
+from cyberdrop_dl.managers.console_manager import ConsoleManager
class LiveManager:
def __init__(self,manager):
self.manager = manager
- self.live=Live(auto_refresh=True, refresh_per_second=self.manager.config_manager.global_settings_data['UI_Options']['refresh_rate'])
+ self.live=Live(auto_refresh=True, refresh_per_second=self.manager.config_manager.global_settings_data['UI_Options']['refresh_rate'],console=ConsoleManager().console)
@contextmanager
def get_main_live(self,stop=False):
try:
@@ -19,7 +20,7 @@ class LiveManager:
if stop:
self.live.stop()
except Exception as e:
- print(e)
+ ConsoleManager().console.print(e)
@@ -38,7 +39,7 @@ class LiveManager:
if stop:
self.live.stop()
except Exception as e:
- print(e)
+ ConsoleManager().console.print(e)
@@ -55,5 +56,5 @@ class LiveManager:
if stop:
self.live.stop()
except Exception as e:
- print(e)
+ ConsoleManager().console.print(e)
diff --git a/cyberdrop_dl/utils/database/tables/hash_table.py b/cyberdrop_dl/utils/database/tables/hash_table.py
index 2a70d65e9..b03db13e9 100644
--- a/cyberdrop_dl/utils/database/tables/hash_table.py
+++ b/cyberdrop_dl/utils/database/tables/hash_table.py
@@ -6,7 +6,8 @@ import aiosqlite
from cyberdrop_dl.utils.database.table_definitions import create_hash
-
+from rich.console import Console
+console=Console()
class HashTable:
def __init__(self, db_conn: aiosqlite.Connection):
self.db_conn: aiosqlite.Connection = db_conn
@@ -45,7 +46,7 @@ class HashTable:
return result[0]
return None
except Exception as e:
- print(f"Error checking file: {e}")
+ console.print(f"Error checking file: {e}")
return False
async def get_files_with_hash_matches(self,hash_value,size):
@@ -66,7 +67,7 @@ class HashTable:
results = await cursor.fetchall()
return results
except Exception as e:
- print(f"Error retrieving folder and filename: {e}")
+ console.print(f"Error retrieving folder and filename: {e}")
return []
@@ -103,7 +104,7 @@ class HashTable:
await self.db_conn.commit()
return True
except Exception as e:
- print(f"Error inserting/updating record: {e}")
+ console.print(f"Error inserting/updating record: {e}")
return False