Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: add config subcommand
NTFSvolume3c4601af1676
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0a762840f..4092337e5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- New `--database-file` option- New `--cache-file` option- New `download` subcommand (replaces the `--download` argument)+- New `config` subcommand- New `interactive` subcommand- New `hash` subcommand- New `report` subcommanddiff --git a/cyberdrop_dl/cli.py b/cyberdrop_dl/cli.pyindex ca7375efe..2af7a8596 100644--- a/cyberdrop_dl/cli.py+++ b/cyberdrop_dl/cli.py@@ -4,6 +4,7 @@ from cyclopts.help import DefaultFormatterfrom cyberdrop_dl import __version__from cyberdrop_dl.commands.clean_up import app as cleanup+from cyberdrop_dl.commands.config import app as configfrom cyberdrop_dl.commands.database import app as databasefrom cyberdrop_dl.commands.hash import compute_hashesfrom cyberdrop_dl.commands.report import report@@ -28,7 +29,7 @@ def show() -> None:app.console.print(table)-for cmd in download, database, interactive, cleanup, report:+for cmd in download, database, interactive, cleanup, report, config:app.command(cmd)diff --git a/cyberdrop_dl/commands/config.py b/cyberdrop_dl/commands/config.pynew file mode 100644index 000000000..d70685fc8--- /dev/null+++ b/cyberdrop_dl/commands/config.py@@ -0,0 +1,36 @@+import logging++from cyclopts import App++from cyberdrop_dl.config import Config+from cyberdrop_dl.config.appdata import AppData+from cyberdrop_dl.prompts import ask_should_create_config++app = App(name="config", help="Config file operations")+logger = logging.getLogger(__name__)+++def file() -> None:+ "Show the default config file path"+ app.console.print(AppData.default().config_file)+++def edit() -> None:+ "Open the default config file on a text editor"+ from cyberdrop_dl.utils import text_editor++ file = AppData.default().config_file+ if not file.exists():+ if not ask_should_create_config(file):+ return+ Config().save_to(file)++ text_editor.open(file)+++def new() -> None:+ "Create a new config with default options and print it"+ app.console.print(Config().dump_yaml())diff --git a/cyberdrop_dl/config/__init__.py b/cyberdrop_dl/config/__init__.pyindex 4cf39e932..d1e35f8ff 100644--- a/cyberdrop_dl/config/__init__.py+++ b/cyberdrop_dl/config/__init__.py@@ -118,10 +118,12 @@ class Config(ConfigModel, title="cyberdrop-dl config"):def source(self) -> Path | None:return self._source+ def dump_yaml(self) -> str:+ return yaml.safe_dump(self.model_dump(mode="json"), default_flow_style=False)+def save_to(self, file: Path) -> None:file.parent.mkdir(parents=True, exist_ok=True)- with file.open("w", encoding="utf8") as file_io:- yaml.safe_dump(self.model_dump(mode="json"), file_io, default_flow_style=False)+ file.write_text(self.dump_yaml(), encoding="utf8")@staticmethoddef from_file(file: Path, *, _save_if_not_found: bool = False) -> Config:diff --git a/cyberdrop_dl/program_ui.py b/cyberdrop_dl/program_ui.pyindex 2a39d927c..a68104321 100644--- a/cyberdrop_dl/program_ui.py+++ b/cyberdrop_dl/program_ui.py@@ -9,13 +9,19 @@ from rich.markdown import Markdownfrom cyberdrop_dl import __version__, aio, statsfrom cyberdrop_dl.hasher import Hasher, hash_directoryfrom cyberdrop_dl.progress import hyperlink-from cyberdrop_dl.prompts import ask_choices, ask_confirmation, ask_dir, console, enter_to_continue+from cyberdrop_dl.prompts import (+ ask_choices,+ ask_confirmation,+ ask_dir,+ ask_should_create_config,+ console,+ enter_to_continue,+)from cyberdrop_dl.sorter import Sorterfrom cyberdrop_dl.utils import text_editorif TYPE_CHECKING:from collections.abc import Callable- from pathlib import Pathfrom cyberdrop_dl.manager import Manager@@ -69,16 +75,11 @@ def _sort_files(manager: Manager) -> None:enter_to_continue()-def _should_create_config(file: Path) -> bool:- console.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.sourceif file is None:file = manager.appdata.config_file- if not _should_create_config(file):+ if not ask_should_create_config(file):returntype(manager.config)().save_to(file)diff --git a/cyberdrop_dl/prompts.py b/cyberdrop_dl/prompts.pyindex c83476e40..77f783ae4 100644--- a/cyberdrop_dl/prompts.py+++ b/cyberdrop_dl/prompts.py@@ -115,3 +115,8 @@ def ask_path(console.error(repr(e))else:return path.resolve()+++def ask_should_create_config(file: Path) -> bool:+ console.warning("A default config file does not exists")+ return ask_confirmation(f"Do you want to create it at '{file}'?")