Skip to content

Bulk asynchronous downloader for multiple file hosts

feat: add `--downloads.back-pressure` option

NTFSvolume36e75a0fb1c8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index be5d63a6c..c58e25de0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+- New `--downloads.back-pressure` option
- New `--restrict-path` option
- New `--input-folder` option that scans all `.txt` within a folder for URLs (non recursive). URLs within the same file will create a group. The name of the group is the filename;
Each group will be downloaded to their own subfolder within the downloads folder. See: <https://script-ware.gitbook.io/cyberdrop-dl/reference/config/sorting#group-urls>
diff --git a/cyberdrop_dl/config/default.yaml b/cyberdrop_dl/config/default.yaml
index 46c997325..88c282073 100644
--- a/cyberdrop_dl/config/default.yaml
+++ b/cyberdrop_dl/config/default.yaml
@@ -68,6 +68,7 @@ delete_partial_files: false
download_folder: downloads/cyberdrop-dl
downloads:
attempts: 2
+ back_pressure: true
concurrency: 15
concurrency_per_domain: 5
concurrent_segments: 10
diff --git a/cyberdrop_dl/config/schema.json b/cyberdrop_dl/config/schema.json
index aa5f975d5..cecfa8ba1 100644
--- a/cyberdrop_dl/config/schema.json
+++ b/cyberdrop_dl/config/schema.json
@@ -225,6 +225,11 @@
"$ref": "#/$defs/ByteSizeSerilized",
"default": 0
},
+ "back_pressure": {
+ "default": true,
+ "title": "Back Pressure",
+ "type": "boolean"
+ },
"jitter": {
"default": 0,
"minimum": 0,
diff --git a/cyberdrop_dl/config/settings.py b/cyberdrop_dl/config/settings.py
index dea4fd957..313d57869 100644
--- a/cyberdrop_dl/config/settings.py
+++ b/cyberdrop_dl/config/settings.py
@@ -315,6 +315,9 @@ class Downloads(ConfigGroup):
speed_limit: ByteSizeSerilized = ByteSize(0)
"Max speed rate (in bytes per second) to limit downloads (combined)"
+ back_pressure: bool = True
+ "Throttle scrape requests if there are too many downloads queued for the same site"
+
jitter: NonNegativeFloat = 0
"Wait a random additional number of seconds in between 0 and <jitter> before downloads"
diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.py
index 2f75ba9d9..82b5abe62 100644
--- a/cyberdrop_dl/crawlers/crawler.py
+++ b/cyberdrop_dl/crawlers/crawler.py
@@ -64,7 +64,7 @@ type SupportedDomains = OneOrTuple[str]
type DebridURL = Callable[[], Awaitable[AbsoluteHttpURL]] | AbsoluteHttpURL | None
_ORIGIN: ContextVar[AbsoluteHttpURL] = ContextVar("ORIGIN")
-_CHECK_DL_CAPACITY: ContextVar[bool] = ContextVar("_CHECK_DL_CAPACITY", default=True)
+_CHECK_DL_CAPACITY: ContextVar[bool] = ContextVar("_CHECK_DL_CAPACITY")
_HASH_PREFIXES = "md5:", "sha1:", "sha256:", "xxh128:"
@@ -235,6 +235,7 @@ class Crawler(HTTPMixin, HLSMixin, ABC):
self._semaphore: asyncio.Semaphore = asyncio.Semaphore(20)
self.config: Config = manager.config
self.client: HTTPClient = manager.http_client
+ _CHECK_DL_CAPACITY.set(self.config.downloads.back_pressure)
assert self.__dl_config__.server_lock is not None
self.downloader: Downloader = Downloader(
manager,
diff --git a/docs/reference/config/downloads.md b/docs/reference/config/downloads.md
index bc747270f..2432d3311 100644
--- a/docs/reference/config/downloads.md
+++ b/docs/reference/config/downloads.md
@@ -11,6 +11,22 @@ downloads:
attempts: 2
```
+# `back_pressure`
+
+| Type | Default |
+| ------ | ------- |
+| `bool` | `True` |
+
+Throttle scrape requests if too many downloads for the same site are queued.
+
+This works by setting a limit of max queued downloads of a single site to the value of `<concurrency>` x10 (capped at 50). If the number of pending downloads
+for that site reaches the limit, all scraping for the site will be paused until the queue goes below it
+
+```yaml
+downloads:
+ back_pressure: True
+```
+
# `delay`
| Type | Default |