Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
perf: send all apprise notifications at once (#1316)
NTFSvolume38ae06dc6376
diff --git a/cyberdrop_dl/utils/apprise.py b/cyberdrop_dl/utils/apprise.pyindex a032fc2c3..48ab48ca3 100644--- a/cyberdrop_dl/utils/apprise.py+++ b/cyberdrop_dl/utils/apprise.py@@ -1,5 +1,6 @@from __future__ import annotations+import asyncioimport jsonimport shutilimport sys@@ -8,7 +9,7 @@ from dataclasses import dataclassfrom enum import IntEnumfrom io import StringIOfrom pathlib import Path-from typing import TYPE_CHECKING+from typing import TYPE_CHECKING, Anyimport appriseimport rich@@ -23,7 +24,7 @@ from cyberdrop_dl.utils.yaml import handle_validation_errorif TYPE_CHECKING:from cyberdrop_dl.managers.manager import Manager-DEFAULT_APPRISE_MESSAGE = {+DEFAULT_APPRISE_MESSAGE: dict[str, Any] = {"body": "Finished downloading. Enjoy :)","title": "Cyberdrop-DL","body_format": apprise.NotifyFormat.TEXT,@@ -196,7 +197,6 @@ async def send_apprise_notifications(manager: Manager) -> tuple[constants.Notifiapprise_obj.add(apprise_url.url, tag=list(apprise_url.tags))main_log = manager.path_manager.main_log- results = {}all_urls = [x.raw_url for x in apprise_urls]log_lines = []@@ -207,7 +207,7 @@ async def send_apprise_notifications(manager: Manager) -> tuple[constants.Notifitemp_dir = Path(temp_dir)assert isinstance(capture, StringIO)temp_main_log = temp_dir / main_log.name- notifications_to_send = {+ notifications_to_send: dict[str, dict[str, Any]] = {"no_logs": {"body": text.plain},"attach_logs": {"body": text.plain},"simplified": {},@@ -220,9 +220,16 @@ async def send_apprise_notifications(manager: Manager) -> tuple[constants.Notifiexcept OSError:log(attach_file_failed_msg, 40)- for tag, extras in notifications_to_send.items():- msg = DEFAULT_APPRISE_MESSAGE | extras- results[tag] = await apprise_obj.async_notify(**msg, tag=tag)+ async def notify(tag: str, msg: dict[str, Any]) -> tuple[str, bool | None]:+ result = await apprise_obj.async_notify(**msg, tag=tag)+ return tag, result++ def prepare_notifications():+ for tag, extras in notifications_to_send.items():+ msg = DEFAULT_APPRISE_MESSAGE | extras+ yield notify(tag, msg)++ results = dict(await asyncio.gather(*prepare_notifications()))apprise_logs = capture.getvalue()result, new_log_lines = _process_results(all_urls, results, apprise_logs)