Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: support connecting to JDownloader via their deprecated API
NTFSvolumeb4d1a7786cfc
diff --git a/cyberdrop_dl/clients/jdownloader.py b/cyberdrop_dl/clients/jdownloader.pyindex 1e7e2740f..0f29d64eb 100644--- a/cyberdrop_dl/clients/jdownloader.py+++ b/cyberdrop_dl/clients/jdownloader.py@@ -19,6 +19,12 @@ if TYPE_CHECKING:from cyberdrop_dl.url_objects import AbsoluteHttpURL[email protected](frozen=True, slots=True)+class JDDeprecatedAPI:+ host: str = ""+ port: int = 3128++@dataclasses.dataclass(frozen=True, slots=True)class JDConfig:enabled: bool@@ -28,6 +34,7 @@ class JDConfig:download_dir: Pathautostart: boolwhitelist: tuple[str, ...]+ deprecated_api: JDDeprecatedAPI | None = None@dataclasses.dataclass(slots=True)@@ -41,6 +48,15 @@ class JDownloader:@classmethoddef from_config(cls, config: Config, /) -> Self:download_dir = config.jdownloader.download_folder or config.download_folder+ d_conf = (+ JDDeprecatedAPI(+ host=d_url.host,+ port=d_url.explicit_port or 3128,+ )+ if (d_url := config.jdownloader.deprecated_api)+ else None+ )+return cls(JDConfig(enabled=config.jdownloader.enabled,@@ -50,6 +66,7 @@ class JDownloader:download_dir=download_dir.resolve(),autostart=config.jdownloader.autostart,whitelist=tuple(config.jdownloader.whitelist),+ deprecated_api=d_conf,))@@ -81,14 +98,10 @@ class JDownloader:if not self._enabled or self._device is not None:return- if not all((self.config.username, self.config.password, self.config.device)):- raise JDownloaderError("JDownloader credentials were not provided")-with self._wrap_errors():api = myjdapi.Myjdapi()api.set_app_key("CYBERDROP-DL")- _ = await asyncio.to_thread(api.connect, self.config.username, self.config.password)- self._device = api.get_device(self.config.device)+ self._device = await _get_device(api, self.config)async def connect(self) -> None:try:@@ -119,3 +132,15 @@ class JDownloader:},],)+++async def _get_device(api: myjdapi.Myjdapi, config: JDConfig):+ if config.deprecated_api:+ await asyncio.to_thread(api.direct_connect, config.deprecated_api.host, config.deprecated_api.port)+ return api.get_device()++ if config.username and config.password and config.device:+ await asyncio.to_thread(api.connect, config.username, config.password)+ return api.get_device(config.device)++ raise JDownloaderError("JDownloader credentials were not provided")diff --git a/cyberdrop_dl/config/settings.py b/cyberdrop_dl/config/settings.pyindex ac1f8f9d9..8c9dbcaa5 100644--- a/cyberdrop_dl/config/settings.py+++ b/cyberdrop_dl/config/settings.py@@ -163,6 +163,9 @@ class Jdownloader(ConfigGroup, name=None):enabled: Annotated[bool, _alias("jdownloader")] = False"Send unsupported URLs to Jdownloader"+ deprecated_api: HttpURL | None = None+ "HTTP URL of a local JDownloader instance to connect to via their deprecated API (insecure, default port=3128)"+autostart: bool = False"Immediately start downloads as soon as they are sent"@@ -172,6 +175,12 @@ class Jdownloader(ConfigGroup, name=None):whitelist: set[NonEmptyStr] = Field(default_factory=set)"Only send unsupported URLs from these domains to Jdownloader. An empty list means 'send all URLs'"+ @override+ def model_post_init(self, context: Any, /) -> None:+ super().model_post_init(context)+ if self.deprecated_api and self.deprecated_api.scheme != "http":+ raise ValueError("Deprecated API URL must have an 'http' scheme")+class SortFormats(ConfigModel):_COMMON_FIELDS: ClassVar[set[str]] = {diff --git a/docs/reference/config/jdownloader.md b/docs/reference/config/jdownloader.mdindex 1ff013186..68ab11fc3 100644--- a/docs/reference/config/jdownloader.md+++ b/docs/reference/config/jdownloader.md@@ -11,6 +11,21 @@ jdownloader:enabled: false```+# `deprecated_api`++| Type | Default |+| ------------------- | ------- |+| `HttpURL` or `None` | `null` |++HTTP URL of a local JDownloader instance to connect to via their deprecated API (insecure, default port=3128)++The 'Deprecated API' options need to be enabled on JDownloader instance (`Settings` -> `Advanced Options`)++```yaml+jdownloader:+ deprecated_api: null+```+# `autostart`| Type | Default |