Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: add `max_thread_folder_depth` config option (#1293)
NTFSvolume5ceb75e27295
diff --git a/cyberdrop_dl/config/config_model.py b/cyberdrop_dl/config/config_model.pyindex d8a98d283..8761f806f 100755--- a/cyberdrop_dl/config/config_model.py+++ b/cyberdrop_dl/config/config_model.py@@ -55,6 +55,7 @@ class DownloadOptions(BaseModel):skip_download_mark_completed: bool = Falseskip_referer_seen_before: bool = Falsemaximum_thread_depth: NonNegativeInt = 0+ maximum_thread_folder_depth: NonNegativeInt | None = None@field_validator("separate_posts_format", mode="after")@classmethoddiff --git a/cyberdrop_dl/crawlers/_forum.py b/cyberdrop_dl/crawlers/_forum.pyindex 64c80a032..a773efd00 100644--- a/cyberdrop_dl/crawlers/_forum.py+++ b/cyberdrop_dl/crawlers/_forum.py@@ -215,6 +215,11 @@ class MessageBoardCrawler(Crawler, is_abc=True):def max_thread_depth(self) -> int:return self.manager.config_manager.settings_data.download_options.maximum_thread_depth+ @final+ @property+ def max_thread_folder_depth(self):+ return self.manager.config.download_options.maximum_thread_folder_depth+async def fetch(self, scrape_item: ScrapeItem) -> None:if not self.logged_in and self.login_required is True:return@@ -271,6 +276,19 @@ class MessageBoardCrawler(Crawler, is_abc=True):)raise MaxChildrenError(msg)+ self.limit_nexted_thread_folders(scrape_item)++ @final+ def limit_nexted_thread_folders(self, scrape_item: ScrapeItem) -> None:+ if self.max_thread_folder_depth is None:+ return+ n_parents = len(scrape_item.parent_threads)+ if n_parents > self.max_thread_folder_depth:+ scrape_item.parent_title = scrape_item.parent_title.rsplit("/", 1)[0]+ if not self.separate_post_title:+ return+ scrape_item.parent_title = scrape_item.parent_title.rsplit("/", 1)[0]+@finaldef stop_thread_recursion(self, scrape_item: ScrapeItem) -> bool:if n_parents := len(scrape_item.parent_threads):diff --git a/docs/reference/configuration-options/settings/download_options.md b/docs/reference/configuration-options/settings/download_options.mdindex a90239f9a..4d13a1e69 100644--- a/docs/reference/configuration-options/settings/download_options.md+++ b/docs/reference/configuration-options/settings/download_options.md@@ -199,7 +199,7 @@ Setting it to `{default}` will use the default format, which is different for ea| `Discourse` | `{date} - {id} - {title}` || `Reddit` | `{title}` || `WordPress` | `{date:%Y-%m-%d} - {id} - {title}` |-| `eFukt` | `{date:%Y-%m-%d} {title}` |+| `eFukt` | `{date:%Y-%m-%d} {title}` |A date without a `format_spec` defaults to ISO 8601 format@@ -271,3 +271,72 @@ Consider CDL finds the following sub-threads while scraping an input URL:- With `maximum_thread_depth` = 0, CDL will only download files in `thread_01`, all the other threads will be ignored- With `maximum_thread_depth` = 1, CDL will only download files in `thread_01` to `thread_08`. All threads from `thread_09` to `thread_12` will be ignored- With `maximum_thread_depth` >= 2, CDL will download files from all the threads in this case++## `maximum_thread_folder_depth`++| Type | Default |+| -------------------------- | ------- |+| `NonNegativeInt` or `None` | `None` |++++Restricts the max number of nested folders CDL will create when `maximum_thread_depth` is greater that 0++Values:++- `None`: Create as many nested folders as required (AKA, the same number as `maximum_thread_depth` allows)+- `0`: Do not create subfolders, use a flat structure for any nested thread.+- `1+`: Create a max of `n` folders+++### Example++- With `maximum_thread_folder_depth` = None:++```bash+└── thread_01+ ├── thread_02+ ├── thread_03+ │ ├── thread_09+ │ ├── thread_10+ │ └── thread_11+ ├── thread_04+ ├── thread_05+ ├── thread_06+ ├── thread_07+ │ └── thread_12+ └── thread_08+```+- With `maximum_thread_folder_depth` = 0:++```bash+├── thread_01+├── thread_02+├── thread_03+├── thread_09+├── thread_10+├── thread_11+├── thread_04+├── thread_05+├── thread_06+├── thread_07+├── thread_12+└── thread_08+```++- With `maximum_thread_folder_depth` = 1:++```bash+└── thread_01+ ├── thread_02+ ├── thread_03+ ├── thread_09+ ├── thread_10+ ├── thread_11+ ├── thread_04+ ├── thread_05+ ├── thread_06+ ├── thread_07+ ├── thread_12+ └── thread_08+```