Skip to content

Bulk asynchronous downloader for multiple file hosts

feat: add UI option to edit config

NTFSvolume2f00a7123505
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b47e80aa..838d859cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,11 +40,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- The config file format has completely changed. All configs (`Auth`, `Global` and `Setttings`) are now a single file. Several options have new names, new defaults and new groups
-- Do not create a config file by default
+- A default config file will not be created by default. You can manually create a default one from the `Edit config` option on the main menu
- Validate config in strict mode. If a config has an unknown entry, CDL will refuse to run instead of ignoring it
- Apprise URLs are now part of the main config file instead of a dedicated `apprise.txt` file
- Refuse to start if the current database schema is older than `v9.15.0`
-- Detect and report BasedFlare anti-bot protection
- Cookies with not be automatically loaded from `AppData/cookies`. Path to cookies needs to be specified with `--cookies`
- Always remove generated id from filenames (Cyberdrop)
- Compute `xxh128`, `md5` and `sha256` hashes by default
@@ -52,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `--input-file` is now a CLI only arg
- If supplied, `--input-file` needs to be a valid file that exists
- Refuse to run if both URLs and `--input-file` are passed as arguments
+- Detect and report BasedFlare anti-bot protection
The following options, which were CLI only arguments, now have dedicated config entries:
diff --git a/cyberdrop_dl/config/__init__.py b/cyberdrop_dl/config/__init__.py
index 694ec8100..9f062217b 100644
--- a/cyberdrop_dl/config/__init__.py
+++ b/cyberdrop_dl/config/__init__.py
@@ -93,6 +93,9 @@ class Config(DeferedModel, title="cyberdrop-dl config"):
def source(self) -> Path | None:
return self._source
+ def save_to(self, file: Path) -> None:
+ yaml.save(file, self.model_dump(mode="json"))
+
@staticmethod
def from_file(file: Path, *, _save_if_not_found: bool = False) -> Config:
try:
@@ -100,7 +103,7 @@ class Config(DeferedModel, title="cyberdrop-dl config"):
except FileNotFoundError:
default = Config()
if _save_if_not_found:
- yaml.save(file, default.model_dump(mode="json"))
+ default.save_to(file)
return default
config = Config.model_validate(content)
diff --git a/cyberdrop_dl/program_ui.py b/cyberdrop_dl/program_ui.py
index 6b0f4bd5e..2e7d6f145 100644
--- a/cyberdrop_dl/program_ui.py
+++ b/cyberdrop_dl/program_ui.py
@@ -4,7 +4,7 @@ import asyncio
import os
import sys
from pathlib import Path
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, Any
import aiohttp
import inquirer
@@ -47,6 +47,7 @@ def run(manager: Manager) -> None:
"Create file hashes": _scan_and_create_hashes,
"Sort files in download folder": _sort_files,
"Edit URLs.txt": _edit_urls,
+ "Edit config": _edit_config,
"View changelog": lambda _: _view_changelog(),
"Exit": lambda _: sys.exit(0),
}
@@ -74,12 +75,34 @@ def _sort_files(manager: Manager) -> None:
_WARNING,
f"You are about to sort files from '{sorter.input_dir}' to '{sorter.output_dir}'",
)
- answer = _ask_text("Type 'YES' to proceed")
- if answer.strip().casefold() == "yes":
+ if _ask_confirmation(explicit=True):
asyncio.run(sorter.run())
_enter_to_continue()
+def _should_create_config(file: Path) -> bool:
+ _CONSOLE.print(_WARNING, "A default config file does not exists")
+ return _ask_confirmation(f"Do you want to create it at '{file}'?")
+
+
+def _edit_config(manager: Manager) -> None:
+ file = manager.config.source
+ if file is None:
+ file = manager.appdata.config_file
+ if not _should_create_config(file):
+ return
+ type(manager.config)().save_to(file)
+
+ try:
+ text_editor.open(file)
+ except ValueError as e:
+ _CONSOLE.print(_ERROR, str(e))
+ else:
+ _CONSOLE.print(_WARNING, "You must restart cyberdrop-dl for changes to the config to take effect")
+ finally:
+ _enter_to_continue()
+
+
def _edit_urls(manager: Manager) -> None:
try:
text_editor.open(manager.input_file)
@@ -129,8 +152,8 @@ def _app_header(manager: Manager) -> None:
_CONSOLE.line()
-def _ask_choices(choices: Iterable[str]) -> str:
- return _ask(
+def _ask_choices[T](choices: Iterable[T]) -> T:
+ return _ask( # pyright: ignore[reportAny]
inquirer.List(
"main",
message="What would you like to do",
@@ -139,7 +162,7 @@ def _ask_choices(choices: Iterable[str]) -> str:
)
-def _ask(question: inquirer.questions.Question) -> str:
+def _ask(question: inquirer.questions.Question) -> Any:
answers = inquirer.prompt(
[question],
raise_keyboard_interrupt=True,
@@ -153,6 +176,14 @@ def _ask_text(text: str) -> str:
return _ask(inquirer.Text("text", message=text))
+def _ask_confirmation(text: str = "", *, explicit: bool = False) -> bool:
+ if explicit:
+ msg = "Type 'YES' to proceed"
+ answer = _ask_text(f"{text}. {msg}" if text else msg)
+ return answer.strip().casefold() == "yes"
+ return _ask(inquirer.Confirm("text", message=text))
+
+
def _ask_dir(message: str = "Select dir path", default: Path | None = None) -> Path:
def is_dir(path: Path) -> None:
diff --git a/uv.lock b/uv.lock
index e9119b976..4a593d96b 100644
--- a/uv.lock
+++ b/uv.lock
@@ -669,7 +669,7 @@ requires-dist = [
{ name = "aiosqlite", specifier = ">=0.22.1" },
{ name = "apprise", marker = "extra == 'apprise'", specifier = ">=1.11.0" },
{ name = "async-mega-py", specifier = ">=2.4.1" },
- { name = "backports-zstd", marker = "python_full_version < '3.14' and implementation_name == 'cpython'", specifier = ">=1.5.0" },
+ { name = "backports-zstd", marker = "python_full_version < '3.14' and implementation_name == 'cpython'", specifier = ">=1.6.0" },
{ name = "beautifulsoup4", specifier = ">=4.15.0" },
{ name = "brotli", marker = "implementation_name == 'cpython' and sys_platform != 'ios'", specifier = ">=1.2.0" },
{ name = "certifi", specifier = ">=2026.6.17" },