Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: make apprise an optional dependency (#1615)

NTFSvolume029619ab6649
diff --git a/cyberdrop_dl/dependencies/__init__.py b/cyberdrop_dl/dependencies/__init__.py
index 5b3618240..08ea8e5ee 100644
--- a/cyberdrop_dl/dependencies/__init__.py
+++ b/cyberdrop_dl/dependencies/__init__.py
@@ -1,3 +1,14 @@
+from typing import TYPE_CHECKING
+
from . import _browser_cookie3 as browser_cookie3
-__all__ = ["browser_cookie3"]
+if TYPE_CHECKING:
+ import apprise
+
+else:
+ try:
+ import apprise
+ except ImportError:
+ apprise = None
+
+__all__ = ["apprise", "browser_cookie3"]
diff --git a/cyberdrop_dl/utils/apprise.py b/cyberdrop_dl/utils/apprise.py
index 0febe43cf..654d3c0ee 100644
--- a/cyberdrop_dl/utils/apprise.py
+++ b/cyberdrop_dl/utils/apprise.py
@@ -11,12 +11,12 @@ from io import StringIO
from pathlib import Path
from typing import TYPE_CHECKING, Any
-import apprise
import rich
from pydantic import ValidationError
from rich.text import Text
from cyberdrop_dl import constants
+from cyberdrop_dl.dependencies import apprise
from cyberdrop_dl.models import AppriseURLModel
from cyberdrop_dl.utils.logger import log, log_debug, log_spacer
from cyberdrop_dl.utils.yaml import handle_validation_error
@@ -24,12 +24,6 @@ from cyberdrop_dl.utils.yaml import handle_validation_error
if TYPE_CHECKING:
from cyberdrop_dl.managers.manager import Manager
-DEFAULT_APPRISE_MESSAGE: dict[str, Any] = {
- "body": "Finished downloading. Enjoy :)",
- "title": "Cyberdrop-DL",
- "body_format": apprise.NotifyFormat.TEXT,
-}
-
@dataclass
class AppriseURL:
@@ -42,7 +36,7 @@ class AppriseURL:
return f"{','.join(tags)}{'=' if tags else ''}{self.url}"
-OS_URLS = ["windows://", "macosx://", "dbus://", "qt://", "glib://", "kde://"]
+_OS_URLS = ["windows://", "macosx://", "dbus://", "qt://", "glib://", "kde://"]
class LogLevel(IntEnum):
@@ -54,7 +48,7 @@ class LogLevel(IntEnum):
CRITICAL = 50
-LOG_LEVEL_NAMES = [x.name for x in LogLevel]
+_LOG_LEVEL_NAMES = [x.name for x in LogLevel]
@dataclass
@@ -74,6 +68,7 @@ def get_apprise_urls(*, file: Path | None = None, urls: list[str] | None = None)
Returns:
list[AppriseURL] | None: A list of processed Apprise URLs, or None if no valid URLs are found.
"""
+
if not (urls or file):
raise ValueError("Neither url of file were supplied")
if urls and file:
@@ -87,9 +82,11 @@ def get_apprise_urls(*, file: Path | None = None, urls: list[str] | None = None)
if not urls:
return []
+ if apprise is None:
+ log("Found apprise URLs for notifications but apprise is not installed. Ignoring", 30)
+ return []
try:
return _simplify_urls([AppriseURLModel.model_validate({"url": url}) for url in set(urls)])
- AppriseURLModel.model_construct()
except ValidationError as e:
handle_validation_error(e, title="Apprise", file=file)
@@ -101,7 +98,7 @@ def _simplify_urls(apprise_urls: list[AppriseURLModel]) -> list[AppriseURL]:
valid_tags = {"no_logs", "attach_logs", "simplified"}
def use_simplified(url: str) -> bool:
- special_urls = OS_URLS
+ special_urls = _OS_URLS
return any(key in url.casefold() for key in special_urls)
for apprise_url in apprise_urls:
@@ -161,7 +158,7 @@ def _parse_apprise_logs(apprise_logs: str) -> list[LogLine]:
parsed_lines: list[LogLine] = []
for line in lines:
log_level = line[0:8].strip()
- if log_level and log_level not in LOG_LEVEL_NAMES: # pragma: no cover
+ if log_level and log_level not in _LOG_LEVEL_NAMES: # pragma: no cover
current_line.msg += f"\n{line}"
continue
@@ -226,7 +223,11 @@ async def send_apprise_notifications(manager: Manager) -> tuple[constants.Notifi
def prepare_notifications():
for tag, extras in notifications_to_send.items():
- msg = DEFAULT_APPRISE_MESSAGE | extras
+ msg = {
+ "body": "Finished downloading. Enjoy :)",
+ "title": "Cyberdrop-DL",
+ "body_format": apprise.NotifyFormat.TEXT,
+ } | extras
yield notify(tag, msg)
results = dict(await asyncio.gather(*prepare_notifications()))
diff --git a/docs/reference/notifications.md b/docs/reference/notifications.md
index cedb4ad83..b1179aea9 100644
--- a/docs/reference/notifications.md
+++ b/docs/reference/notifications.md
@@ -21,6 +21,16 @@ Optionally, you can add the tag `attach_logs=` as a prefix to your webhook url.
Cyberdrop-DL uses [Apprise](https://github.com/caronc/apprise) to send notifications to any of the services than they support.
+{% hint style="info" %}
+`apprise` is an an optional dependency; It's not installed by default with CDL. To install `cyberdrop-dl` with `apprise`, especify it as an extra while installing cyberdrop:
+ex:
+
+```shell
+uv tool install cyberdrop-dl-patched[apprise]
+```
+
+{% endhint %}
+
### How to setup Apprise
To send notifications via Apprise, you need to create an `apprise.txt` file inside `AppData/Configs/<config_name>`, where `<config_name>` if the config you want to use. The file must contain a list of URLs and they must be in the format of one of the supported apprise services.
diff --git a/poetry.lock b/poetry.lock
index 42ccd654f..6bb519914 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -246,7 +246,7 @@ version = "1.9.7"
description = "Push Notifications that work with just about every platform!"
optional = false
python-versions = ">=3.9"
-groups = ["main"]
+groups = ["extras"]
files = [
{file = "apprise-1.9.7-py3-none-any.whl", hash = "sha256:c7640a81a1097685de66e0508e3da89f49235d566cb44bbead1dd98419bf5ee3"},
{file = "apprise-1.9.7.tar.gz", hash = "sha256:2f73cc1e0264fb119fdb9b7cde82e8fde40a0f531ac885d8c6f0cf0f6e13aec2"},
@@ -631,7 +631,7 @@ version = "2026.1.4"
description = "Python package for providing Mozilla's CA Bundle."
optional = false
python-versions = ">=3.7"
-groups = ["main"]
+groups = ["main", "extras"]
files = [
{file = "certifi-2026.1.4-py3-none-any.whl", hash = "sha256:9943707519e4add1115f44c2bc244f782c0249876bf51b6599fee1ffbedd685c"},
{file = "certifi-2026.1.4.tar.gz", hash = "sha256:ac726dd470482006e014ad384921ed6438c457018f4b3d204aea4281258b2120"},
@@ -764,7 +764,7 @@ version = "3.4.4"
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
optional = false
python-versions = ">=3.7"
-groups = ["main"]
+groups = ["main", "extras"]
files = [
{file = "charset_normalizer-3.4.4-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:e824f1492727fa856dd6eda4f7cee25f8518a12f3c4a56a74e8095695089cf6d"},
{file = "charset_normalizer-3.4.4-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4bd5d4137d500351a30687c2d3971758aac9a19208fc110ccb9d7188fbe709e8"},
@@ -887,7 +887,7 @@ version = "8.3.1"
description = "Composable command line interface toolkit"
optional = false
python-versions = ">=3.10"
-groups = ["main"]
+groups = ["extras"]
files = [
{file = "click-8.3.1-py3-none-any.whl", hash = "sha256:981153a64e25f12d547d3426c367a4857371575ee7ad18df2a6183ab0545b2a6"},
{file = "click-8.3.1.tar.gz", hash = "sha256:12ff4785d337a1bb490bb7e9c2b1ee5da3112e94a8622f26a6c77f5d2fc6842a"},
@@ -902,12 +902,12 @@ version = "0.4.6"
description = "Cross-platform colored terminal text."
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
-groups = ["main", "dev", "test"]
+groups = ["dev", "extras", "test"]
files = [
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
]
-markers = {main = "platform_system == \"Windows\"", test = "sys_platform == \"win32\""}
+markers = {extras = "platform_system == \"Windows\"", test = "sys_platform == \"win32\""}
[[package]]
name = "coverage"
@@ -1264,7 +1264,7 @@ version = "3.11"
description = "Internationalized Domain Names in Applications (IDNA)"
optional = false
python-versions = ">=3.8"
-groups = ["main"]
+groups = ["main", "extras"]
files = [
{file = "idna-3.11-py3-none-any.whl", hash = "sha256:771a87f49d9defaf64091e6e6fe9c18d4833f140bd19464795bc32d966ca37ea"},
{file = "idna-3.11.tar.gz", hash = "sha256:795dafcc9c04ed0c1fb032c2aa73654d8e8c5023a7df64a53f39190ada629902"},
@@ -1347,18 +1347,18 @@ files = [
[[package]]
name = "markdown"
-version = "3.10"
+version = "3.10.1"
description = "Python implementation of John Gruber's Markdown."
optional = false
python-versions = ">=3.10"
-groups = ["main"]
+groups = ["extras"]
files = [
- {file = "markdown-3.10-py3-none-any.whl", hash = "sha256:b5b99d6951e2e4948d939255596523444c0e677c669700b1d17aa4a8a464cb7c"},
- {file = "markdown-3.10.tar.gz", hash = "sha256:37062d4f2aa4b2b6b32aefb80faa300f82cc790cb949a35b8caede34f2b68c0e"},
+ {file = "markdown-3.10.1-py3-none-any.whl", hash = "sha256:867d788939fe33e4b736426f5b9f651ad0c0ae0ecf89df0ca5d1176c70812fe3"},
+ {file = "markdown-3.10.1.tar.gz", hash = "sha256:1c19c10bd5c14ac948c53d0d762a04e2fa35a6d58a6b7b1e6bfcbe6fefc0001a"},
]
[package.extras]
-docs = ["mdx_gh_links (>=0.2)", "mkdocs (>=1.6)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python]"]
+docs = ["mdx_gh_links (>=0.2)", "mkdocs (>=1.6)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python] (>=0.28.3)"]
testing = ["coverage", "pyyaml"]
[[package]]
@@ -1587,7 +1587,7 @@ version = "3.3.1"
description = "A generic, spec-compliant, thorough implementation of the OAuth request-signing logic"
optional = false
python-versions = ">=3.8"
-groups = ["main"]
+groups = ["extras"]
files = [
{file = "oauthlib-3.3.1-py3-none-any.whl", hash = "sha256:88119c938d2b8fb88561af5f6ee0eec8cc8d552b7bb1f712743136eb7523b7a1"},
{file = "oauthlib-3.3.1.tar.gz", hash = "sha256:0f0f8aa759826a193cf66c12ea1af1637f87b9b4622d46e866952bb022e538c9"},
@@ -2324,7 +2324,7 @@ version = "6.0.3"
description = "YAML parser and emitter for Python"
optional = false
python-versions = ">=3.8"
-groups = ["main", "dev"]
+groups = ["main", "dev", "extras"]
files = [
{file = "PyYAML-6.0.3-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:c2514fceb77bc5e7a2f7adfaa1feb2fb311607c9cb518dbc378688ec73d8292f"},
{file = "PyYAML-6.0.3-cp38-cp38-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9c57bb8c96f6d1808c030b1687b9b5fb476abaa47f0db9c0101f5e9f394e97f4"},
@@ -2548,7 +2548,7 @@ version = "2.32.5"
description = "Python HTTP for Humans."
optional = false
python-versions = ">=3.9"
-groups = ["main"]
+groups = ["main", "extras"]
files = [
{file = "requests-2.32.5-py3-none-any.whl", hash = "sha256:2462f94637a34fd532264295e186976db0f5d453d1cdd31473c85a6a161affb6"},
{file = "requests-2.32.5.tar.gz", hash = "sha256:dbba0bac56e100853db0ea71b82b4dfd5fe2bf6d3754a8893c3af500cec7d7cf"},
@@ -2570,7 +2570,7 @@ version = "2.0.0"
description = "OAuthlib authentication support for Requests."
optional = false
python-versions = ">=3.4"
-groups = ["main"]
+groups = ["extras"]
files = [
{file = "requests-oauthlib-2.0.0.tar.gz", hash = "sha256:b3dffaebd884d8cd778494369603a9e7b58d29111bf6b41bdc2dcd87203af4e9"},
{file = "requests_oauthlib-2.0.0-py2.py3-none-any.whl", hash = "sha256:7dd8a5c40426b779b0868c404bdef9768deccf22749cde15852df527e6269b36"},
@@ -2740,7 +2740,7 @@ version = "2025.3"
description = "Provider of IANA time zone data"
optional = false
python-versions = ">=2"
-groups = ["main"]
+groups = ["main", "extras"]
markers = "platform_system == \"Windows\""
files = [
{file = "tzdata-2025.3-py2.py3-none-any.whl", hash = "sha256:06a47e5700f3081aab02b2e513160914ff0694bce9947d6b76ebd6bf57cfc5d1"},
@@ -2791,7 +2791,7 @@ version = "2.6.3"
description = "HTTP library with thread-safe connection pooling, file post, and more."
optional = false
python-versions = ">=3.9"
-groups = ["main"]
+groups = ["main", "extras"]
files = [
{file = "urllib3-2.6.3-py3-none-any.whl", hash = "sha256:bf272323e553dfb2e87d9bfd225ca7b0f467b919d7bbd355436d3fd37cb0acd4"},
{file = "urllib3-2.6.3.tar.gz", hash = "sha256:1b62b6884944a57dbe321509ab94fd4d3b307075e0c2eae991ac71ee15ad38ed"},
@@ -3134,4 +3134,4 @@ propcache = ">=0.2.1"
[metadata]
lock-version = "2.1"
python-versions = ">=3.11,<4"
-content-hash = "4d1a06f956ded354d045cbae3c0c2aa33635da95e770f90fcddb304a8a04570b"
+content-hash = "545f4d359a61658ab8960d3303e2586c9b49dc8c7dc0a0561cd197d298fe1156"
diff --git a/pyproject.toml b/pyproject.toml
index 44e92bb77..8483ccc83 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -7,7 +7,6 @@ dependencies = [
"aiohttp[speedups] >=3.13.3",
"aiolimiter >=1.2.1",
"aiosqlite==0.17.0",
- "apprise >=1.9.6",
"asyncpraw >=7.8.1",
"beautifulsoup4 >=4.14.3",
"certifi >=2026.1.4",
@@ -59,6 +58,9 @@ dev = [
"ruff>=0.14.11",
"tox>=4.34.1"
]
+extras = [
+ "apprise >=1.9.7"
+]
test = [
"pytest-asyncio>=1.3.0",
"pytest-cov>=7.0.0",