Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: add interactive subcommand

NTFSvolumecccc48547a63
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1d262264d..7cccf067a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New `--hashes` option to control which hashes CDL computes for new downloads
- New `--database-file` option
- New `--cache-file` option
+- New `download` subcommand (replaces the `--download` argument)
+- New `interactive` subcommand
- New `hash` subcommand
- New `report` subcommand
diff --git a/cyberdrop_dl/cli/__init__.py b/cyberdrop_dl/cli/__init__.py
index 76b8942bc..236ea8a02 100644
--- a/cyberdrop_dl/cli/__init__.py
+++ b/cyberdrop_dl/cli/__init__.py
@@ -23,9 +23,6 @@ class CLIargs(ConfigModel):
database_file: Path | None = None
"SQLite file to use as database"
- download: bool = False
- "Skips UI, start download immediately"
-
app = App(
name="cyberdrop-dl",
@@ -47,15 +44,13 @@ def show() -> None:
def register_commands() -> None:
from cyberdrop_dl.cli.clean_up import app as cleanup
from cyberdrop_dl.cli.database import app as database
- from cyberdrop_dl.cli.download import download
from cyberdrop_dl.cli.hash import compute_hashes
+ from cyberdrop_dl.cli.main import download, interactive
from cyberdrop_dl.cli.report import report
- app.command(download)
- app.command(database)
- app.command(show)
- app.command(cleanup)
- app.command(report)
+ for cmd in download, database, interactive, show, cleanup, report:
+ app.command(cmd)
+
app.command(compute_hashes, name="hash")
diff --git a/cyberdrop_dl/cli/download.py b/cyberdrop_dl/cli/main.py
similarity index 87%
rename from cyberdrop_dl/cli/download.py
rename to cyberdrop_dl/cli/main.py
index b9eb74a45..64d074fd3 100644
--- a/cyberdrop_dl/cli/download.py
+++ b/cyberdrop_dl/cli/main.py
@@ -1,7 +1,8 @@
from __future__ import annotations
import logging
-from pathlib import Path # noqa: TC003
+from contextvars import ContextVar
+from pathlib import Path
from typing import TYPE_CHECKING, Annotated
import cyclopts.validators
@@ -19,6 +20,7 @@ from cyberdrop_dl.models.types import HttpURL # noqa: TC001
from cyberdrop_dl.utils import cleanup
logger = logging.getLogger(__name__)
+_INTERACTIVE: ContextVar[bool] = ContextVar("_INTERACTIVE", default=False)
if TYPE_CHECKING:
from cyclopts.argument import ArgumentCollection
@@ -80,20 +82,23 @@ async def _post_runtime(manager: Manager) -> None:
_check_partials_and_empty_folders(manager.config)
+def _show_interactive_ui(manager: Manager) -> None:
+ if not _INTERACTIVE.get():
+ return
+
+ from cyberdrop_dl import program_ui
+
+ program_ui.run(manager)
+
+
def _main(manager: Manager) -> None:
- from cyberdrop_dl import aio, program_ui
+ from cyberdrop_dl import aio
set_console_level(manager.config.logs.effective_console_level)
manager.appdata.mkdirs()
try:
with manager():
- if (
- not manager.cli_args.download
- or not manager.config.ui.mode.is_fullscreen
- or manager.cli_args.config_file
- or manager.config.sort.enabled
- ):
- program_ui.run(manager)
+ _show_interactive_ui(manager)
with setup_file_logging(
manager.config.logs.files.main,
@@ -117,6 +122,23 @@ def _validate_inputs(args: ArgumentCollection) -> None:
inputs_group = Group(sort_key=-1, validator=_validate_inputs)
+def interactive(
+ *,
+ input_file: Annotated[
+ Path,
+ Parameter(
+ alias="-i",
+ help="Text/HTML file with URL(s) to download",
+ validator=cyclopts.validators.Path(exists=True, dir_okay=False),
+ ),
+ ] = Path("URLs.txt"), # pyright: ignore[reportCallInDefaultInitializer]
+ cli: CLIargs | None = None,
+) -> None:
+ "Show a TUI menu equivalent to the CLI commands"
+ _INTERACTIVE.set(True)
+ download(input_file=input_file, cli=cli or CLIargs())
+
+
def download(
urls: Annotated[
tuple[HttpURL, ...],
diff --git a/tests/test_config.py b/tests/test_config.py
index 01c36857d..a33fa955c 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -10,7 +10,7 @@ import yaml
from cyclopts.exceptions import UnknownOptionError
from pydantic import BaseModel
-import cyberdrop_dl.cli.download
+import cyberdrop_dl.cli.main
from cyberdrop_dl.config import Config, Files, _resolve_paths, merge_additive_args, settings
from cyberdrop_dl.config.appdata import AppData
from cyberdrop_dl.config.auth import Authentication, Notifications
@@ -154,7 +154,7 @@ class TestRuntimeLogsConfig:
def test_default_config_does_not_need_ffmpeg() -> None:
- cyberdrop_dl.cli.download._check_ffmpeg(Config())
+ cyberdrop_dl.cli.main._check_ffmpeg(Config())
def test_media_durations_need_ffmpeg() -> None:
@@ -164,7 +164,7 @@ def test_media_durations_need_ffmpeg() -> None:
assert duration.total_seconds() == 20
assert config.filters.duration.needs_ffmpeg
with pytest.raises(CDLConfigRuntimeErrorsGroup) as exc:
- cyberdrop_dl.cli.download._check_ffmpeg(config)
+ cyberdrop_dl.cli.main._check_ffmpeg(config)
assert len(exc.value.exceptions) == 1
assert type(exc.value.exceptions[0]) is RuntimeError