Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Fix: Windows Startup Logger Permission Error (#455)
Jacobdef5d03e76da
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex 8a3bc93ac..3b8ba2cb3 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -27,8 +27,9 @@ from cyberdrop_dl.utils.yaml import handle_validation_errorif TYPE_CHECKING:from collections.abc import Callable-logger_startup = logging.getLogger("cyberdrop_dl_startup")-LOGGER_STARTUP_FILE = Path().cwd().joinpath("downloader.log")+startup_logger = logging.getLogger("cyberdrop_dl_startup")+STARTUP_LOGGER_FILE = Path().cwd().joinpath("startup.log")+STARTUP_LOGGER_CONSOLE = Nonedef startup() -> Manager:@@ -42,14 +43,14 @@ def startup() -> Manager:manager = Manager()manager.startup()if manager.parsed_args.cli_only_args.multiconfig:- logger_startup.info("validating all configs, please wait...")+ startup_logger.info("validating all configs, please wait...")manager.validate_all_configs()if not manager.parsed_args.cli_only_args.download:ProgramUI(manager)except InvalidYamlError as e:- logger_startup.error(e.message)+ startup_logger.error(e.message)sys.exit(1)except ValidationError as e:@@ -61,12 +62,12 @@ def startup() -> Manager:handle_validation_error(e, sources=sources)except KeyboardInterrupt:- logger_startup.info("Exiting...")+ startup_logger.info("Exiting...")sys.exit(0)except Exception:msg = "An error occurred, please report this to the developer with your logs file:"- logger_startup.exception(msg)+ startup_logger.exception(msg)sys.exit(1)else:@@ -107,19 +108,21 @@ async def post_runtime(manager: Manager) -> None:def setup_startup_logger() -> None:- logger_startup.setLevel(10)- LOGGER_STARTUP_FILE.unlink(missing_ok=True)+ global STARTUP_LOGGER_CONSOLE+ startup_logger.setLevel(10)+ STARTUP_LOGGER_FILE.unlink(missing_ok=True)+ STARTUP_LOGGER_CONSOLE = RedactedConsole(+ file=STARTUP_LOGGER_FILE.open("w", encoding="utf8"),+ width=constants.DEFAULT_CONSOLE_WIDTH,+ )rich_file_handler = RichHandler(**constants.RICH_HANDLER_CONFIG,- console=RedactedConsole(- file=LOGGER_STARTUP_FILE.open("w", encoding="utf8"),- width=constants.DEFAULT_CONSOLE_WIDTH,- ),+ console=STARTUP_LOGGER_CONSOLE,level=10,)rich_handler = RichHandler(**(constants.RICH_HANDLER_CONFIG | {"show_time": False}), level=10)- logger_startup.addHandler(rich_file_handler)- logger_startup.addHandler(rich_handler)+ startup_logger.addHandler(rich_file_handler)+ startup_logger.addHandler(rich_handler)def setup_debug_logger(manager: Manager) -> Path | None:@@ -214,8 +217,9 @@ async def director(manager: Manager) -> None:if manager.multiconfig:configs_to_run = manager.config_manager.get_configs()- if LOGGER_STARTUP_FILE.is_file() and LOGGER_STARTUP_FILE.stat().st_size == 0:- LOGGER_STARTUP_FILE.unlink()+ if STARTUP_LOGGER_FILE.is_file() and STARTUP_LOGGER_FILE.stat().st_size == 0:+ STARTUP_LOGGER_CONSOLE.file.close()+ STARTUP_LOGGER_FILE.unlink()start_time = manager.start_timewhile configs_to_run:@@ -258,7 +262,7 @@ def main() -> None:asyncio.run(director(manager))exit_code = 0except KeyboardInterrupt:- logger_startup.info("Trying to Exit ...")+ startup_logger.info("Trying to Exit ...")finally:asyncio.run(manager.close())loop.close()diff --git a/cyberdrop_dl/utils/yaml.py b/cyberdrop_dl/utils/yaml.pyindex 37e56f03b..dbda070cc 100644--- a/cyberdrop_dl/utils/yaml.py+++ b/cyberdrop_dl/utils/yaml.py@@ -65,13 +65,13 @@ def load(file: Path, *, create: bool = False) -> dict:def handle_validation_error(e: ValidationError, *, title: str | None = None, sources: dict[str, Path] | None = None):- logger_startup = logging.getLogger("cyberdrop_dl_startup")+ startup_logger = logging.getLogger("cyberdrop_dl_startup")error_count = e.error_count()source = sources.get(e.title) if sources else Nonetitle = title or e.titlesource = f"from {source.resolve()}" if source else ""msg = f"Found {error_count} error{'s' if error_count>1 else ''} parsing {title} {source}"- logger_startup.error(msg)+ startup_logger.error(msg)for error in e.errors(include_url=False):loc = ".".join(map(str, error["loc"]))if title == "CLI arguments":@@ -81,6 +81,6 @@ def handle_validation_error(e: ValidationError, *, title: str | None = None, souloc = f"--{loc}"msg = f"Value of '{loc}' is invalid:\n"msg += f" {error['msg']} (input_value='{error['input']}', input_type='{error['type']}')\n"- logger_startup.error(msg)- logger_startup.error(VALIDATION_ERROR_FOOTER)+ startup_logger.error(msg)+ startup_logger.error(VALIDATION_ERROR_FOOTER)sys.exit(1)