Skip to content

Bulk asynchronous downloader for multiple file hosts

Merge branch 'master' into retry

datawhores4a59780a07d9
diff --cc cyberdrop_dl/managers/console_manager.py
index 895190f4b,9b966c6d6..402ee33c5
--- a/cyberdrop_dl/managers/console_manager.py
+++ b/cyberdrop_dl/managers/console_manager.py
@@@ -6,61 -5,42 +6,62 @@@ from collections import dequ
from rich.console import Console
console = Console()
-_height,_width=None,None
+_HEIGHT,_=None,None
+LEVEL=100
+QUEUE= deque()
+def log(level,record,*args, sleep=None,**kwargs):
+ level=level or 10
+ if level>=LEVEL:
+ # QUEUE.append((record,sleep))
+ console.log(record)
+ if sleep:
+ time.sleep(sleep)
+def print_(text,sleep=None):
+ set_console_height()
+ console.print(text)
-class ConsoleManager:
- def __init__(self):
- pass
-
-
+def set_console_height():
+ global _HEIGHT
+ _width, _new_height = shutil.get_terminal_size()
+ if not _HEIGHT==_new_height:
+ _HEIGHT=_new_height
+ console.size = (_width, _HEIGHT - 4)
- @property
- def console(self):
- return console
+class ConsoleManager:
+ def __init__(self):
+ self.thread=None
-
- def log(self,*args, sleep=None,**kwargs):
- self._log_helper(*args,sleep=sleep, **kwargs)
- def _log_helper(self,*args, sleep=None,**kwargs):
- # global _height
- # _width, _new_height = shutil.get_terminal_size()
- # if not _height==_new_height:
- # _height=_new_height
- # console.size = (_width, _height - 4)
- # self.console.log(*args, **kwargs)
- # if sleep:
- # time.sleep(sleep)
+ def startup(self) -> None:
+ pass
+ # self.thread = threading.Thread(target=self.flush_buffer_thread)
+ # self.thread.start()
+ def close(self):
pass
+ # if self.thread:
+ # self.thread.join()
+
+ def flush_buffer_thread(self):
+ max_entries=10
+ while True:
+ log_rends = []
+ try:
+ num = min(len(QUEUE), max_entries)
+ sleep=None
+ for _ in range(num):
+ log_renderable,sleep = QUEUE.popleft()
+ log_rends.append(log_renderable)
+ if sleep:
+ break
+ if not bool(log_rends):
+ time.sleep(.3)
+ continue
+ set_console_height()
+ console.log("\n".join(log_rends))
+ if sleep:
+ time.sleep(sleep)
+ except Exception:
+ pass
-
++
+
- def print(self,text,sleep=None):
- self._print_helper(text,sleep=sleep)
- def _print_helper(self,text,sleep=None):
- global _height
- _width, _new_height = shutil.get_terminal_size()
- if not _height==_new_height:
- _height=_new_height
- console.size = (_width, _height - 4)
- self.console.print(text)
- if sleep:
- time.sleep(sleep)