Skip to content

Bulk asynchronous downloader for multiple file hosts

fix: Respect `--subfolders.include.domain` for `Loose Files` folders

NTFSvolume4abf62f33f8f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1525edc68..9802222ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Handle posts with no audio (TikTok)
- Do not stop entire profile scrape when a single post fails (TikTok)
- Respect `--rate-limit` values higher than 25req/s
+- Respect `--subfolders.include.domain` for `Loose Files` folders
### Security
diff --git a/cyberdrop_dl/config/settings.py b/cyberdrop_dl/config/settings.py
index 93f6d3e9f..78cc594b2 100644
--- a/cyberdrop_dl/config/settings.py
+++ b/cyberdrop_dl/config/settings.py
@@ -60,7 +60,7 @@ class SubFolders(ConfigGroup, name=None):
"Enable/disable the creation of nested sub-folders"
group_loose_files: bool = True
- "Create a subfolder named 'Loose Files (<DOMAIN>)' for individual files not part of any album/thread"
+ "Create a subfolder named 'Loose Files' for individual files not part of any album/thread"
include: _SubFoldersInclude = Field(default_factory=_SubFoldersInclude)
separate_posts: _SeparatePosts = Field(default_factory=_SeparatePosts)
diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.py
index c0aa60401..4c8a1886b 100644
--- a/cyberdrop_dl/crawlers/crawler.py
+++ b/cyberdrop_dl/crawlers/crawler.py
@@ -1330,11 +1330,16 @@ def _should_skip_by_config(media_item: MediaItem, config: Config) -> bool:
def _prepare_download_path(item: ScrapeItem, domain: str, config: Config) -> Path:
if item.retry_info and USE_RETRY_PATH.get():
return item.retry_info.download_path
+
path = item.download_folder / item.path
- if item.is_loose_file and config.subfolders.create and config.subfolders.group_loose_files:
- loose_files = f"Loose Files ({domain})" if domain else "Loose Files"
- path = path / loose_files
- return path
+ if not (item.is_loose_file and config.subfolders.create and config.subfolders.group_loose_files):
+ return path
+
+ loose_files = "Loose Files"
+ if config.subfolders.include.domain and domain:
+ loose_files += f" ({domain})"
+
+ return path / loose_files
def compose_title( # noqa: PLR0913
diff --git a/docs/reference/config/subfolders.md b/docs/reference/config/subfolders.md
index 6ea8d5edc..624e26dab 100644
--- a/docs/reference/config/subfolders.md
+++ b/docs/reference/config/subfolders.md
@@ -23,8 +23,8 @@ subfolders:
| ------ | ------- |
| `bool` | `true` |
-Download individual files not part of any album/thread into a subfolder named `Loose Files (<DOMAIN>)`. Direct HTTP files from unsupported sites
-will be downloaded to `Loose Files` (no domain in folder name).
+Download individual files not part of any album/thread into a subfolder named `Loose Files (<DOMAIN>)`
+(or just `Loose Files` for Direct HTTP files from unsupported sites or when `--subfolders.include.domain` is disabled).
This option is ignored unless `--subfolder.create` is enabled
diff --git a/tests/test_database.py b/tests/test_database.py
index 4691ffd21..504e741b1 100644
--- a/tests/test_database.py
+++ b/tests/test_database.py
@@ -108,6 +108,13 @@ class TestGetDownloadPath:
with enter_context(USE_RETRY_PATH, True):
assert self.dl_path(item) == retry.download_path
+ def test_loose_files_no_include_domain(self, item: ScrapeItem) -> None:
+ item.append_folders("a/sub/folder")
+ config = Config()
+ config.subfolders.include.domain = False
+ path = _prepare_download_path(item, "cyberdrop", config)
+ assert path == Path("downloads/a-sub-folder/Loose Files")
+
async def test_database_creation(tmp_cwd: Path) -> None:
db_file = tmp_cwd / "test_db.db"