Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: bring back debug crawlers

NTFSvolume8a1e6ac03bba
diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.py
index a56af99c5..366a8234f 100644
--- a/cyberdrop_dl/crawlers/crawler.py
+++ b/cyberdrop_dl/crawlers/crawler.py
@@ -20,6 +20,7 @@ from typing import TYPE_CHECKING, Any, ClassVar, Concatenate, Final, Literal, Pa
from aiolimiter import AsyncLimiter
from typing_extensions import deprecated
+from cyberdrop_dl import env
from cyberdrop_dl.clients import HTTPClient, HTTPClientProxy
from cyberdrop_dl.crawlers._hls import HLSParser
from cyberdrop_dl.downloader.downloader import Downloader
@@ -214,6 +215,7 @@ class Crawler(HTTPClientProxy, HLSParser, ABC):
cls,
is_abc: bool = False,
is_generic: bool = False,
+ is_debug: bool = False,
db_path: Literal["url", "name", "path", "path_qs", "path_qs_frag", "path_frag"] | None = None,
**kwargs,
) -> None:
@@ -233,17 +235,21 @@ class Crawler(HTTPClientProxy, HLSParser, ABC):
cls.SUPPORTED_PATHS = _sort_supported_paths(cls.SUPPORTED_PATHS) # pyright: ignore[reportConstantRedefinition]
cls.IS_ABC: bool = is_abc
+ add_to_register = bool(not is_debug or (is_debug and env.ENABLE_DEBUG_CRAWLERS))
+
if db_path:
cls.__db_path__ = staticmethod(_DB_PATH_BUILDERS[db_path])
if cls.IS_GENERIC:
cls.SCRAPE_MAPPER_KEYS = ()
cls.INFO: CrawlerInfo = CrawlerInfo.generic(cls.NAME, cls.SUPPORTED_PATHS)
- Registry.generic.add(cls)
+ if add_to_register:
+ Registry.generic.add(cls)
return
if is_abc:
- Registry.abc.add(cls)
+ if add_to_register:
+ Registry.abc.add(cls)
return
if cls.NAME != "RealDebrid":
@@ -266,7 +272,8 @@ class Crawler(HTTPClientProxy, HLSParser, ABC):
supported_domains=_make_wiki_supported_domains(cls.SCRAPE_MAPPER_KEYS),
supported_paths=cls.SUPPORTED_PATHS,
)
- Registry.concrete.add(cls)
+ if add_to_register:
+ Registry.concrete.add(cls)
def __init_downloader__(self) -> None:
self.downloader = dl = Downloader(self.manager, self.DOMAIN)
diff --git a/cyberdrop_dl/crawlers/xenforo/simpcity.py b/cyberdrop_dl/crawlers/xenforo/simpcity.py
index 108f42299..e2068f89d 100644
--- a/cyberdrop_dl/crawlers/xenforo/simpcity.py
+++ b/cyberdrop_dl/crawlers/xenforo/simpcity.py
@@ -7,7 +7,7 @@ from cyberdrop_dl.url_objects import AbsoluteHttpURL
from .xenforo import XenforoCrawler
-class SimpCityCrawler(XenforoCrawler):
+class SimpCityCrawler(XenforoCrawler, is_debug=True):
PRIMARY_URL: ClassVar[AbsoluteHttpURL] = AbsoluteHttpURL("https://simpcity.cr")
DOMAIN: ClassVar[str] = "simpcity"
FOLDER_DOMAIN: ClassVar[str] = "SimpCity"
diff --git a/cyberdrop_dl/env.py b/cyberdrop_dl/env.py
index 7e8688292..5512ab704 100644
--- a/cyberdrop_dl/env.py
+++ b/cyberdrop_dl/env.py
@@ -1,12 +1,16 @@
+import hashlib
import os
ALL_VARS: dict[str, str | None] = {}
os.environ["PYDANTIC_ERRORS_INCLUDE_URL"] = "0"
-def _env(name: str) -> str | None:
+def _env(name: str, *, censor: bool = True) -> str | None:
full_name = "CDL_" + name
- value = ALL_VARS[full_name] = os.getenv(full_name)
+ value = os.getenv(full_name)
+ if censor and value:
+ value = hashlib.sha256(value.encode("utf-8")).hexdigest()
+ ALL_VARS[full_name] = value
return value
@@ -25,6 +29,10 @@ DEBUG_MODE = bool(
or os.getenv("PYCHARM_HOSTED")
or os.getenv("TERM_PROGRAM") in ("vscode", "zed")
)
+ENABLE_DEBUG_CRAWLERS = (
+ _env("ENABLE_DEBUG_CRAWLERS", censor=True) == "d396ab8c85fcb1fecd22c8d9b58acf944a44e6d35014e9dd39e42c9a64091eda"
+)
+
NO_PLUGINS = bool(_env("NO_PLUGINS"))
EDITOR = os.getenv("EDITOR")
@@ -38,5 +46,5 @@ ONEPACE_PREFER_DUB = bool(_env("ONEPACE_PREFER_DUB"))
ALL_VARS = dict(sorted(ALL_VARS.items())) # pyright: ignore[reportConstantRedefinition]
ALL_VARS_RESOLVED = dict(
- sorted((k, v) for k, v in globals().items() if k not in ("os", "ALL_VARS") and not k.startswith("_"))
+ sorted((k, v) for k, v in globals().items() if k not in ("os", "hashlib", "ALL_VARS") and not k.startswith("_"))
)