Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: detect Gandalf bot protection

NTFSvolumea591ea7a20d3
diff --git a/cyberdrop_dl/ddos_guard.py b/cyberdrop_dl/ddos_guard.py
index 2649c31fa..b68606e45 100644
--- a/cyberdrop_dl/ddos_guard.py
+++ b/cyberdrop_dl/ddos_guard.py
@@ -147,6 +147,16 @@ class BasedFlare(DDosGuard):
return bool(soup.select_one(cls.SELECTOR))
+class Gandalf(DDosGuard):
+ # https://gandalf.nerdvpn.de/
+ # https://git.nerdvpn.de/NerdVPN.de/gandalf
+ TITLES = ("Gandalf",)
+ SELECTOR = "main#g-container " + css.where(
+ "form[action$='/.gandalf/confirm']",
+ "#g-title:-soup-contains('Gandalf is checking your connection')",
+ )
+
+
class Anubis(DDosGuard):
TITLES = ("Making sure you're not a bot!",)
CHALLENGE = "script#anubis_challenge:-soup-contains(algorithm)"
diff --git a/cyberdrop_dl/utils/css.py b/cyberdrop_dl/utils/css.py
index b7926c943..af96249bd 100644
--- a/cyberdrop_dl/utils/css.py
+++ b/cyberdrop_dl/utils/css.py
@@ -210,6 +210,11 @@ def parse_form(form: Tag, /) -> HTMLForm:
return HTMLForm(cast("HttpMethod", method), action, inputs)
+def where(*selectors: str) -> str:
+ assert len(selectors) >= 2, ":where only makes sense combining 2 or more selectors"
+ return ":where(" + ", ".join(selectors) + ")"
+
+
def soup(content: str, parse_only: tuple[str, ...] | str | None = None) -> BeautifulSoup:
return BeautifulSoup(content, HTML_PARSER, parse_only=SoupStrainer(parse_only) if parse_only is not None else None)