feat(config): add rename_chapters field, CLI flag, and 3-layer resolution
Add rename_chapters boolean config field following the established pattern from download_extras/download_covers. Config defaults to True; YAML supports explicit false; --rename-chapters CLI flag forces True overriding config. Threaded through sync_run() with resolved value ready for pipeline wiring in slice 3. Closes #33
This commit is contained in:
1 parent
b6df4e3a9b
commit
af5ad4953c
11 files changed
+175
-2
No files matched your search
@@ -17,6 +17,7 @@ def run(
|
||||
verbose: bool = False,
|
||||
limit: int = 0,
|
||||
workers: int = 0,
|
||||
rename_chapters: bool = False,
|
||||
select_mode: bool = False,
|
||||
) -> int:
|
||||
"""Thin adapter: call sync_run() and translate SyncRunResult → exit code (0/1/130)."""
|
||||
@@ -27,6 +28,7 @@ def run(
|
||||
verbose=verbose,
|
||||
limit=limit,
|
||||
workers=workers,
|
||||
rename_chapters=rename_chapters,
|
||||
select_mode=select_mode,
|
||||
)
|
||||
if result.interrupted:
|
||||
@@ -46,11 +48,14 @@ def main() -> None:
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output")
|
||||
parser.add_argument("--limit", type=int, default=0, metavar="N", help="Max books to download (0=no limit)")
|
||||
parser.add_argument("-w", "--workers", type=int, default=0, metavar="N", help="Parallel workers (0=config)")
|
||||
parser.add_argument("--rename-chapters", action="store_true", default=False,
|
||||
help="Rename chapter files (default: use config)")
|
||||
parser.add_argument("--select", action="store_true", default=False, help="Interactive selection [not implemented]")
|
||||
args = parser.parse_args()
|
||||
exit_code = run(
|
||||
config_path=args.config, secrets_path=args.secrets, history_path=args.history,
|
||||
verbose=args.verbose, limit=args.limit, workers=args.workers, select_mode=args.select,
|
||||
verbose=args.verbose, limit=args.limit, workers=args.workers,
|
||||
rename_chapters=args.rename_chapters, select_mode=args.select,
|
||||
)
|
||||
if exit_code == 130:
|
||||
try:
|
||||
|
||||
@@ -16,6 +16,7 @@ class Config:
|
||||
output_dir: str
|
||||
download_extras: bool
|
||||
download_covers: bool
|
||||
rename_chapters: bool
|
||||
_config_path: Path | None = None # None = defaulted (file missing)
|
||||
workers: int = 3
|
||||
|
||||
@@ -139,6 +140,7 @@ def load_config(
|
||||
output_dir=librofm.get("output_dir", "./audiobooks"),
|
||||
download_extras=librofm.get("download_extras", True),
|
||||
download_covers=librofm.get("download_covers", True),
|
||||
rename_chapters=librofm.get("rename_chapters", True),
|
||||
_config_path=config_path,
|
||||
workers=librofm.get("workers", 3),
|
||||
)
|
||||
|
||||
@@ -60,6 +60,7 @@ def sync_run(
|
||||
verbose: bool = False,
|
||||
limit: int = 0,
|
||||
workers: int = 0,
|
||||
rename_chapters: bool = False,
|
||||
*,
|
||||
select_mode: bool = False,
|
||||
) -> SyncRunResult:
|
||||
@@ -123,13 +124,16 @@ def sync_run(
|
||||
console.print(f" output: {config.output_dir}")
|
||||
console.print(f" extras: {config.download_extras}")
|
||||
console.print(f" covers: {config.download_covers}")
|
||||
console.print(f" chapters: {config.rename_chapters}")
|
||||
console.print(f" user: {config.username}")
|
||||
|
||||
# Resolve workers: CLI flag (>0?) → config.workers → default 3
|
||||
resolved_workers = workers if workers > 0 else config.workers
|
||||
if resolved_workers < 1:
|
||||
resolved_workers = 3
|
||||
console.print(f" user: {config.username}")
|
||||
|
||||
# Resolve rename_chapters: CLI flag (True?) → config.rename_chapters
|
||||
resolved_rename_chapters = rename_chapters or config.rename_chapters
|
||||
|
||||
# 2. Authenticate
|
||||
if verbose:
|
||||
|
||||
Reference in new issue
Block a user