Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: reduce max log file size to 20MB
NTFSvolume3c8c1bc3ac7e
diff --git a/cyberdrop_dl/logs.py b/cyberdrop_dl/logs.pyindex 0d83b93b5..a75a3ceb6 100644--- a/cyberdrop_dl/logs.py+++ b/cyberdrop_dl/logs.py@@ -44,6 +44,7 @@ _DEFAULT_CONSOLE_WIDTH = 240_MAIN_LOG_LISTENER: ContextVar[QueueListener] = ContextVar("_MAIN_LOG_LISTENER")_CONSOLE_LOG_LISTENER: ContextVar[QueueListener] = ContextVar("_CONSOLE_LOG_LISTENER")_LOG_TO_CONSOLE: ContextVar[bool] = ContextVar("LOG_TO_CONSOLE", default=True)+MAX_ATTACHMENT_SIZE = 20 * 1e6class HandlerName(StrEnum):diff --git a/cyberdrop_dl/utils/apprise.py b/cyberdrop_dl/utils/apprise.pyindex a061baa1f..6a55d9055 100644--- a/cyberdrop_dl/utils/apprise.py+++ b/cyberdrop_dl/utils/apprise.py@@ -8,7 +8,7 @@ from typing import TYPE_CHECKINGfrom cyberdrop_dl import aiofrom cyberdrop_dl.constants import MAIN_LOG_FILE-from cyberdrop_dl.logs import borrow_logger, export_logs, log_spacer+from cyberdrop_dl.logs import MAX_ATTACHMENT_SIZE, borrow_logger, export_logs, log_spacerif TYPE_CHECKING:from collections.abc import AsyncGenerator, Iterable, Sequence@@ -82,7 +82,7 @@ async def _temp_copy_of_main_log() -> AsyncGenerator[Path | None]:async with aio.temp_dir() as temp_dir:temp_file = temp_dir / MAIN_LOG_FILE.get().nametry:- logs = await asyncio.to_thread(export_logs, size_limit=25 * 1e6)+ logs = await asyncio.to_thread(export_logs, size_limit=MAX_ATTACHMENT_SIZE)except Exception:logger.exception("Unable to attach main log for apprise notifications")yielddiff --git a/cyberdrop_dl/webhook.py b/cyberdrop_dl/webhook.pyindex 8dab6c31f..0ee613fab 100644--- a/cyberdrop_dl/webhook.py+++ b/cyberdrop_dl/webhook.py@@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Anyimport aiohttpfrom cyberdrop_dl.constants import MAIN_LOG_FILE-from cyberdrop_dl.logs import export_logs, log_spacer+from cyberdrop_dl.logs import MAX_ATTACHMENT_SIZE, export_logs, log_spacerif TYPE_CHECKING:import yarl@@ -19,25 +19,30 @@ logger = logging.getLogger(__name__)async def notify(webhook: AppriseURL, body: str) -> None:+ await _notify(+ url=str(webhook.url.get_secret_value()),+ body=body,+ attach_logs=webhook.attach_logs,+ )+++async def _notify(url: str, body: str, *, attach_logs: bool) -> None:log_spacer()- url, form = await _prepare(webhook)+ form = aiohttp.FormData()+ if attach_logs:+ await _attach_logs(form, size_limit=MAX_ATTACHMENT_SIZE - len(body.encode()))+ form.add_field("username", "cyberdrop-dl")form.add_field("content", body)await _send_notification(url, form)-async def _prepare(webhook: AppriseURL) -> tuple[str, aiohttp.FormData]:- url = str(webhook.url.get_secret_value())- form = aiohttp.FormData()- if webhook.attach_logs:- try:- logs = await asyncio.to_thread(export_logs, size_limit=25 * 1e6)- except Exception:- logger.exception("Unable to attach log for webhook notification")- else:- form.add_field("file", logs, filename=MAIN_LOG_FILE.get().name)-- form.add_field("username", "cyberdrop-dl")- return url, form+async def _attach_logs(form: aiohttp.FormData, size_limit: float) -> None:+ try:+ logs = await asyncio.to_thread(export_logs, size_limit=size_limit)+ except Exception:+ logger.exception("Unable to attach log for webhook notification")+ else:+ form.add_field("file", logs, filename=MAIN_LOG_FILE.get().name)async def _send_notification(url: yarl.URL | str, form: aiohttp.FormData) -> None: