Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: update formatting of log messages (#1216)
NTFSvolume0a738053f9f3
diff --git a/cyberdrop_dl/clients/download_client.py b/cyberdrop_dl/clients/download_client.pyindex bcef05823..cf6b09ff2 100644--- a/cyberdrop_dl/clients/download_client.py+++ b/cyberdrop_dl/clients/download_client.py@@ -458,7 +458,7 @@ class DownloadClient:if media_item.partial_file.stat().st_size == media_item.filesize:if media_item.complete_file.exists():log(- f"Found conflicting complete file {media_item.complete_file} locally, iterating filename",+ f"Found conflicting complete file '{media_item.complete_file}' locally, iterating filename",30,)new_complete_filename, new_partial_file = await self.iterate_filename(@@ -474,15 +474,15 @@ class DownloadClient:proceed = Falsemedia_item.partial_file.rename(media_item.complete_file)log(- f"Renaming found partial file {media_item.partial_file} to complete file {media_item.complete_file}"+ f"Renaming found partial file '{media_item.partial_file}' to complete file {media_item.complete_file}")elif media_item.complete_file.exists():if media_item.complete_file.stat().st_size == media_item.filesize:- log(f"Found complete file {media_item.complete_file} locally, skipping download")+ log(f"Found complete file '{media_item.complete_file}' locally, skipping download")proceed = Falseelse:log(- f"Found conflicting complete file {media_item.complete_file} locally, iterating filename",+ f"Found conflicting complete file '{media_item.complete_file}' locally, iterating filename",30,)media_item.complete_file, media_item.partial_file = await self.iterate_filename(diff --git a/cyberdrop_dl/clients/hash_client.py b/cyberdrop_dl/clients/hash_client.pyindex 7988605bb..0fd78da2b 100644--- a/cyberdrop_dl/clients/hash_client.py+++ b/cyberdrop_dl/clients/hash_client.py@@ -75,7 +75,7 @@ class HashClient:)await self.save_hash_data(media_item, hash)except Exception as e:- log(f"After hash processing failed: {media_item.complete_file} with error {e}", 40, exc_info=True)+ log(f"After hash processing failed: '{media_item.complete_file}' with error {e}", 40, exc_info=True)async def update_db_and_retrive_hash(self, file: Path | str, original_filename: str | None = None, referer: URL | None = None@@ -123,7 +123,7 @@ class HashClient:referer,)except Exception as e:- log(f"Error hashing {file} : {e}", 40, exc_info=True)+ log(f"Error hashing '{file}' : {e}", 40, exc_info=True)else:return hashdiff --git a/cyberdrop_dl/crawlers/_forum.py b/cyberdrop_dl/crawlers/_forum.pyindex 6d2cca9d9..bd49b4d18 100644--- a/cyberdrop_dl/crawlers/_forum.py+++ b/cyberdrop_dl/crawlers/_forum.py@@ -504,7 +504,7 @@ class HTMLMessageBoardCrawler(MessageBoardCrawler, is_abc=True):if seen:self.log(f"[{self.FOLDER_DOMAIN}] post #{post.id} {stats = }")if duplicates:- msg = f"Found duplicate links in post {scrape_item.url}. Selectors are too generic: {duplicates}"+ msg = f"Found duplicate links in post {scrape_item.parent}. Selectors are too generic: {duplicates}"self.log(msg, bug=True)await asyncio.gather(*tasks)if max_children_error is not None:diff --git a/cyberdrop_dl/director.py b/cyberdrop_dl/director.pyindex 04d3c7631..6112eeb8b 100644--- a/cyberdrop_dl/director.py+++ b/cyberdrop_dl/director.py@@ -217,7 +217,7 @@ def _setup_main_logger(manager: Manager, config_name: str) -> None:log(f"Picking new config: '{config_name}' ...", 20)try:manager.config_manager.change_config(config_name)- log(f"Changed config to {config_name}...", 20)+ log(f"Changed config to '{config_name}'...", 20)finally:logger.removeHandler(queued_logger.handler)queued_logger.stop()diff --git a/cyberdrop_dl/managers/manager.py b/cyberdrop_dl/managers/manager.pyindex c759d997f..aa6f08854 100644--- a/cyberdrop_dl/managers/manager.py+++ b/cyberdrop_dl/managers/manager.py@@ -208,7 +208,7 @@ class Manager:args_info = ("Starting Cyberdrop-DL Process",f"Running Version: {__version__}",- f"System Info:{system_info}",+ f"System Info: {system_info}",f"Using Config: {self.config_manager.loaded_config}",f"Using Config File: {self.config_manager.settings}",f"Using Input File: {self.path_manager.input_file}",diff --git a/cyberdrop_dl/managers/storage_manager.py b/cyberdrop_dl/managers/storage_manager.pyindex 222b44125..c98ff2615 100644--- a/cyberdrop_dl/managers/storage_manager.py+++ b/cyberdrop_dl/managers/storage_manager.py@@ -77,12 +77,12 @@ class StorageManager:@propertydef _simplified_stats(self) -> str:- def simplify(mount_stats: MountStats) -> str:+ def stringify(mount_stats: MountStats) -> str:free_space = mount_stats.free_space.human_readable(decimal=True)stats_as_dict = asdict(mount_stats.partition) | {"free_space": free_space}return ", ".join(f"'{k}': '{v}'" for k, v in stats_as_dict.items())- stats_as_str = "\n".join(f" {simplify(mount_stats)}" for mount_stats in self.get_used_mounts_stats())+ stats_as_str = "\n".join(f" {stringify(mount_stats)}" for mount_stats in self.get_used_mounts_stats())return f"Storage status:\n {stats_as_str}"def get_used_mounts_stats(self) -> list[MountStats]:diff --git a/cyberdrop_dl/utils/logger.py b/cyberdrop_dl/utils/logger.pyindex ed3475240..26007d716 100644--- a/cyberdrop_dl/utils/logger.py+++ b/cyberdrop_dl/utils/logger.py@@ -5,7 +5,7 @@ import loggingimport queuefrom logging.handlers import QueueHandler, QueueListenerfrom pathlib import Path-from typing import IO, TYPE_CHECKING, Any+from typing import IO, TYPE_CHECKINGfrom rich._log_render import LogRenderfrom rich.console import Console, Group@@ -208,10 +208,10 @@ class RedactedConsole(Console):return _redact_message(output)-def process_log_msg(message: dict[str, Any] | Exception | str) -> str:+def process_log_msg(message: object) -> object:if isinstance(message, dict):return json.dumps(message, indent=4, ensure_ascii=False)- return str(message)+ return messagedef create_rich_log_msg(msg: str, level: int = 10) -> Text:@@ -220,19 +220,17 @@ def create_rich_log_msg(msg: str, level: int = 10) -> Text:return rich_level + indent_string(msg)-def log(- message: dict[str, Any] | Exception | str, level: int = 10, prefix: str = "", bug: bool = False, **kwargs-) -> None:+def log(message: object, level: int = 10, bug: bool = False, **kwargs) -> None:"""Simple logging function."""- msg = prefix + process_log_msg(message)+ msg = process_log_msg(message)log_debug(msg, level, **kwargs)if bug:- msg = msg.rstrip() + f". Please open a bug report at {NEW_ISSUE_URL}"+ msg = f"{msg}. Please open a bug report at {NEW_ISSUE_URL}"level = 30logger.log(level, msg, **kwargs)-def log_debug(message: dict[str, Any] | Exception | str, level: int = 10, **kwargs) -> None:+def log_debug(message: object, level: int = 10, **kwargs) -> None:"""Simple logging function."""if env.DEBUG_VAR:msg = process_log_msg(message)diff --git a/cyberdrop_dl/utils/sorting.py b/cyberdrop_dl/utils/sorting.pyindex 5a1c349ba..54d6618a9 100644--- a/cyberdrop_dl/utils/sorting.py+++ b/cyberdrop_dl/utils/sorting.py@@ -140,7 +140,7 @@ class Sorter:bitrate = int(float(props.get("bit_rate", 0))) or Nonesample_rate = int(float(props.get("sample_rate", 0))) or Noneexcept (RuntimeError, CalledProcessError):- log(f"Unable to get audio properties of {file}")+ log(f"Unable to get audio properties of '{file}'")if await self._process_file_move(file,@@ -163,7 +163,7 @@ class Sorter:width, height = image.sizeresolution = f"{width}x{height}"except (PIL.UnidentifiedImageError, PIL.Image.DecompressionBombError): # type: ignore- log(f"Unable to get some image properties of {file}")+ log(f"Unable to get some image properties of '{file}'")if await self._process_file_move(file,@@ -197,7 +197,7 @@ class Sorter:else None)except (RuntimeError, CalledProcessError):- log(f"Unable to get some video properties of {file}")+ log(f"Unable to get some video properties of '{file}'")if fps is not None:fps = str(int(fps)) if fps.is_integer() else f"{fps:.2f}"diff --git a/cyberdrop_dl/utils/utilities.py b/cyberdrop_dl/utils/utilities.pyindex ff3cbe9bc..4eab1539e 100644--- a/cyberdrop_dl/utils/utilities.py+++ b/cyberdrop_dl/utils/utilities.py@@ -70,8 +70,8 @@ class Dataclass(Protocol):def error_handling_wrapper(- func: Callable[Concatenate[CrawerOrDownloader, Origin, P], R | Coroutine[None, None, R]],-) -> Callable[Concatenate[CrawerOrDownloader, Origin, P], Coroutine[None, None, R | None]]:+ func: Callable[Concatenate[CrawerOrDownloader, Origin, P], R | Coroutine[Any, Any, R]],+) -> Callable[Concatenate[CrawerOrDownloader, Origin, P], Coroutine[Any, Any, R | None]]:"""Wrapper handles errors for url scraping."""@wraps(func)