Skip to content

Bulk asynchronous downloader for multiple file hosts

feat: add `--input-folder` option

NTFSvolume7f7583c52800
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1cac808b8..52412bb68 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,18 @@ All notable changes to this project will be documented here. For more details, v
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [10.7.0] - UNRELEASED
+
+### Added
+
+- New `--input-folder` option that scans all `.txt` within a folder for URLs (non recursive). URLs within the same file will be a group;
+ A subfolder within the downloads folder will be created for each group. See: <https://script-ware.gitbook.io/cyberdrop-dl/reference/config/sorting#group-urls>
+- New `--source` option that accepts either a file or a folder
+
+### Changed
+
+- `-i` is now an alias for `--source` instead of `--input-file`
+
## [10.6.1] - 2026-08-25
### Changed
diff --git a/cyberdrop_dl/commands/scrape.py b/cyberdrop_dl/commands/scrape.py
index 9dfc75c8e..0fa02de79 100644
--- a/cyberdrop_dl/commands/scrape.py
+++ b/cyberdrop_dl/commands/scrape.py
@@ -107,14 +107,14 @@ def _validate_inputs(args: ArgumentCollection) -> None:
cyclopts.validators.LimitedChoice(min=1, max=1)(args)
except ValueError as e:
if "choices may be specified." in str(e):
- raise ValueError("You must provide either URLs or a file with `--input-file`") from None
+ raise ValueError("You must provide either URLs, `--input-file`, `--input-folder` or `--source`") from None
raise
_inputs_group = Group(sort_key=-1, validator=_validate_inputs)
-def download(
+def download( # noqa: PLR0913
urls: Annotated[
tuple[HttpURL, ...],
Parameter(
@@ -131,19 +131,37 @@ def download(
Path | None,
Parameter(
group=_inputs_group,
- alias="-i",
help="Text/HTML file with URL(s) to download",
validator=cyclopts.validators.Path(exists=True, dir_okay=False),
),
] = None,
+ input_folder: Annotated[
+ Path | None,
+ Parameter(
+ group=_inputs_group,
+ help="""Read all '.txt' within this folder for URL(s) to download (non recursive).
+ All URLs within the same file will be grouped in the own subfolder (the filename) within the downloads folder""",
+ validator=cyclopts.validators.Path(exists=True, dir_okay=True, file_okay=False),
+ ),
+ ] = None,
+ source: Annotated[
+ Path | None,
+ Parameter(
+ group=_inputs_group,
+ alias="-i",
+ help="File/folder with URL(s) to download (non recursive)",
+ validator=cyclopts.validators.Path(exists=True),
+ ),
+ ] = None,
cli_args: CLIarguments | None = None,
cli_overrides: Config | None = None,
) -> None:
"Download URLs"
- if input_file:
- input_file = input_file.resolve().absolute()
+ source = source or input_folder or input_file
+ if source:
+ source = source.resolve().absolute()
with prepare_manager(cli_args, cli_overrides)() as manager:
- scrape(manager, input_file or urls)
+ scrape(manager, source or urls)
def prepare_manager(cli_args: CLIarguments | None, cli_overrides: Config | None) -> Manager:
diff --git a/cyberdrop_dl/scrape_mapper.py b/cyberdrop_dl/scrape_mapper.py
index 2e73489b5..4fbb5d986 100644
--- a/cyberdrop_dl/scrape_mapper.py
+++ b/cyberdrop_dl/scrape_mapper.py
@@ -21,8 +21,8 @@ from cyberdrop_dl.scrape_source import (
RetryScrapeSource,
URLsSource,
load_items_from_db,
- load_items_from_file,
load_items_from_iterable,
+ load_items_from_path,
)
from cyberdrop_dl.url_objects import AbsoluteHttpURL, ScrapeItem, ScrapeItemType
from cyberdrop_dl.utils import remove_trailing_slash
@@ -446,7 +446,7 @@ def _build_max_children_map(config: Config) -> dict[ScrapeItemType, int]:
def _parse_source(
- src: RetryScrapeSource | Path | Iterable[AbsoluteHttpURL], manager: Manager
+ src: RetryScrapeSource | URLsSource, manager: Manager
) -> tuple[ScrapeStats, AsyncGenerator[ScrapeItem]]:
match src:
case RetryScrapeSource():
@@ -460,7 +460,7 @@ def _parse_source(
)
case Path():
source = src
- items = load_items_from_file(src)
+ items = load_items_from_path(src)
case _:
source = "--links (CLI args)"
items = load_items_from_iterable(src)
diff --git a/cyberdrop_dl/scrape_source.py b/cyberdrop_dl/scrape_source.py
index a2317b4ea..4c0fb5e2f 100644
--- a/cyberdrop_dl/scrape_source.py
+++ b/cyberdrop_dl/scrape_source.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import contextlib
import dataclasses
import logging
import re
@@ -55,16 +56,36 @@ class RetryScrapeSource:
before: datetime.date
-async def load_items_from_file(file: Path) -> AsyncGenerator[ScrapeItem]:
- async for group_name, urls in _parse_input_file_groups(file):
- for url in urls:
- item = ScrapeItem.from_url(url)
- if group_name:
- item.append_folders(group_name)
- item.part_of_album = True
+async def load_items_from_path(path: Path) -> AsyncGenerator[ScrapeItem]:
+ gen_fn = load_items_from_file if await aio.is_file(path) else load_items_from_folder
+ async with contextlib.aclosing(gen_fn(path)) as items:
+ async for item in items:
yield item
+async def load_items_from_folder(path: Path) -> AsyncGenerator[ScrapeItem]:
+ files = sorted(
+ [f async for f in aio.glob(path, "*.txt") if not f.name.startswith(".")], key=lambda x: str(x).casefold()
+ )
+ for file in files:
+ async with contextlib.aclosing(load_items_from_file(file)) as items:
+ async for item in items:
+ item.append_folders(file.stem)
+ item.part_of_album = True
+ yield item
+
+
+async def load_items_from_file(file: Path) -> AsyncGenerator[ScrapeItem]:
+ async with contextlib.aclosing(_parse_input_file_groups(file)) as lines:
+ async for group_name, urls in lines:
+ for url in urls:
+ item = ScrapeItem.from_url(url)
+ if group_name:
+ item.append_folders(group_name)
+ item.part_of_album = True
+ yield item
+
+
async def _parse_input_file_groups(input_file: Path) -> AsyncGenerator[tuple[str, list[AbsoluteHttpURL]]]:
if not await aio.is_file(input_file):
yield ("", [])