Merge branch 'develop' into feature/parallel-downloads
This commit is contained in:
22 files changed
+1051
-113
No files matched your search
@@ -8,6 +8,8 @@ They capture what was done, decisions & rationale, gotchas & fixes, and next ste
|
||||
<!-- write-log: session-log-index -->
|
||||
| Date | Type | File | Summary |
|
||||
|------|------|------|---------|
|
||||
| 2026-06-04 | issue | [20260604-issue23-wire-xdg-resolution-into-cli_log.md](docs/devlog/20260604-issue23-wire-xdg-resolution-into-cli_log.md) | **Issue #23 Complete:** Wire XDG resolution into CLI — history path XDG default, verbose resolved paths, searched-paths message. **7 new tests, 188 total** · **10/10 AC** |
|
||||
| 2026-06-04 | issue | [20260604-issue22-xdg-config-path-resolution-with-cwd-fallback_log.md](docs/devlog/20260604-issue22-xdg-config-path-resolution-with-cwd-fallback_log.md) | **Issue #22 Complete:** XDG→CWD path resolution, `load_config(None, None)` search, missing-config notice, OS→domain error wrapping. **9 new tests, 181 total** · **8/8 AC** |
|
||||
| 2026-06-03 | issue | [20260603-cli-parallel-integration-and-ctrl-c-drain-issue17_log.md](docs/devlog/20260603-cli-parallel-integration-and-ctrl-c-drain-issue17_log.md) | **Issue #17 Complete:** CLI parallel integration + graceful Ctrl+C drain. Orchestrator catches KeyboardInterrupt, drains in-flight downloads (shutdown(wait=True)), double-Ctrl+C fast exit. **13 new tests, 231 total** · **10/10 AC** |
|
||||
| 2026-06-03 | issue | [20260603-parallel-download-orchestrator-issue16_log.md](docs/devlog/20260603-parallel-download-orchestrator-issue16_log.md) | **Issue #16 Complete:** `orchestrator.py` — `ThreadPoolExecutor` parallel download engine. Replaces sequential for-loop in cli.py. `OrchestratorResult` dataclass, stable-sort ordering, failure isolation. **20 new tests, 218 total** · **11/11 AC** |
|
||||
| 2026-06-03 | issue | [20260603-api-rate-limiter-issue15_log.md](docs/devlog/20260603-api-rate-limiter-issue15_log.md) | **Issue #15 Complete:** `threading.Semaphore(3)` API rate limiter on `LibroFmClient`. Caps concurrent API calls; CDN downloads bypass. **4 new tests, 198 total** · **6/6 AC** |
|
||||
|
||||
+25
-1
@@ -5,7 +5,31 @@ All notable changes to this project will be documented in this file.
|
||||
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).
|
||||
|
||||
## [Unreleased]
|
||||
## [1.1.0] - 2026-06-04
|
||||
|
||||
### Added
|
||||
- **config (closes #22):** XDG config path resolution with CWD fallback.
|
||||
`_resolve_config_file()` searches `~/.config/librofm-downloader/` then CWD.
|
||||
`load_config(None, None)` triggers search; missing config.yaml is non-fatal
|
||||
(prints notice, uses built-in defaults); missing secrets.yaml raises
|
||||
domain error listing searched paths. All OS exceptions wrapped as
|
||||
`ConfigError`. XDG directory auto-created on demand.
|
||||
- **cli (closes #23):** Wire XDG path resolution into CLI layer.
|
||||
History path defaults to `None` (resolves XDG → CWD, falls back to XDG
|
||||
location). Missing config message now lists searched paths. `--verbose`
|
||||
shows resolved file paths for config, secrets, and history. Explicit
|
||||
`--config`/`--secrets`/`--history` flags bypass search. Clean exit 1
|
||||
with no traceback when secrets missing from all locations.
|
||||
|
||||
### Documentation
|
||||
- **docs (closes #24):** Update all documentation for XDG path resolution.
|
||||
configuration.md: new "Default file locations" section with search order,
|
||||
auto-creation, missing-config vs missing-secrets behavior, CLI flag
|
||||
overrides, validation error table with "not found" messages, and
|
||||
history default location. quickstart.md, cli-usage.md, troubleshooting.md,
|
||||
and README.md updated to reference XDG-first search.
|
||||
|
||||
## [1.0.0] - 2026-06-03
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
+16
-1
@@ -75,7 +75,7 @@ via HTTP Range header on next run. Renamed to final filename on completion.
|
||||
`config.yaml` at runtime. Script errors if credentials found in config.yaml.
|
||||
|
||||
### **Sync Run**
|
||||
One execution of the script: auth → fetch library → filter undownloaded
|
||||
One execution of the script: auth → fetch library → (select mode or filter undownloaded)
|
||||
→ download each (sequentially or in parallel) → write history → print summary → exit.
|
||||
|
||||
### **Workers**
|
||||
@@ -97,3 +97,18 @@ Endpoints:
|
||||
- GET /api/v10/download-manifest?isbn= — MP3 download manifest (parts[], tracks[])
|
||||
- GET /api/v10/explore/audiobook_details/{isbn} — Full book details
|
||||
- GET /api/v10/library/{isbn}/pdf_extra_url?filename= — PDF extra download URL
|
||||
|
||||
## Select Mode
|
||||
|
||||
### **Select Mode**
|
||||
Optional interactive book selection, activated by `--select` CLI flag (off by default).
|
||||
Replaces the automatic history-filter + `--limit` pipeline stage with a user-driven TUI.
|
||||
Requires a TTY; exits with error if stdout is not a terminal.
|
||||
Powered by `questionary` library.
|
||||
|
||||
When active, the pipeline becomes:
|
||||
auth → fetch library → hide already-downloaded → open checkbox TUI
|
||||
→ user picks books → confirm summary (y/N) → download(selected) → write history.
|
||||
|
||||
Selection rows show: `Title — First Author [Series #]`. All books unchecked by default.
|
||||
Empty selection → exit 0. All books already downloaded → same "caught up" message as non-select mode.
|
||||
@@ -25,8 +25,11 @@ No Docker. No JVM. Just `pip install` and go.
|
||||
# 1. Install
|
||||
pip install librofm-downloader
|
||||
|
||||
# 2. Configure
|
||||
cat > config.yaml << 'EOF'
|
||||
# 2. Create XDG config directory
|
||||
mkdir -p ~/.config/librofm-downloader
|
||||
|
||||
# 3. Configure
|
||||
cat > ~/.config/librofm-downloader/config.yaml << 'EOF'
|
||||
librofm:
|
||||
format: m4b_mp3_fallback
|
||||
output_dir: ./audiobooks
|
||||
@@ -34,7 +37,7 @@ librofm:
|
||||
download_covers: true
|
||||
EOF
|
||||
|
||||
cat > secrets.yaml << 'EOF'
|
||||
cat > ~/.config/librofm-downloader/secrets.yaml << 'EOF'
|
||||
librofm:
|
||||
username: your-email@example.com
|
||||
password: your-password
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
# ADR 0006: Select Mode — Interactive Book Selection
|
||||
|
||||
## Status
|
||||
|
||||
Accepted (2026-06-03)
|
||||
|
||||
## Context
|
||||
|
||||
Libro.fm-downloader downloads **all** undownloaded books from the user's library on every run. The only controls are `--limit N` (cap count) and download-history filtering (skip already-downloaded). Users with large libraries (50+ books) or limited storage want to choose specific books rather than downloading everything.
|
||||
|
||||
The tool already supports two output modes: TTY (Rich progress bars) and non-TTY/cron (plain log lines). Any interactive feature must respect this duality.
|
||||
|
||||
## Decision
|
||||
|
||||
Add a `--select` CLI flag (off by default, CLI-only — no config.yaml option) that opens an interactive checkbox TUI before downloading. When active, select mode supersedes both the history filter and `--limit`.
|
||||
|
||||
### Library: questionary
|
||||
|
||||
| Library | Verdict |
|
||||
|---|---|
|
||||
| **questionary** | **Chosen** — mature, Rich-compatible styling, checkbox prompt with fuzzy search, most popular Python interactive CLI library |
|
||||
| inquirer | Rejected — lighter but fewer features, less active maintenance |
|
||||
| Custom Rich-based | Rejected — more code to write/maintain, Rich's Live is powerful but not designed for form-style interaction |
|
||||
|
||||
### Non-TTY behavior
|
||||
|
||||
**Hard exit with error.** Select mode requires interactivity by definition. If stdout is not a terminal (piped, cron, redirected), print `"--select requires an interactive terminal (TTY)"` and exit 1.
|
||||
|
||||
Rationale: silent degradation would be surprising (user expects to pick books, gets all-or-nothing instead). A fallback to numbered-list input was considered but adds a second codepath to test and a degraded experience that most users won't encounter.
|
||||
|
||||
### Row format
|
||||
|
||||
`[ ] N. Title — First Author [Series #]`
|
||||
|
||||
- Number for easy reference
|
||||
- Title + first author (full author list available elsewhere if needed)
|
||||
- Series + number when present (helps with series ordering decisions)
|
||||
- Duration deliberately omitted: not available from `/api/v10/library` endpoint; fetching per-book from `/api/v10/explore/audiobook_details/{isbn}` adds N API calls and latency before the UI renders
|
||||
|
||||
### Default selection state
|
||||
|
||||
**All unchecked.** User must actively opt-in each book. Prevents accidental bulk downloads of large libraries.
|
||||
|
||||
### Already-downloaded books
|
||||
|
||||
**Hidden completely.** The selection list shows only undownloaded books. Already-downloaded books are filtered out before the TUI opens, same as today's automatic pipeline stage. If all books are downloaded, print the existing `"All caught up! No new books to download."` message and exit 0 — identical to non-select behavior.
|
||||
|
||||
### Post-selection confirmation
|
||||
|
||||
Always show a y/N summary after selection:
|
||||
|
||||
```
|
||||
3 books selected for download:
|
||||
• The Great Gatsby — F. Scott Fitzgerald
|
||||
• Dune — Frank Herbert
|
||||
• Project Hail Mary — Andy Weir
|
||||
|
||||
Proceed? [y/N]
|
||||
```
|
||||
|
||||
Prevents fat-finger mistakes on large libraries. No configurable threshold — always confirm.
|
||||
|
||||
### Empty selection
|
||||
|
||||
If user presses Enter without checking any boxes: print `"No books selected. Exiting."` and exit 0. Not an error — choosing nothing is valid.
|
||||
|
||||
### Pipeline integration
|
||||
|
||||
```
|
||||
BEFORE: auth → fetch_library → filter_downloaded → [limit] → download_all
|
||||
AFTER: auth → fetch_library → [--select? → select_books() : filter_downloaded+limit] → download_all
|
||||
```
|
||||
|
||||
When `--select` is on:
|
||||
1. Fetch full library
|
||||
2. Remove already-downloaded books (same `DownloadHistory` check)
|
||||
3. Verify TTY availability → error if not
|
||||
4. Convert raw dicts to `Book` objects
|
||||
5. Open questionary checkbox prompt
|
||||
6. On confirm: show summary, ask y/N
|
||||
7. Pass selected books to existing `download_all_books()` orchestrator
|
||||
8. Continue with normal progress reporting, history writing, summary
|
||||
|
||||
### Code location
|
||||
|
||||
New module: `librofm_downloader/selector.py`
|
||||
|
||||
Single public function:
|
||||
```python
|
||||
def select_books(books: list[Book]) -> list[Book]:
|
||||
"""Open interactive TUI, return user-selected books."""
|
||||
```
|
||||
|
||||
CLI integration in `cli.py`: add `--select` argument, branch between select mode and existing auto-filter path before the download stage.
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
|
||||
- Users control exactly what downloads — no more bulk downloads of unwanted books
|
||||
- Works naturally with existing parallel download infrastructure (`download_all_books` accepts any book list)
|
||||
- Zero changes to download pipeline, history, or progress reporting
|
||||
- Clear mental model: `--select` means "I'll pick"; no flag means "auto-download everything new"
|
||||
|
||||
### Negative
|
||||
|
||||
- New runtime dependency: `questionary` (adds ~200KB installed, pulls in `prompt_toolkit`)
|
||||
- Interactive-only feature: cannot be used in cron or piped contexts
|
||||
- `--limit` becomes meaningless when `--select` is on (documented, not silently ignored)
|
||||
- Test complexity: questionary's TUI requires mocking/patching for unit tests
|
||||
|
||||
### Risks
|
||||
|
||||
- **questionary abandonment**: mitigated by it being the most popular choice; thin wrapper around `prompt_toolkit`; could swap to custom Rich implementation if needed
|
||||
- **Large libraries (100+ books)**: questionary's checkbox handles scrolling natively; row format is compact; fuzzy search helps narrow down
|
||||
- **Terminal width**: rows are ~60-80 chars average; should fit 80-column terminals
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
1. **Numbered list + comma input**: Zero dependencies, works anywhere. Rejected — poor UX for 20+ books, no visual feedback, hard to correct mistakes.
|
||||
2. **Per-book y/n prompts**: Simplest possible interactive mode. Rejected — unbearable for 30+ books ("Download this? [y/n]" × 30).
|
||||
3. **Config-driven include/exclude lists**: `only_isbns: [...]` or `skip_titles: [...]` in config.yaml. Rejected — requires editing config before each run; defeats the purpose of "pick what I want right now."
|
||||
4. **Web UI / separate selector tool**: Overengineered for a CLI-first tool.
|
||||
@@ -0,0 +1,63 @@
|
||||
# Issue #22: XDG config path resolution with CWD fallback
|
||||
|
||||
> **Date:** 2026-06-04
|
||||
> **Type:** issue
|
||||
> **Reference:** [GitHub #22](https://github.com/AlexKucera/librofm-downloader/issues/22) · Parent [#21](https://github.com/AlexKucera/librofm-downloader/issues/21)
|
||||
|
||||
## Goal
|
||||
|
||||
Build a path resolution engine for config files that searches `~/.config/librofm-downloader/` (XDG) first, then falls back to CWD. Wire it into `load_config()` so passing `None` for either path triggers search. Missing `config.yaml` is non-fatal (defaulted Config). Missing `secrets.yaml` is fatal (domain error listing searched paths). All OS exceptions caught internally → domain errors only. CLI should print a notice when running on built-in defaults.
|
||||
|
||||
## What Was Done
|
||||
|
||||
- Added `_resolve_config_file(filename)` to `config.py` — searches XDG (`~/.config/librofm-downloader/`) then CWD, auto-creates XDG dir, returns `Path | None`
|
||||
- Modified `load_config()` signature to accept `Path | str | None` for both params; `None` triggers resolver
|
||||
- Missing `config.yaml` path → `config_yaml = {}` (all fields get built-in defaults from `.get()` calls)
|
||||
- Missing `secrets.yaml` path → raises `ConfigError` listing both searched locations in order
|
||||
- All `FileNotFoundError`/`OSError` from file I/O caught and re-raised as `ConfigError`
|
||||
- Added `_config_path: Path | None = None` field to `Config` dataclass — sentinel for "used defaults"
|
||||
- CLI `run()` and argparse defaults changed from `"config.yaml"`/`"secrets.yaml"` to `None` so resolver activates
|
||||
- CLI prints `[yellow]config.yaml not found. Using built-in defaults.[/yellow]` when `_config_path is None`
|
||||
- 9 new tests across `TestResolveConfigFile` (5) and `TestLoadConfigWithResolution` (4)
|
||||
- **181 total tests pass** (was 172)
|
||||
|
||||
## Decisions & Rationale
|
||||
|
||||
| Decision | Rationale |
|
||||
|----------|-----------|
|
||||
| `_config_path` private field on `Config` for defaults signal | Non-breaking: existing code ignores it, CLI can check it. Frozen dataclass prevents mutation. Alternatives: return tuple (breaks signature), raise warning (invisible). |
|
||||
| `ConfigError` for missing secrets (not `FileNotFoundError`) | AC requires no OS exceptions leak to callers. Domain error lists searched paths so user knows where to put the file. |
|
||||
| Missing config → empty dict, not exception | AC says non-fatal. All `Config` fields have sensible defaults via `.get()`. Credentials come from secrets only. |
|
||||
| CLI defaults to `None` (not filename strings) | Original defaults of `"config.yaml"` bypassed the resolver entirely — `load_config` only searches when it receives `None`. |
|
||||
| XDG dir auto-created on every resolution call | AC requires it. `mkdir(parents=True, exist_ok=True)` is idempotent and cheap. Ensures the dir exists for users to drop files into. |
|
||||
|
||||
## Gotchas & Fixes
|
||||
|
||||
| Problem | Root Cause | Fix |
|
||||
|---------|------------|-----|
|
||||
| `ConfigError` not imported in test file | New test class used `ConfigError` but only subclasses were imported | Added `ConfigError` to the import block |
|
||||
| Test created `config/` instead of `.config/` | Test XDG path used `"config"` without leading dot, but implementation uses `.config` | Fixed test to use `tmp_path / ".config" / "librofm-downloader"` |
|
||||
| `environ.get("HOME", "~").expanduser()` — `AttributeError` | Called `.expanduser()` on a `str`, not `Path` | Changed to `Path(environ.get("HOME", "~")).expanduser()` |
|
||||
| `mkdir()` called after `chdir()` in test | Test ordered `monkeypatch.chdir()` before creating the CWD directory | Reordered: `mkdir()` first, then `chdir()` |
|
||||
| CLI showed `Config error: Cannot read config file 'config.yaml': [Errno 2]` | CLI argparse defaults were `"config.yaml"` strings — `load_config` received a path, not `None`, so resolver never ran | Changed CLI and argparse defaults to `None` |
|
||||
| Duplicate `InvalidFormatError` class + orphaned docstring | Edit operation merged old code into new location | Removed duplicate, kept single definition |
|
||||
| Extra `"` in docstring → `SyntaxError` | Corrupted edit left 4 closing quotes instead of 3 | Fixed to `"""Invalid audio format value."""` |
|
||||
|
||||
## Files Changed
|
||||
|
||||
| File | Change Summary |
|
||||
|------|---------------|
|
||||
| `librofm_downloader/config.py` | Added `_resolve_config_file()`, modified `load_config()` to accept `None`, added `_config_path` field to `Config`, wrapped I/O in try/except for domain errors |
|
||||
| `librofm_downloader/cli.py` | Changed `run()` and argparse defaults from `"config.yaml"`/`"secrets.yaml"` to `None`, added "using built-in defaults" notice |
|
||||
| `tests/test_config.py` | Added `ConfigError` + `_resolve_config_file` imports, 9 new tests in `TestResolveConfigFile` and `TestLoadConfigWithResolution` |
|
||||
|
||||
## Open Items & Next Steps
|
||||
|
||||
- [ ] Update CLI `--help` text to mention XDG search behavior
|
||||
- [ ] Consider adding `XDG_CONFIG_HOME` override (currently hardcoded to `~/.config`)
|
||||
- [ ] Update README/docs to document XDG config location and CWD fallback
|
||||
- [ ] GitNexus index needs rebuild (`npx gitnexus analyze`) after these changes
|
||||
|
||||
---
|
||||
|
||||
*Log written by write-log skill*
|
||||
@@ -0,0 +1,52 @@
|
||||
# Issue #23: Wire XDG Path Resolution into CLI Layer
|
||||
|
||||
> **Date:** 2026-06-04
|
||||
> **Type:** issue
|
||||
> **Reference:** [GitHub #23](https://github.com/AlexKucera/librofm-downloader/issues/23) · Parent [#21](https://github.com/AlexKucera/librofm-downloader/issues/21)
|
||||
|
||||
## Goal
|
||||
|
||||
Wire the path resolver from Issue #22 into the CLI layer so that running `librofm-downloader` with no flags finds config/secrets/history via XDG→CWD search. History path defaults to XDG location. Missing config prints searched paths. Verbose mode shows resolved file locations. Explicit CLI flags bypass search entirely.
|
||||
|
||||
## What Was Done
|
||||
|
||||
- Changed `run()` parameter `history_path` default from `"download_history.json"` to `None` so the resolver activates
|
||||
- Added history path resolution block in `run()`: calls `_resolve_config_file("download_history.json")` (XDG→CWD search); falls back to `~/.config/librofm-downloader/download_history.json` if not found anywhere
|
||||
- Imported `_resolve_config_file` from `config.py` into `cli.py`
|
||||
- Enhanced missing-config message to list searched paths: `"config.yaml not found in ~/.config/librofm-downloader/config.yaml → ./config.yaml. Using built-in defaults."`
|
||||
- Added verbose resolved-paths display after config load showing `config`, `secrets`, `history` with actual resolved filesystem paths (not input args)
|
||||
- Changed argparse `--history` default from `"download_history.json"` to `None` with updated help text
|
||||
- 7 new tests across 3 test classes: `TestCLIHistoryResolution` (3), `TestCLIConfigResolutionMessages` (2), `TestCLIMissingFilesErrors` (2)
|
||||
- **188 tests pass** (was 181 → +7 new)
|
||||
- **All 10 acceptance criteria met**
|
||||
|
||||
## Decisions & Rationale
|
||||
|
||||
| Decision | Rationale |
|
||||
|----------|-----------|
|
||||
| History resolves before config load | History path is needed by `DownloadHistory.__init__()`, which happens before downloads; resolving early avoids expanding `load_config`'s responsibility |
|
||||
| History defaults to XDG location (not CWD) when not found | Consistent with XDG-first resolution strategy; CWD is only a read fallback, not a default-write location |
|
||||
| Verbose block moved to after config load | The actual resolved paths aren't known until after `load_config` runs and `_resolve_config_file` has been called; showing paths before resolution would display `None` |
|
||||
| `_resolve_config_file` reused for history | Same XDG→CWD search logic; no need for a separate history resolver |
|
||||
| Verbose re-calls `_resolve_config_file` for secrets display | At that point `secrets_path` is already consumed by `load_config`; re-resolving is cheap (two `is_file()` checks) and avoids threading the resolved path through |
|
||||
|
||||
## Gotchas & Fixes
|
||||
|
||||
*None* — all 7 vertical slices passed cleanly on first implementation attempt. No test failures requiring iteration.
|
||||
|
||||
## Files Changed
|
||||
|
||||
| File | Change Summary |
|
||||
|------|---------------|
|
||||
| `librofm_downloader/cli.py` | `history_path` default → `None`; XDG resolution for history path; verbose resolved-paths display; argparse `--history` default → `None`; enhanced missing-config message with searched paths; imported `_resolve_config_file` |
|
||||
| `tests/test_cli.py` | 7 new tests: `TestCLIHistoryResolution` (3), `TestCLIConfigResolutionMessages` (2), `TestCLIMissingFilesErrors` (2) |
|
||||
|
||||
## Open Items & Next Steps
|
||||
|
||||
- [ ] Update CLI `--help` text to mention XDG search behavior for `--history`
|
||||
- [ ] Update README/docs to document XDG config location and history defaults
|
||||
- [ ] GitNexus index needs rebuild (`npx gitnexus analyze`) after these changes
|
||||
|
||||
---
|
||||
|
||||
*Log written by write-log skill*
|
||||
@@ -1223,20 +1223,20 @@
|
||||
<tr>
|
||||
<td><code>--config</code></td>
|
||||
<td></td>
|
||||
<td><code>config.yaml</code></td>
|
||||
<td>Path to <code>config.yaml</code></td>
|
||||
<td>XDG → CWD search</td>
|
||||
<td>Path to <code>config.yaml</code> (overrides default search)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>--secrets</code></td>
|
||||
<td></td>
|
||||
<td><code>secrets.yaml</code></td>
|
||||
<td>Path to <code>secrets.yaml</code></td>
|
||||
<td>XDG → CWD search</td>
|
||||
<td>Path to <code>secrets.yaml</code> (overrides default search)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>--history</code></td>
|
||||
<td></td>
|
||||
<td><code>download_history.json</code></td>
|
||||
<td>Path to download history JSON file</td>
|
||||
<td>XDG → CWD search</td>
|
||||
<td>Path to download history JSON (overrides default search)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>-v, --verbose</code></td>
|
||||
@@ -1261,9 +1261,9 @@
|
||||
<h3 id="-verbose">--verbose</h3>
|
||||
<p>Shows internal pipeline state at each stage:</p>
|
||||
<div class="language-text highlight"><pre><span></span><code><span id="__span_0__-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a>── config ──────────────────────────────────────
|
||||
</span><span id="__span_0__-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a> config: config.yaml
|
||||
</span><span id="__span_0__-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a> secrets: secrets.yaml
|
||||
</span><span id="__span_0__-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a> history: download_history.json
|
||||
</span><span id="__span_0__-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a> config: ~/.config/librofm-downloader/config.yaml
|
||||
</span><span id="__span_0__-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a> secrets: ~/.config/librofm-downloader/secrets.yaml
|
||||
</span><span id="__span_0__-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a> history: ~/.config/librofm-downloader/download_history.json
|
||||
</span><span id="__span_0__-1-5"><a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a> format: m4b_mp3_fallback
|
||||
</span><span id="__span_0__-1-6"><a id="__codelineno-1-6" name="__codelineno-1-6" href="#__codelineno-1-6"></a> output: ./audiobooks
|
||||
</span><span id="__span_0__-1-7"><a id="__codelineno-1-7" name="__codelineno-1-7" href="#__codelineno-1-7"></a> extras: True
|
||||
|
||||
+143
-35
@@ -523,14 +523,42 @@
|
||||
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#file-locations" class="md-nav__link">
|
||||
<a href="#default-file-locations" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
File locations
|
||||
Default file locations
|
||||
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="Default file locations">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#missing-files-config-vs-secrets" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
Missing files: config vs secrets
|
||||
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#overriding-with-cli-flags" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
Overriding with CLI flags
|
||||
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@@ -857,14 +885,42 @@
|
||||
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#file-locations" class="md-nav__link">
|
||||
<a href="#default-file-locations" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
File locations
|
||||
Default file locations
|
||||
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="Default file locations">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#missing-files-config-vs-secrets" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
Missing files: config vs secrets
|
||||
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#overriding-with-cli-flags" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
Overriding with CLI flags
|
||||
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@@ -971,12 +1027,52 @@
|
||||
|
||||
|
||||
<h1 id="configuration-reference">Configuration Reference</h1>
|
||||
<p>Complete reference for <code>config.yaml</code> and <code>secrets.yaml</code>.</p>
|
||||
<h2 id="file-locations">File locations</h2>
|
||||
<p>The CLI looks for these files in the <strong>current working directory</strong> by default:</p>
|
||||
<div class="language-bash highlight"><pre><span></span><code><span id="__span_0__-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a>librofm-downloader<span class="w"> </span>--config<span class="w"> </span>config.yaml<span class="w"> </span>--secrets<span class="w"> </span>secrets.yaml
|
||||
<p>Complete reference for <code>config.yaml</code>, <code>secrets.yaml</code>, and download history.</p>
|
||||
<h2 id="default-file-locations">Default file locations</h2>
|
||||
<p>When no <code>--config</code>, <code>--secrets</code>, or <code>--history</code> flags are provided, the tool searches for each file in this order:</p>
|
||||
<ol>
|
||||
<li><strong>XDG directory</strong> — <code>~/.config/librofm-downloader/</code></li>
|
||||
<li><strong>Current working directory</strong> (CWD)</li>
|
||||
</ol>
|
||||
<p>The XDG directory is <strong>created automatically</strong> on first run if it doesn't exist. This means you can drop your files into <code>~/.config/librofm-downloader/</code> and run <code>librofm-downloader</code> from any directory.</p>
|
||||
<div class="language-text highlight"><pre><span></span><code><span id="__span_0__-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a>~/.config/librofm-downloader/
|
||||
</span><span id="__span_0__-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a>├── config.yaml # optional — built-in defaults used if missing
|
||||
</span><span id="__span_0__-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a>├── secrets.yaml # required — tool exits with an error if missing
|
||||
</span><span id="__span_0__-0-4"><a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a>└── download_history.json # created automatically on first download
|
||||
</span></code></pre></div>
|
||||
<p>Both files share the same top-level key: <code>librofm</code>.</p>
|
||||
<h3 id="missing-files-config-vs-secrets">Missing files: config vs secrets</h3>
|
||||
<p>The two config files have different missing-file behavior:</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>File</th>
|
||||
<th>If missing</th>
|
||||
<th>Behavior</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>config.yaml</code></td>
|
||||
<td>Non-fatal</td>
|
||||
<td>Tool runs with built-in defaults (m4b_mp3_fallback, <code>./audiobooks</code>, etc.). A notice is printed listing searched paths.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>secrets.yaml</code></td>
|
||||
<td>Fatal</td>
|
||||
<td>Tool exits with code <strong>1</strong> and an error listing both searched locations so you know where to create it.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 id="overriding-with-cli-flags">Overriding with CLI flags</h3>
|
||||
<p>Use <code>--config</code>, <code>--secrets</code>, and <code>--history</code> to bypass the XDG→CWD search entirely and point at specific files:</p>
|
||||
<div class="language-bash highlight"><pre><span></span><code><span id="__span_0__-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="c1"># Use files in a custom location</span>
|
||||
</span><span id="__span_0__-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a>librofm-downloader<span class="w"> </span>--config<span class="w"> </span>/path/to/config.yaml<span class="w"> </span>--secrets<span class="w"> </span>/path/to/secrets.yaml
|
||||
</span><span id="__span_0__-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a>
|
||||
</span><span id="__span_0__-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a><span class="c1"># Custom history file</span>
|
||||
</span><span id="__span_0__-1-5"><a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a>librofm-downloader<span class="w"> </span>--history<span class="w"> </span>/path/to/download_history.json
|
||||
</span></code></pre></div>
|
||||
<p>When a flag is provided, that path is used directly — no search is performed.</p>
|
||||
<p>Both config files share the same top-level key: <code>librofm</code>.</p>
|
||||
<h2 id="secretsyaml">secrets.yaml</h2>
|
||||
<p>Credentials only. This file must <strong>not</strong> be committed to version control.</p>
|
||||
<table>
|
||||
@@ -1003,9 +1099,9 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="language-yaml highlight"><pre><span></span><code><span id="__span_0__-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="nt">librofm</span><span class="p">:</span>
|
||||
</span><span id="__span_0__-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="w"> </span><span class="nt">username</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">your-email@example.com</span>
|
||||
</span><span id="__span_0__-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a><span class="w"> </span><span class="nt">password</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">your-password</span>
|
||||
<div class="language-yaml highlight"><pre><span></span><code><span id="__span_0__-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="nt">librofm</span><span class="p">:</span>
|
||||
</span><span id="__span_0__-2-2"><a id="__codelineno-2-2" name="__codelineno-2-2" href="#__codelineno-2-2"></a><span class="w"> </span><span class="nt">username</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">your-email@example.com</span>
|
||||
</span><span id="__span_0__-2-3"><a id="__codelineno-2-3" name="__codelineno-2-3" href="#__codelineno-2-3"></a><span class="w"> </span><span class="nt">password</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">your-password</span>
|
||||
</span></code></pre></div>
|
||||
<blockquote>
|
||||
<p>[!IMPORTANT]
|
||||
@@ -1013,7 +1109,7 @@ Only <code>username</code> and <code>password</code> belong in this file. All ot
|
||||
If either field is missing, the tool exits with code <strong>1</strong> and an error message.</p>
|
||||
</blockquote>
|
||||
<h2 id="configyaml">config.yaml</h2>
|
||||
<p>All non-credential settings. Safe to commit.</p>
|
||||
<p>All non-credential settings. Safe to commit. <strong>Optional</strong> — if missing, built-in defaults are used.</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -1057,18 +1153,18 @@ If either field is missing, the tool exits with code <strong>1</strong> and an e
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 id="full-example">Full example</h3>
|
||||
<div class="language-yaml highlight"><pre><span></span><code><span id="__span_0__-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="nt">librofm</span><span class="p">:</span>
|
||||
</span><span id="__span_0__-2-2"><a id="__codelineno-2-2" name="__codelineno-2-2" href="#__codelineno-2-2"></a><span class="w"> </span><span class="nt">format</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">m4b_mp3_fallback</span>
|
||||
</span><span id="__span_0__-2-3"><a id="__codelineno-2-3" name="__codelineno-2-3" href="#__codelineno-2-3"></a><span class="w"> </span><span class="nt">output_dir</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./audiobooks</span>
|
||||
</span><span id="__span_0__-2-4"><a id="__codelineno-2-4" name="__codelineno-2-4" href="#__codelineno-2-4"></a><span class="w"> </span><span class="nt">download_extras</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">true</span>
|
||||
</span><span id="__span_0__-2-5"><a id="__codelineno-2-5" name="__codelineno-2-5" href="#__codelineno-2-5"></a><span class="w"> </span><span class="nt">download_covers</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">true</span>
|
||||
</span><span id="__span_0__-2-6"><a id="__codelineno-2-6" name="__codelineno-2-6" href="#__codelineno-2-6"></a><span class="w"> </span><span class="nt">workers</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">3</span>
|
||||
<div class="language-yaml highlight"><pre><span></span><code><span id="__span_0__-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="nt">librofm</span><span class="p">:</span>
|
||||
</span><span id="__span_0__-3-2"><a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a><span class="w"> </span><span class="nt">format</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">m4b_mp3_fallback</span>
|
||||
</span><span id="__span_0__-3-3"><a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a><span class="w"> </span><span class="nt">output_dir</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">./audiobooks</span>
|
||||
</span><span id="__span_0__-3-4"><a id="__codelineno-3-4" name="__codelineno-3-4" href="#__codelineno-3-4"></a><span class="w"> </span><span class="nt">download_extras</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">true</span>
|
||||
</span><span id="__span_0__-3-5"><a id="__codelineno-3-5" name="__codelineno-3-5" href="#__codelineno-3-5"></a><span class="w"> </span><span class="nt">download_covers</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">true</span>
|
||||
</span><span id="__span_0__-3-6"><a id="__codelineno-3-6" name="__codelineno-3-6" href="#__codelineno-3-6"></a><span class="w"> </span><span class="nt">workers</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">3</span>
|
||||
</span></code></pre></div>
|
||||
<h3 id="minimal-example">Minimal example</h3>
|
||||
<p>Only <code>format</code> is meaningful here — everything else has a default:</p>
|
||||
<div class="language-yaml highlight"><pre><span></span><code><span id="__span_0__-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="nt">librofm</span><span class="p">:</span>
|
||||
</span><span id="__span_0__-3-2"><a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a><span class="w"> </span><span class="nt">format</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">mp3_only</span>
|
||||
</span><span id="__span_0__-3-3"><a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a><span class="w"> </span><span class="nt">workers</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">5</span><span class="w"> </span><span class="c1"># high-bandwidth connection</span>
|
||||
<div class="language-yaml highlight"><pre><span></span><code><span id="__span_0__-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="nt">librofm</span><span class="p">:</span>
|
||||
</span><span id="__span_0__-4-2"><a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a><span class="w"> </span><span class="nt">format</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">mp3_only</span>
|
||||
</span><span id="__span_0__-4-3"><a id="__codelineno-4-3" name="__codelineno-4-3" href="#__codelineno-4-3"></a><span class="w"> </span><span class="nt">workers</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">5</span><span class="w"> </span><span class="c1"># high-bandwidth connection</span>
|
||||
</span></code></pre></div>
|
||||
<h2 id="how-merging-works">How merging works</h2>
|
||||
<p><code>config.yaml</code> and <code>secrets.yaml</code> are <strong>deep-merged</strong> at startup:</p>
|
||||
@@ -1078,8 +1174,8 @@ If either field is missing, the tool exits with code <strong>1</strong> and an e
|
||||
<li>The merged result is validated</li>
|
||||
</ol>
|
||||
<p>This means you could theoretically put any field in either file — but <strong>credentials in <code>config.yaml</code> are explicitly rejected</strong> at load time with a clear error:</p>
|
||||
<div class="language-text highlight"><pre><span></span><code><span id="__span_0__-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a>Config error: Credentials (username, password) found in config.yaml.
|
||||
</span><span id="__span_0__-4-2"><a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a>Move them to secrets.yaml (which is gitignored).
|
||||
<div class="language-text highlight"><pre><span></span><code><span id="__span_0__-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a>Config error: Credentials (username, password) found in config.yaml.
|
||||
</span><span id="__span_0__-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a>Move them to secrets.yaml (which is gitignored).
|
||||
</span></code></pre></div>
|
||||
<h2 id="validation-errors">Validation errors</h2>
|
||||
<table>
|
||||
@@ -1107,6 +1203,16 @@ If either field is missing, the tool exits with code <strong>1</strong> and an e
|
||||
<td>Use one of: <code>m4b_mp3_fallback</code>, <code>mp3_only</code>, <code>m4b_only</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>config.yaml not found in ~/.config/.../config.yaml → ./config.yaml. Using built-in defaults.</code></td>
|
||||
<td>No config file in either location</td>
|
||||
<td>Non-fatal — defaults used. Create <code>config.yaml</code> to customize.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>Missing secrets.yaml. Searched: ~/.config/.../secrets.yaml → ./secrets.yaml.</code></td>
|
||||
<td>No secrets file in either location</td>
|
||||
<td>Create <code>secrets.yaml</code> with your credentials in one of the searched locations.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>Invalid workers value: 0</code></td>
|
||||
<td>Workers < 1</td>
|
||||
<td>Set <code>workers</code> to an integer ≥ 1</td>
|
||||
@@ -1114,21 +1220,23 @@ If either field is missing, the tool exits with code <strong>1</strong> and an e
|
||||
</tbody>
|
||||
</table>
|
||||
<h2 id="download-history">Download history</h2>
|
||||
<p>A third file, <code>download_history.json</code>, is created automatically on first run:</p>
|
||||
<div class="language-json highlight"><pre><span></span><code><span id="__span_0__-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="p">{</span>
|
||||
</span><span id="__span_0__-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a><span class="w"> </span><span class="nt">"9780743565400"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span>
|
||||
</span><span id="__span_0__-5-3"><a id="__codelineno-5-3" name="__codelineno-5-3" href="#__codelineno-5-3"></a><span class="w"> </span><span class="nt">"isbn"</span><span class="p">:</span><span class="w"> </span><span class="s2">"9780743565400"</span><span class="p">,</span>
|
||||
</span><span id="__span_0__-5-4"><a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="w"> </span><span class="nt">"title"</span><span class="p">:</span><span class="w"> </span><span class="s2">"The Way of Kings"</span><span class="p">,</span>
|
||||
</span><span id="__span_0__-5-5"><a id="__codelineno-5-5" name="__codelineno-5-5" href="#__codelineno-5-5"></a><span class="w"> </span><span class="nt">"format"</span><span class="p">:</span><span class="w"> </span><span class="s2">"m4b"</span><span class="p">,</span>
|
||||
</span><span id="__span_0__-5-6"><a id="__codelineno-5-6" name="__codelineno-5-6" href="#__codelineno-5-6"></a><span class="w"> </span><span class="nt">"path"</span><span class="p">:</span><span class="w"> </span><span class="s2">"./audiobooks/Brandon Sanderson/The Way of Kings/The Way of Kings.m4b"</span><span class="p">,</span>
|
||||
</span><span id="__span_0__-5-7"><a id="__codelineno-5-7" name="__codelineno-5-7" href="#__codelineno-5-7"></a><span class="w"> </span><span class="nt">"downloaded_at"</span><span class="p">:</span><span class="w"> </span><span class="s2">"2026-06-03T10:30:00+00:00"</span>
|
||||
</span><span id="__span_0__-5-8"><a id="__codelineno-5-8" name="__codelineno-5-8" href="#__codelineno-5-8"></a><span class="w"> </span><span class="p">}</span>
|
||||
</span><span id="__span_0__-5-9"><a id="__codelineno-5-9" name="__codelineno-5-9" href="#__codelineno-5-9"></a><span class="p">}</span>
|
||||
<p>A third file, <code>download_history.json</code>, tracks what's been downloaded. It follows the same XDG→CWD search order as the config files, and defaults to the XDG directory when not found anywhere:</p>
|
||||
<div class="language-text highlight"><pre><span></span><code><span id="__span_0__-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a>~/.config/librofm-downloader/download_history.json
|
||||
</span></code></pre></div>
|
||||
<p>The file is created automatically on first download. Override with <code>--history</code> to use a custom location.</p>
|
||||
<div class="language-json highlight"><pre><span></span><code><span id="__span_0__-7-1"><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a><span class="p">{</span>
|
||||
</span><span id="__span_0__-7-2"><a id="__codelineno-7-2" name="__codelineno-7-2" href="#__codelineno-7-2"></a><span class="w"> </span><span class="nt">"9780743565400"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span>
|
||||
</span><span id="__span_0__-7-3"><a id="__codelineno-7-3" name="__codelineno-7-3" href="#__codelineno-7-3"></a><span class="w"> </span><span class="nt">"isbn"</span><span class="p">:</span><span class="w"> </span><span class="s2">"9780743565400"</span><span class="p">,</span>
|
||||
</span><span id="__span_0__-7-4"><a id="__codelineno-7-4" name="__codelineno-7-4" href="#__codelineno-7-4"></a><span class="w"> </span><span class="nt">"title"</span><span class="p">:</span><span class="w"> </span><span class="s2">"The Way of Kings"</span><span class="p">,</span>
|
||||
</span><span id="__span_0__-7-5"><a id="__codelineno-7-5" name="__codelineno-7-5" href="#__codelineno-7-5"></a><span class="w"> </span><span class="nt">"format"</span><span class="p">:</span><span class="w"> </span><span class="s2">"m4b"</span><span class="p">,</span>
|
||||
</span><span id="__span_0__-7-6"><a id="__codelineno-7-6" name="__codelineno-7-6" href="#__codelineno-7-6"></a><span class="w"> </span><span class="nt">"path"</span><span class="p">:</span><span class="w"> </span><span class="s2">"./audiobooks/Brandon Sanderson/The Way of Kings/The Way of Kings.m4b"</span><span class="p">,</span>
|
||||
</span><span id="__span_0__-7-7"><a id="__codelineno-7-7" name="__codelineno-7-7" href="#__codelineno-7-7"></a><span class="w"> </span><span class="nt">"downloaded_at"</span><span class="p">:</span><span class="w"> </span><span class="s2">"2026-06-03T10:30:00+00:00"</span>
|
||||
</span><span id="__span_0__-7-8"><a id="__codelineno-7-8" name="__codelineno-7-8" href="#__codelineno-7-8"></a><span class="w"> </span><span class="p">}</span>
|
||||
</span><span id="__span_0__-7-9"><a id="__codelineno-7-9" name="__codelineno-7-9" href="#__codelineno-7-9"></a><span class="p">}</span>
|
||||
</span></code></pre></div>
|
||||
<ul>
|
||||
<li>Keyed by <strong>ISBN</strong> — each book is recorded once</li>
|
||||
<li>Used to skip already-downloaded books on subsequent runs</li>
|
||||
<li>Location defaults to <code>download_history.json</code> in CWD; override with <code>--history</code></li>
|
||||
<li>If the file is corrupt or missing, the tool starts with an empty history (and logs a warning)</li>
|
||||
</ul>
|
||||
|
||||
|
||||
@@ -1120,12 +1120,13 @@
|
||||
</span></code></pre></div>
|
||||
<p>The <code>[dev]</code> extra installs pytest for testing — omit it if you only want to run the tool.</p>
|
||||
<h2 id="2-configure">2. Configure</h2>
|
||||
<p>librofm-downloader uses two YAML files:</p>
|
||||
<p>librofm-downloader uses two YAML files, searched in <code>~/.config/librofm-downloader/</code> first, then the current working directory:</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>File</th>
|
||||
<th>Purpose</th>
|
||||
<th style="text-align: center;">Required?</th>
|
||||
<th style="text-align: center;">Committed to git?</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -1133,15 +1134,22 @@
|
||||
<tr>
|
||||
<td><code>config.yaml</code></td>
|
||||
<td>Preferences (format, output dir, toggles)</td>
|
||||
<td style="text-align: center;">No (defaults used)</td>
|
||||
<td style="text-align: center;">✅ Yes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>secrets.yaml</code></td>
|
||||
<td>Credentials only</td>
|
||||
<td style="text-align: center;"><strong>Yes</strong></td>
|
||||
<td style="text-align: center;">❌ No (gitignored)</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<blockquote>
|
||||
<p>[!TIP]
|
||||
The XDG directory (<code>~/.config/librofm-downloader/</code>) is created automatically on first run.
|
||||
Place both files there to run <code>librofm-downloader</code> from any directory.</p>
|
||||
</blockquote>
|
||||
<h3 id="configyaml">config.yaml</h3>
|
||||
<div class="language-yaml highlight"><pre><span></span><code><span id="__span_0__-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="c1"># libro.fm downloader configuration</span>
|
||||
</span><span id="__span_0__-2-2"><a id="__codelineno-2-2" name="__codelineno-2-2" href="#__codelineno-2-2"></a><span class="c1"># This file is safe to commit — no credentials here.</span>
|
||||
@@ -1179,10 +1187,11 @@ If you accidentally put credentials in <code>config.yaml</code>, the tool will r
|
||||
</span></code></pre></div>
|
||||
<p>This:</p>
|
||||
<ol>
|
||||
<li>Loads <code>config.yaml</code> + <code>secrets.yaml</code></li>
|
||||
<li>Searches for <code>config.yaml</code> + <code>secrets.yaml</code> (XDG directory first, then CWD)</li>
|
||||
<li>Authenticates with Libro.fm via OAuth2 password grant</li>
|
||||
<li>Fetches your full library (all pages)</li>
|
||||
<li>Skips books already in <code>download_history.json</code></li>
|
||||
<li>Skips books already in <code>download_history.json</code> (XDG → CWD search)</li>
|
||||
<li>Downloads each new book with a progress bar</li>
|
||||
<li>Downloads each new book (3 parallel workers by default) with a progress bar</li>
|
||||
<li>Records successful downloads to history</li>
|
||||
</ol>
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"],"fields":{"title":{"boost":1000.0},"text":{"boost":1.0},"tags":{"boost":1000000.0}}},"docs":[{"location":"index.html","title":"librofm-downloader","text":"<p>Download owned audiobooks from your Libro.fm account \u2014 a lightweight, dependency-minimal CLI tool written in Python.</p> <p>No Docker. No JVM. Just <code>pip install</code> and go.</p>"},{"location":"index.html#features","title":"Features","text":"<ul> <li>Full library sync \u2014 fetches every audiobook in your Libro.fm account with automatic pagination</li> <li>M4B + MP3 formats \u2014 downloads M4B (single file) or MP3 (ZIP parts extracted) with automatic fallback</li> <li>Resume support \u2014 interrupted downloads pick up where they left off via <code>.partial</code> files</li> <li>Cover art & PDF extras \u2014 optional download of cover images and accompanying PDFs</li> <li>Customizable output paths \u2014 token-based patterns for organizing your library on disk</li> <li>TTY-aware progress \u2014 rich progress bars in your terminal, clean log lines in cron jobs</li> <li>Download history \u2014 tracks what's been downloaded so re-runs only fetch new books</li> <li>Graceful failure isolation \u2014 one failed book doesn't stop the rest</li> </ul>"},{"location":"index.html#quick-start","title":"Quick Start","text":"<pre><code># 1. Install\npip install librofm-downloader\n\n# 2. Configure\ncat > config.yaml << 'EOF'\nlibrofm:\n format: m4b_mp3_fallback\n output_dir: ./audiobooks\n download_extras: true\n download_covers: true\nEOF\n\ncat > secrets.yaml << 'EOF'\nlibrofm:\n username: your-email@example.com\n password: your-password\nEOF\n\n# 3. Run\nlibrofm-downloader\n</code></pre> <p>See Quickstart for the full walkthrough, or jump to Configuration Reference for every option.</p>"},{"location":"cli-usage.html","title":"CLI Usage","text":"<p>Command-line interface reference for <code>librofm-downloader</code>.</p>"},{"location":"cli-usage.html#synopsis","title":"Synopsis","text":"<pre><code>librofm-downloader [OPTIONS]\n</code></pre>"},{"location":"cli-usage.html#options","title":"Options","text":"Option Short Default Description <code>--config</code> <code>config.yaml</code> Path to <code>config.yaml</code> <code>--secrets</code> <code>secrets.yaml</code> Path to <code>secrets.yaml</code> <code>--history</code> <code>download_history.json</code> Path to download history JSON file <code>-v, --verbose</code> off Print extra detail (URLs, paths, API responses) <code>--limit</code> N <code>0</code> (no limit) Maximum number of books to download <code>-w, --workers</code> N <code>3</code> Number of parallel download workers (1 = sequential)"},{"location":"cli-usage.html#-verbose","title":"--verbose","text":"<p>Shows internal pipeline state at each stage:</p> <pre><code>\u2500\u2500 config \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n config: config.yaml\n secrets: secrets.yaml\n history: download_history.json\n format: m4b_mp3_fallback\n output: ./audiobooks\n extras: True\n covers: True\n user: me@example.com\n\u2500\u2500 auth \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n \u2713 authenticated\n\u2500\u2500 library \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n 47 book(s) in library\n\u2500\u2500 filtering \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n 42 already downloaded, 5 new\n \u2b07 Book Title [dim](9780743565400)[/dim]\n authors: Brandon Sanderson\n narrators: Kate Reading, Michael Kramer\n ...\n 123,456,789 bytes\n</code></pre>"},{"location":"cli-usage.html#-limit","title":"--limit","text":"<p>Cap how many books are downloaded in a single run. Useful for testing:</p> <pre><code># Download only 1 book (the first new one)\nlibrofm-downloader --limit 1\n\n# Download up to 3 books\nlibrofm-downloader --limit 3 -v\n</code></pre> <p>Books are processed in the order returned by the Libro.fm API. Already-downloaded books are filtered out before the limit is applied.</p>"},{"location":"cli-usage.html#-workers","title":"--workers","text":"<p>Controls how many books download simultaneously:</p> <pre><code># Default: 3 parallel downloads\nlibrofm-downloader\n\n# High-bandwidth connection: 5 worLine truncated
|
||||
{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"],"fields":{"title":{"boost":1000.0},"text":{"boost":1.0},"tags":{"boost":1000000.0}}},"docs":[{"location":"index.html","title":"librofm-downloader","text":"<p>Download owned audiobooks from your Libro.fm account \u2014 a lightweight, dependency-minimal CLI tool written in Python.</p> <p>No Docker. No JVM. Just <code>pip install</code> and go.</p>"},{"location":"index.html#features","title":"Features","text":"<ul> <li>Full library sync \u2014 fetches every audiobook in your Libro.fm account with automatic pagination</li> <li>M4B + MP3 formats \u2014 downloads M4B (single file) or MP3 (ZIP parts extracted) with automatic fallback</li> <li>Resume support \u2014 interrupted downloads pick up where they left off via <code>.partial</code> files</li> <li>Cover art & PDF extras \u2014 optional download of cover images and accompanying PDFs</li> <li>Customizable output paths \u2014 token-based patterns for organizing your library on disk</li> <li>TTY-aware progress \u2014 rich progress bars in your terminal, clean log lines in cron jobs</li> <li>Download history \u2014 tracks what's been downloaded so re-runs only fetch new books</li> <li>Graceful failure isolation \u2014 one failed book doesn't stop the rest</li> </ul>"},{"location":"index.html#quick-start","title":"Quick Start","text":"<pre><code># 1. Install\npip install librofm-downloader\n\n# 2. Configure\ncat > config.yaml << 'EOF'\nlibrofm:\n format: m4b_mp3_fallback\n output_dir: ./audiobooks\n download_extras: true\n download_covers: true\nEOF\n\ncat > secrets.yaml << 'EOF'\nlibrofm:\n username: your-email@example.com\n password: your-password\nEOF\n\n# 3. Run\nlibrofm-downloader\n</code></pre> <p>See Quickstart for the full walkthrough, or jump to Configuration Reference for every option.</p>"},{"location":"cli-usage.html","title":"CLI Usage","text":"<p>Command-line interface reference for <code>librofm-downloader</code>.</p>"},{"location":"cli-usage.html#synopsis","title":"Synopsis","text":"<pre><code>librofm-downloader [OPTIONS]\n</code></pre>"},{"location":"cli-usage.html#options","title":"Options","text":"Option Short Default Description <code>--config</code> XDG \u2192 CWD search Path to <code>config.yaml</code> (overrides default search) <code>--secrets</code> XDG \u2192 CWD search Path to <code>secrets.yaml</code> (overrides default search) <code>--history</code> XDG \u2192 CWD search Path to download history JSON (overrides default search) <code>-v, --verbose</code> off Print extra detail (URLs, paths, API responses) <code>--limit</code> N <code>0</code> (no limit) Maximum number of books to download <code>-w, --workers</code> N <code>3</code> Number of parallel download workers (1 = sequential)"},{"location":"cli-usage.html#-verbose","title":"--verbose","text":"<p>Shows internal pipeline state at each stage:</p> <pre><code>\u2500\u2500 config \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n config: ~/.config/librofm-downloader/config.yaml\n secrets: ~/.config/librofm-downloader/secrets.yaml\n history: ~/.config/librofm-downloader/download_history.json\n format: m4b_mp3_fallback\n output: ./audiobooks\n extras: True\n covers: True\n user: me@example.com\n\u2500\u2500 auth \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n \u2713 authenticated\n\u2500\u2500 library \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n 47 book(s) in library\n\u2500\u2500 filtering \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n 42 already downloaded, 5 new\n \u2b07 Book Title [dim](9780743565400)[/dim]\n authors: Brandon Sanderson\n narrators: Kate Reading, Michael Kramer\n ...\n 123,456,789 bytes\n</code></pre>"},{"location":"cli-usage.html#-limit","title":"--limit","text":"<p>Cap how many books are downloaded in a single run. Useful for testing:</p> <pre><code># Download only 1 book (the first new one)\nlibrofm-downloader --limit 1\n\n# Download up to 3 books\nlibrofm-downloader --limit 3 -v\n</code></pre> <p>Books are processed in the order returned by the Libro.fm API. Already-downloaded books are filtered out before the limit is applied.</p>"},{"location":"cli-usage.html#-workers","title":"--workers","text":"<p>ControlLine truncated
|
||||
Binary file not shown.
@@ -1370,13 +1370,17 @@
|
||||
<li><code>m4b_only</code></li>
|
||||
</ul>
|
||||
<h3 id="errno-2-no-such-file-or-directory-configyaml">"[Errno 2] No such file or directory: 'config.yaml'"</h3>
|
||||
<p><strong>Cause:</strong> The config file doesn't exist at the specified path (default: current directory).</p>
|
||||
<p><strong>Cause:</strong> The config file doesn't exist at the specified path.</p>
|
||||
<p><strong>Fix:</strong></p>
|
||||
<div class="language-bash highlight"><pre><span></span><code><span id="__span_0__-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="c1"># Run from the directory that contains config.yaml</span>
|
||||
</span><span id="__span_0__-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="nb">cd</span><span class="w"> </span>/path/to/your/project
|
||||
</span><span id="__span_0__-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a>
|
||||
</span><span id="__span_0__-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a><span class="c1"># Or specify the path explicitly</span>
|
||||
</span><span id="__span_0__-1-5"><a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a>librofm-downloader<span class="w"> </span>--config<span class="w"> </span>/path/to/config.yaml<span class="w"> </span>--secrets<span class="w"> </span>/path/to/secrets.yaml
|
||||
<div class="language-bash highlight"><pre><span></span><code><span id="__span_0__-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="c1"># Option 1: Place files in the XDG directory (recommended)</span>
|
||||
</span><span id="__span_0__-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a>mkdir<span class="w"> </span>-p<span class="w"> </span>~/.config/librofm-downloader
|
||||
</span><span id="__span_0__-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a>cp<span class="w"> </span>config.yaml<span class="w"> </span>secrets.yaml<span class="w"> </span>~/.config/librofm-downloader/
|
||||
</span><span id="__span_0__-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a>
|
||||
</span><span id="__span_0__-1-5"><a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a><span class="c1"># Option 2: Run from the directory that contains config.yaml</span>
|
||||
</span><span id="__span_0__-1-6"><a id="__codelineno-1-6" name="__codelineno-1-6" href="#__codelineno-1-6"></a><span class="nb">cd</span><span class="w"> </span>/path/to/your/project
|
||||
</span><span id="__span_0__-1-7"><a id="__codelineno-1-7" name="__codelineno-1-7" href="#__codelineno-1-7"></a>
|
||||
</span><span id="__span_0__-1-8"><a id="__codelineno-1-8" name="__codelineno-1-8" href="#__codelineno-1-8"></a><span class="c1"># Option 3: Specify paths explicitly</span>
|
||||
</span><span id="__span_0__-1-9"><a id="__codelineno-1-9" name="__codelineno-1-9" href="#__codelineno-1-9"></a>librofm-downloader<span class="w"> </span>--config<span class="w"> </span>/path/to/config.yaml<span class="w"> </span>--secrets<span class="w"> </span>/path/to/secrets.yaml
|
||||
</span></code></pre></div>
|
||||
<h2 id="download-issues">Download issues</h2>
|
||||
<h3 id="download-stops-partway-through">Download stops partway through</h3>
|
||||
@@ -1420,19 +1424,26 @@ Run again — the failed book will be retried (it wasn't recorded in history sin
|
||||
- Already-downloaded books will be re-downloaded</p>
|
||||
<p><strong>Fix:</strong></p>
|
||||
<div class="language-bash highlight"><pre><span></span><code><span id="__span_0__-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="c1"># Option 1: Delete and let it rebuild</span>
|
||||
</span><span id="__span_0__-4-2"><a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a>rm<span class="w"> </span>download_history.json
|
||||
</span><span id="__span_0__-4-2"><a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a>rm<span class="w"> </span>~/.config/librofm-downloader/download_history.json
|
||||
</span><span id="__span_0__-4-3"><a id="__codelineno-4-3" name="__codelineno-4-3" href="#__codelineno-4-3"></a>librofm-downloader
|
||||
</span><span id="__span_0__-4-4"><a id="__codelineno-4-4" name="__codelineno-4-4" href="#__codelineno-4-4"></a>
|
||||
</span><span id="__span_0__-4-5"><a id="__codelineno-4-5" name="__codelineno-4-5" href="#__codelineno-4-5"></a><span class="c1"># Option 2: Fix the JSON manually (if you know what's in there)</span>
|
||||
</span><span id="__span_0__-4-6"><a id="__codelineno-4-6" name="__codelineno-4-6" href="#__codelineno-4-6"></a><span class="c1"># Check for trailing commas, missing braces, etc.</span>
|
||||
</span><span id="__span_0__-4-5"><a id="__codelineno-4-5" name="__codelineno-4-5" href="#__codelineno-4-5"></a><span class="c1"># Option 2: If using CWD-based history</span>
|
||||
</span><span id="__span_0__-4-6"><a id="__codelineno-4-6" name="__codelineno-4-6" href="#__codelineno-4-6"></a>rm<span class="w"> </span>download_history.json
|
||||
</span><span id="__span_0__-4-7"><a id="__codelineno-4-7" name="__codelineno-4-7" href="#__codelineno-4-7"></a>librofm-downloader
|
||||
</span><span id="__span_0__-4-8"><a id="__codelineno-4-8" name="__codelineno-4-8" href="#__codelineno-4-8"></a>
|
||||
</span><span id="__span_0__-4-9"><a id="__codelineno-4-9" name="__codelineno-4-9" href="#__codelineno-4-9"></a><span class="c1"># Option 3: Fix the JSON manually (if you know what's in there)</span>
|
||||
</span><span id="__span_0__-4-10"><a id="__codelineno-4-10" name="__codelineno-4-10" href="#__codelineno-4-10"></a><span class="c1"># Check for trailing commas, missing braces, etc.</span>
|
||||
</span></code></pre></div>
|
||||
<h3 id="books-re-downloading-after-already-being-downloaded">Books re-downloading after already being downloaded</h3>
|
||||
<p><strong>Cause:</strong> The ISBN in the library response doesn't match what's stored in history.</p>
|
||||
<p><strong>Check:</strong></p>
|
||||
<div class="language-bash highlight"><pre><span></span><code><span id="__span_0__-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="c1"># See what's recorded</span>
|
||||
</span><span id="__span_0__-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a>cat<span class="w"> </span>download_history.json<span class="w"> </span><span class="p">|</span><span class="w"> </span>python<span class="w"> </span>-m<span class="w"> </span>json.tool
|
||||
<div class="language-bash highlight"><pre><span></span><code><span id="__span_0__-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="c1"># See what's recorded (XDG location)</span>
|
||||
</span><span id="__span_0__-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a>cat<span class="w"> </span>~/.config/librofm-downloader/download_history.json<span class="w"> </span><span class="p">|</span><span class="w"> </span>python<span class="w"> </span>-m<span class="w"> </span>json.tool
|
||||
</span><span id="__span_0__-5-3"><a id="__codelineno-5-3" name="__codelineno-5-3" href="#__codelineno-5-3"></a>
|
||||
</span><span id="__span_0__-5-4"><a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="c1"># Look for the ISBN of the book that's re-downloading</span>
|
||||
</span><span id="__span_0__-5-4"><a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="c1"># Or if using CWD-based history</span>
|
||||
</span><span id="__span_0__-5-5"><a id="__codelineno-5-5" name="__codelineno-5-5" href="#__codelineno-5-5"></a>cat<span class="w"> </span>download_history.json<span class="w"> </span><span class="p">|</span><span class="w"> </span>python<span class="w"> </span>-m<span class="w"> </span>json.tool
|
||||
</span><span id="__span_0__-5-6"><a id="__codelineno-5-6" name="__codelineno-5-6" href="#__codelineno-5-6"></a>
|
||||
</span><span id="__span_0__-5-7"><a id="__codelineno-5-7" name="__codelineno-5-7" href="#__codelineno-5-7"></a><span class="c1"># Look for the ISBN of the book that's re-downloading</span>
|
||||
</span></code></pre></div>
|
||||
<p><strong>Possible reasons:</strong>
|
||||
- The book was re-published under a new ISBN
|
||||
|
||||
@@ -12,9 +12,9 @@ librofm-downloader [OPTIONS]
|
||||
|
||||
| Option | Short | Default | Description |
|
||||
|--------|-------|---------|-------------|
|
||||
| `--config` | | `config.yaml` | Path to `config.yaml` |
|
||||
| `--secrets` | | `secrets.yaml` | Path to `secrets.yaml` |
|
||||
| `--history` | | `download_history.json` | Path to download history JSON file |
|
||||
| `--config` | | XDG → CWD search | Path to `config.yaml` (overrides default search) |
|
||||
| `--secrets` | | XDG → CWD search | Path to `secrets.yaml` (overrides default search) |
|
||||
| `--history` | | XDG → CWD search | Path to download history JSON (overrides default search) |
|
||||
| `-v, --verbose` | | off | Print extra detail (URLs, paths, API responses) |
|
||||
| `--limit` N | | `0` (no limit) | Maximum number of books to download |
|
||||
| `-w, --workers` N | | `3` | Number of parallel download workers (1 = sequential) |
|
||||
@@ -25,9 +25,9 @@ Shows internal pipeline state at each stage:
|
||||
|
||||
```
|
||||
── config ──────────────────────────────────────
|
||||
config: config.yaml
|
||||
secrets: secrets.yaml
|
||||
history: download_history.json
|
||||
config: ~/.config/librofm-downloader/config.yaml
|
||||
secrets: ~/.config/librofm-downloader/secrets.yaml
|
||||
history: ~/.config/librofm-downloader/download_history.json
|
||||
format: m4b_mp3_fallback
|
||||
output: ./audiobooks
|
||||
extras: True
|
||||
|
||||
@@ -1,16 +1,47 @@
|
||||
# Configuration Reference
|
||||
|
||||
Complete reference for `config.yaml` and `secrets.yaml`.
|
||||
Complete reference for `config.yaml`, `secrets.yaml`, and download history.
|
||||
|
||||
## File locations
|
||||
## Default file locations
|
||||
|
||||
The CLI looks for these files in the **current working directory** by default:
|
||||
When no `--config`, `--secrets`, or `--history` flags are provided, the tool searches for each file in this order:
|
||||
|
||||
```bash
|
||||
librofm-downloader --config config.yaml --secrets secrets.yaml
|
||||
1. **XDG directory** — `~/.config/librofm-downloader/`
|
||||
2. **Current working directory** (CWD)
|
||||
|
||||
The XDG directory is **created automatically** on first run if it doesn't exist. This means you can drop your files into `~/.config/librofm-downloader/` and run `librofm-downloader` from any directory.
|
||||
|
||||
```
|
||||
~/.config/librofm-downloader/
|
||||
├── config.yaml # optional — built-in defaults used if missing
|
||||
├── secrets.yaml # required — tool exits with an error if missing
|
||||
└── download_history.json # created automatically on first download
|
||||
```
|
||||
|
||||
Both files share the same top-level key: `librofm`.
|
||||
### Missing files: config vs secrets
|
||||
|
||||
The two config files have different missing-file behavior:
|
||||
|
||||
| File | If missing | Behavior |
|
||||
|------|-----------|----------|
|
||||
| `config.yaml` | Non-fatal | Tool runs with built-in defaults (m4b_mp3_fallback, `./audiobooks`, etc.). A notice is printed listing searched paths. |
|
||||
| `secrets.yaml` | Fatal | Tool exits with code **1** and an error listing both searched locations so you know where to create it. |
|
||||
|
||||
### Overriding with CLI flags
|
||||
|
||||
Use `--config`, `--secrets`, and `--history` to bypass the XDG→CWD search entirely and point at specific files:
|
||||
|
||||
```bash
|
||||
# Use files in a custom location
|
||||
librofm-downloader --config /path/to/config.yaml --secrets /path/to/secrets.yaml
|
||||
|
||||
# Custom history file
|
||||
librofm-downloader --history /path/to/download_history.json
|
||||
```
|
||||
|
||||
When a flag is provided, that path is used directly — no search is performed.
|
||||
|
||||
Both config files share the same top-level key: `librofm`.
|
||||
|
||||
## secrets.yaml
|
||||
|
||||
@@ -33,7 +64,7 @@ librofm:
|
||||
|
||||
## config.yaml
|
||||
|
||||
All non-credential settings. Safe to commit.
|
||||
All non-credential settings. Safe to commit. **Optional** — if missing, built-in defaults are used.
|
||||
|
||||
| Field | Type | Default | Description |
|
||||
|-------|------|---------|-------------|
|
||||
@@ -86,11 +117,19 @@ Move them to secrets.yaml (which is gitignored).
|
||||
| `Config error: Credentials (...) found in config.yaml` | Username or password in config file | Move to `secrets.yaml` |
|
||||
| `Missing required fields in secrets.yaml: username` | Missing credential field | Add it to `secrets.yaml` |
|
||||
| `Invalid format 'foo'` | Unknown format value | Use one of: `m4b_mp3_fallback`, `mp3_only`, `m4b_only` |
|
||||
| `config.yaml not found in ~/.config/.../config.yaml → ./config.yaml. Using built-in defaults.` | No config file in either location | Non-fatal — defaults used. Create `config.yaml` to customize. |
|
||||
| `Missing secrets.yaml. Searched: ~/.config/.../secrets.yaml → ./secrets.yaml.` | No secrets file in either location | Create `secrets.yaml` with your credentials in one of the searched locations. |
|
||||
| `Invalid workers value: 0` | Workers < 1 | Set `workers` to an integer ≥ 1 |
|
||||
|
||||
## Download history
|
||||
|
||||
A third file, `download_history.json`, is created automatically on first run:
|
||||
A third file, `download_history.json`, tracks what's been downloaded. It follows the same XDG→CWD search order as the config files, and defaults to the XDG directory when not found anywhere:
|
||||
|
||||
```
|
||||
~/.config/librofm-downloader/download_history.json
|
||||
```
|
||||
|
||||
The file is created automatically on first download. Override with `--history` to use a custom location.
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -106,5 +145,4 @@ A third file, `download_history.json`, is created automatically on first run:
|
||||
|
||||
- Keyed by **ISBN** — each book is recorded once
|
||||
- Used to skip already-downloaded books on subsequent runs
|
||||
- Location defaults to `download_history.json` in CWD; override with `--history`
|
||||
- If the file is corrupt or missing, the tool starts with an empty history (and logs a warning)
|
||||
@@ -26,12 +26,16 @@ The `[dev]` extra installs pytest for testing — omit it if you only want to ru
|
||||
|
||||
## 2. Configure
|
||||
|
||||
librofm-downloader uses two YAML files:
|
||||
librofm-downloader uses two YAML files, searched in `~/.config/librofm-downloader/` first, then the current working directory:
|
||||
|
||||
| File | Purpose | Committed to git? |
|
||||
|------|---------|:-----------------:|
|
||||
| `config.yaml` | Preferences (format, output dir, toggles) | ✅ Yes |
|
||||
| `secrets.yaml` | Credentials only | ❌ No (gitignored) |
|
||||
| File | Purpose | Required? | Committed to git? |
|
||||
|------|---------|:---------:|:-----------------:|
|
||||
| `config.yaml` | Preferences (format, output dir, toggles) | No (defaults used) | ✅ Yes |
|
||||
| `secrets.yaml` | Credentials only | **Yes** | ❌ No (gitignored) |
|
||||
|
||||
> [!TIP]
|
||||
> The XDG directory (`~/.config/librofm-downloader/`) is created automatically on first run.
|
||||
> Place both files there to run `librofm-downloader` from any directory.
|
||||
|
||||
### config.yaml
|
||||
|
||||
@@ -79,12 +83,13 @@ librofm-downloader
|
||||
|
||||
This:
|
||||
|
||||
1. Loads `config.yaml` + `secrets.yaml`
|
||||
1. Searches for `config.yaml` + `secrets.yaml` (XDG directory first, then CWD)
|
||||
2. Authenticates with Libro.fm via OAuth2 password grant
|
||||
3. Fetches your full library (all pages)
|
||||
4. Skips books already in `download_history.json`
|
||||
5. Downloads each new book (3 parallel workers by default) with a progress bar
|
||||
6. Records successful downloads to history
|
||||
4. Skips books already in `download_history.json` (XDG → CWD search)
|
||||
5. Downloads each new book with a progress bar
|
||||
6. Downloads each new book (3 parallel workers by default) with a progress bar
|
||||
7. Records successful downloads to history
|
||||
|
||||
### First run output (TTY)
|
||||
|
||||
|
||||
@@ -56,15 +56,19 @@ librofm:
|
||||
|
||||
### "[Errno 2] No such file or directory: 'config.yaml'"
|
||||
|
||||
**Cause:** The config file doesn't exist at the specified path (default: current directory).
|
||||
**Cause:** The config file doesn't exist at the specified path.
|
||||
|
||||
**Fix:**
|
||||
|
||||
```bash
|
||||
# Run from the directory that contains config.yaml
|
||||
# Option 1: Place files in the XDG directory (recommended)
|
||||
mkdir -p ~/.config/librofm-downloader
|
||||
cp config.yaml secrets.yaml ~/.config/librofm-downloader/
|
||||
|
||||
# Option 2: Run from the directory that contains config.yaml
|
||||
cd /path/to/your/project
|
||||
|
||||
# Or specify the path explicitly
|
||||
# Option 3: Specify paths explicitly
|
||||
librofm-downloader --config /path/to/config.yaml --secrets /path/to/secrets.yaml
|
||||
```
|
||||
|
||||
@@ -133,10 +137,14 @@ $ librofm-downloader
|
||||
|
||||
```bash
|
||||
# Option 1: Delete and let it rebuild
|
||||
rm ~/.config/librofm-downloader/download_history.json
|
||||
librofm-downloader
|
||||
|
||||
# Option 2: If using CWD-based history
|
||||
rm download_history.json
|
||||
librofm-downloader
|
||||
|
||||
# Option 2: Fix the JSON manually (if you know what's in there)
|
||||
# Option 3: Fix the JSON manually (if you know what's in there)
|
||||
# Check for trailing commas, missing braces, etc.
|
||||
```
|
||||
|
||||
@@ -147,7 +155,10 @@ librofm-downloader
|
||||
**Check:**
|
||||
|
||||
```bash
|
||||
# See what's recorded
|
||||
# See what's recorded (XDG location)
|
||||
cat ~/.config/librofm-downloader/download_history.json | python -m json.tool
|
||||
|
||||
# Or if using CWD-based history
|
||||
cat download_history.json | python -m json.tool
|
||||
|
||||
# Look for the ISBN of the book that's re-downloading
|
||||
|
||||
+37
-12
@@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
from rich.console import Console
|
||||
|
||||
from librofm_downloader.config import load_config, ConfigError
|
||||
from librofm_downloader.config import load_config, ConfigError, _resolve_config_file
|
||||
from librofm_downloader.client import LibroFmClient, AuthError
|
||||
from librofm_downloader.history import DownloadHistory
|
||||
from librofm_downloader.downloader import Book, download_book
|
||||
@@ -16,9 +16,9 @@ console = Console()
|
||||
|
||||
|
||||
def run(
|
||||
config_path: str = "config.yaml",
|
||||
secrets_path: str = "secrets.yaml",
|
||||
history_path: str = "download_history.json",
|
||||
config_path: str | None = None,
|
||||
secrets_path: str | None = None,
|
||||
history_path: str | None = None,
|
||||
verbose: bool = False,
|
||||
limit: int = 0,
|
||||
workers: int = 0,
|
||||
@@ -38,20 +38,45 @@ def run(
|
||||
"""
|
||||
|
||||
try:
|
||||
if verbose:
|
||||
console.print("[dim]── config ──────────────────────────────────────[/dim]")
|
||||
console.print(f" config: {config_path}")
|
||||
console.print(f" secrets: {secrets_path}")
|
||||
console.print(f" history: {history_path}")
|
||||
# 0. Resolve history path (XDG → CWD, default to XDG location)
|
||||
if history_path is None:
|
||||
resolved = _resolve_config_file("download_history.json")
|
||||
if resolved is not None:
|
||||
history_path = str(resolved)
|
||||
else:
|
||||
from os import environ
|
||||
home = Path(environ.get("HOME", "~")).expanduser()
|
||||
xdg_dir = home / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True, exist_ok=True)
|
||||
history_path = str(xdg_dir / "download_history.json")
|
||||
|
||||
# 1. Load config
|
||||
try:
|
||||
config = load_config(config_path, secrets_path)
|
||||
if config._config_path is None:
|
||||
searched = [
|
||||
"~/.config/librofm-downloader/config.yaml",
|
||||
"./config.yaml",
|
||||
]
|
||||
console.print(
|
||||
f"[yellow]config.yaml not found in {' → '.join(searched)}. "
|
||||
f"Using built-in defaults.[/yellow]"
|
||||
)
|
||||
except ConfigError as exc:
|
||||
console.print(f"[red]Config error:[/red] {exc}")
|
||||
return 1
|
||||
|
||||
if verbose:
|
||||
console.print("[dim]── config ──────────────────────────────────────[/dim]")
|
||||
cfg_display = config._config_path if config._config_path else "(built-in defaults)"
|
||||
# Determine resolved secrets path
|
||||
secrets_display = secrets_path
|
||||
if secrets_path is None:
|
||||
resolved_secrets = _resolve_config_file("secrets.yaml")
|
||||
secrets_display = resolved_secrets or "(not found)"
|
||||
console.print(f" config: {cfg_display}")
|
||||
console.print(f" secrets: {secrets_display}")
|
||||
console.print(f" history: {history_path}")
|
||||
console.print(f" format: {config.format}")
|
||||
console.print(f" output: {config.output_dir}")
|
||||
console.print(f" extras: {config.download_extras}")
|
||||
@@ -171,9 +196,9 @@ if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description="Download audiobooks from Libro.fm")
|
||||
parser.add_argument("--config", default="config.yaml", help="Path to config.yaml")
|
||||
parser.add_argument("--secrets", default="secrets.yaml", help="Path to secrets.yaml")
|
||||
parser.add_argument("--history", default="download_history.json", help="Path to download history JSON")
|
||||
parser.add_argument("--config", default=None, help="Path to config.yaml (default: search XDG then CWD)")
|
||||
parser.add_argument("--secrets", default=None, help="Path to secrets.yaml (default: search XDG then CWD)")
|
||||
parser.add_argument("--history", default=None, help="Path to download history JSON (default: search XDG then CWD)")
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output (URLs, sizes, tracebacks)")
|
||||
parser.add_argument(
|
||||
"--limit",
|
||||
|
||||
@@ -16,6 +16,7 @@ class Config:
|
||||
output_dir: str
|
||||
download_extras: bool
|
||||
download_covers: bool
|
||||
_config_path: Path | None = None # None = defaulted (file missing)
|
||||
workers: int = 3
|
||||
|
||||
|
||||
@@ -39,19 +40,88 @@ class InvalidWorkersError(ConfigError):
|
||||
"""Invalid parallel download worker count."""
|
||||
|
||||
|
||||
def _resolve_config_file(filename: str) -> Path | None:
|
||||
"""Resolve a config file by searching XDG then CWD.
|
||||
|
||||
|
||||
def load_config(config_path: Path | str, secrets_path: Path | str) -> Config:
|
||||
"""Load config.yaml + secrets.yaml, merge, validate, and return Config."""
|
||||
config_path = Path(config_path)
|
||||
secrets_path = Path(secrets_path)
|
||||
|
||||
with config_path.open() as f:
|
||||
config_yaml = yaml.safe_load(f) or {}
|
||||
Searches ``~/.config/librofm-downloader/`` first, then falls back to
|
||||
the current working directory. Auto-creates the XDG parent directory
|
||||
on demand.
|
||||
|
||||
Returns:
|
||||
Resolved :class:`Path` if found, ``None`` if absent from both locations.
|
||||
"""
|
||||
from os import environ # noqa: S405 – we only read HOME
|
||||
|
||||
home = Path(environ.get("HOME", "~")).expanduser()
|
||||
xdg_path = home / ".config" / "librofm-downloader" / filename
|
||||
xdg_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if xdg_path.is_file():
|
||||
return xdg_path.resolve()
|
||||
|
||||
cwd_path = Path(filename).resolve()
|
||||
if cwd_path.is_file():
|
||||
return cwd_path
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def load_config(
|
||||
config_path: Path | str | None,
|
||||
secrets_path: Path | str | None,
|
||||
) -> Config:
|
||||
"""Load config.yaml + secrets.yaml, merge, validate, and return Config.
|
||||
|
||||
When either path is ``None``, searches XDG then CWD via
|
||||
:func:`_resolve_config_file`. Missing config.yaml is non-fatal
|
||||
(returns fully-defaulted :class:`Config`). Missing secrets.yaml is
|
||||
fatal (raises :class:`ConfigError`).
|
||||
"""
|
||||
# Resolve None paths → search XDG then CWD
|
||||
if config_path is None:
|
||||
config_path = _resolve_config_file("config.yaml")
|
||||
if secrets_path is None:
|
||||
secrets_path = _resolve_config_file("secrets.yaml")
|
||||
|
||||
# Load config.yaml (non-fatal if missing)
|
||||
config_yaml: dict = {}
|
||||
if config_path is not None:
|
||||
try:
|
||||
with Path(config_path).open() as f:
|
||||
config_yaml = yaml.safe_load(f) or {}
|
||||
except (FileNotFoundError, OSError) as exc:
|
||||
raise ConfigError(
|
||||
f"Cannot read config file '{config_path}': {exc}"
|
||||
) from exc
|
||||
|
||||
# Reject credentials in config.yaml
|
||||
_check_no_credentials_in_config(config_yaml)
|
||||
|
||||
with secrets_path.open() as f:
|
||||
secrets_yaml = yaml.safe_load(f) or {}
|
||||
# Load secrets.yaml (fatal if missing)
|
||||
if secrets_path is None:
|
||||
searched = [
|
||||
"~/.config/librofm-downloader/secrets.yaml",
|
||||
"./secrets.yaml",
|
||||
]
|
||||
raise ConfigError(
|
||||
f"Missing secrets.yaml. Searched: {' → '.join(searched)}. "
|
||||
f"Create one with your Libro.fm username and password."
|
||||
)
|
||||
|
||||
try:
|
||||
with Path(secrets_path).open() as f:
|
||||
secrets_yaml = yaml.safe_load(f) or {}
|
||||
except (FileNotFoundError, OSError) as exc:
|
||||
raise ConfigError(
|
||||
f"Cannot read secrets file '{secrets_path}': {exc}"
|
||||
) from exc
|
||||
|
||||
# Deep-merge secrets over config
|
||||
merged = _deep_merge(config_yaml, secrets_yaml)
|
||||
@@ -75,10 +145,10 @@ def load_config(config_path: Path | str, secrets_path: Path | str) -> Config:
|
||||
output_dir=librofm.get("output_dir", "./audiobooks"),
|
||||
download_extras=librofm.get("download_extras", True),
|
||||
download_covers=librofm.get("download_covers", True),
|
||||
_config_path=config_path,
|
||||
workers=librofm.get("workers", 3),
|
||||
)
|
||||
|
||||
|
||||
def _deep_merge(base: dict, override: dict) -> dict:
|
||||
"""Recursively merge override into base. Override wins on conflict."""
|
||||
result = base.copy()
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "librofm-downloader"
|
||||
version = "0.1.0"
|
||||
version = "1.1.0"
|
||||
description = "Download owned audiobooks from your Libro.fm account"
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
|
||||
@@ -647,6 +647,229 @@ class TestAllBooksFailExitCode:
|
||||
assert mock_download.call_count == 3
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Issue #23: XDG path resolution wired into CLI
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestCLIHistoryResolution:
|
||||
"""History path resolves via XDG → CWD when not explicitly provided."""
|
||||
|
||||
def test_history_defaults_to_xdg_location(self, tmp_path, monkeypatch):
|
||||
"""run() with history_path=None → history resolves to XDG path."""
|
||||
xdg_dir = tmp_path / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True)
|
||||
(xdg_dir / "download_history.json").write_text("{}")
|
||||
|
||||
cwd = tmp_path / "cwd"
|
||||
cwd.mkdir()
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(cwd)
|
||||
|
||||
with (
|
||||
patch("librofm_downloader.cli.load_config") as mock_config,
|
||||
patch("librofm_downloader.cli.LibroFmClient") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.DownloadHistory") as mock_history_cls,
|
||||
):
|
||||
mock_config.return_value.username = "alice"
|
||||
mock_config.return_value.password = "secret"
|
||||
mock_config.return_value._config_path = None
|
||||
mock_config.return_value.output_dir = "./audiobooks"
|
||||
|
||||
mock_instance = mock_client_cls.return_value
|
||||
mock_instance.authenticate.return_value = "tok"
|
||||
mock_instance.fetch_library.return_value = []
|
||||
|
||||
exit_code = run(
|
||||
config_path=None,
|
||||
secrets_path=None,
|
||||
history_path=None,
|
||||
)
|
||||
|
||||
assert exit_code == 0
|
||||
|
||||
# Verify DownloadHistory received the XDG path
|
||||
history_arg = mock_history_cls.call_args[0][0]
|
||||
assert "librofm-downloader" in str(history_arg)
|
||||
assert "download_history.json" in str(history_arg)
|
||||
|
||||
def test_history_defaults_to_xdg_when_not_found_anywhere(self, tmp_path, monkeypatch):
|
||||
"""No download_history.json anywhere → defaults to XDG location."""
|
||||
cwd = tmp_path / "cwd"
|
||||
cwd.mkdir()
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(cwd)
|
||||
|
||||
with (
|
||||
patch("librofm_downloader.cli.load_config") as mock_config,
|
||||
patch("librofm_downloader.cli.LibroFmClient") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.DownloadHistory") as mock_history_cls,
|
||||
):
|
||||
mock_config.return_value.username = "alice"
|
||||
mock_config.return_value.password = "secret"
|
||||
mock_config.return_value._config_path = None
|
||||
mock_config.return_value.output_dir = "./audiobooks"
|
||||
|
||||
mock_instance = mock_client_cls.return_value
|
||||
mock_instance.authenticate.return_value = "tok"
|
||||
mock_instance.fetch_library.return_value = []
|
||||
|
||||
exit_code = run(history_path=None)
|
||||
|
||||
assert exit_code == 0
|
||||
|
||||
# Should default to XDG location even though file doesn't exist
|
||||
history_arg = mock_history_cls.call_args[0][0]
|
||||
assert "librofm-downloader" in str(history_arg)
|
||||
assert ".config" in str(history_arg)
|
||||
assert "download_history.json" in str(history_arg)
|
||||
|
||||
def test_explicit_history_path_bypasses_resolution(self, tmp_path, monkeypatch):
|
||||
"""Explicit --history flag uses the exact path provided."""
|
||||
with (
|
||||
patch("librofm_downloader.cli.load_config") as mock_config,
|
||||
patch("librofm_downloader.cli.LibroFmClient") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.DownloadHistory") as mock_history_cls,
|
||||
):
|
||||
mock_config.return_value.username = "alice"
|
||||
mock_config.return_value.password = "secret"
|
||||
mock_config.return_value._config_path = None
|
||||
mock_config.return_value.output_dir = "./audiobooks"
|
||||
|
||||
mock_instance = mock_client_cls.return_value
|
||||
mock_instance.authenticate.return_value = "tok"
|
||||
mock_instance.fetch_library.return_value = []
|
||||
|
||||
exit_code = run(history_path="/custom/my_history.json")
|
||||
|
||||
assert exit_code == 0
|
||||
|
||||
history_arg = mock_history_cls.call_args[0][0]
|
||||
assert str(history_arg) == "/custom/my_history.json"
|
||||
|
||||
|
||||
|
||||
class TestCLIConfigResolutionMessages:
|
||||
"""CLI messages about config resolution."""
|
||||
|
||||
def test_missing_config_message_includes_searched_paths(self, tmp_path, monkeypatch, capsys):
|
||||
"""config.yaml not found → message lists XDG and CWD paths."""
|
||||
xdg_dir = tmp_path / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True)
|
||||
(xdg_dir / "secrets.yaml").write_text(
|
||||
"librofm:\n username: alice\n password: secret\n"
|
||||
)
|
||||
|
||||
cwd = tmp_path / "cwd"
|
||||
cwd.mkdir()
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(cwd)
|
||||
|
||||
with (
|
||||
patch("librofm_downloader.cli.LibroFmClient") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.download_book"),
|
||||
):
|
||||
mock_instance = mock_client_cls.return_value
|
||||
mock_instance.authenticate.return_value = "tok"
|
||||
mock_instance.fetch_library.return_value = []
|
||||
|
||||
exit_code = run(config_path=None, secrets_path=None, history_path=None)
|
||||
|
||||
assert exit_code == 0
|
||||
output = capsys.readouterr().out
|
||||
assert "config.yaml not found" in output
|
||||
assert ".config" in output or "librofm-downloader" in output
|
||||
assert "Using built-in defaults" in output
|
||||
|
||||
def test_verbose_shows_resolved_paths(self, tmp_path, monkeypatch, capsys):
|
||||
"""--verbose shows the actual resolved file paths after loading config."""
|
||||
xdg_dir = tmp_path / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True)
|
||||
(xdg_dir / "secrets.yaml").write_text(
|
||||
"librofm:\n username: alice\n password: secret\n"
|
||||
)
|
||||
(xdg_dir / "download_history.json").write_text("{}")
|
||||
|
||||
cwd = tmp_path / "cwd"
|
||||
cwd.mkdir()
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(cwd)
|
||||
|
||||
with (
|
||||
patch("librofm_downloader.cli.LibroFmClient") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.download_book"),
|
||||
):
|
||||
mock_instance = mock_client_cls.return_value
|
||||
mock_instance.authenticate.return_value = "tok"
|
||||
mock_instance.fetch_library.return_value = []
|
||||
|
||||
exit_code = run(
|
||||
config_path=None,
|
||||
secrets_path=None,
|
||||
history_path=None,
|
||||
verbose=True,
|
||||
)
|
||||
|
||||
assert exit_code == 0
|
||||
output = capsys.readouterr().out.lower()
|
||||
# Verbose should show the resolved XDG paths
|
||||
assert "secrets" in output
|
||||
assert "history" in output
|
||||
assert "librofm-downloader" in output
|
||||
|
||||
|
||||
|
||||
class TestCLIMissingFilesErrors:
|
||||
"""Error handling when files are missing."""
|
||||
|
||||
def test_empty_home_clean_secrets_error(self, tmp_path, monkeypatch, capsys):
|
||||
"""No files anywhere → clean error about missing secrets, exit 1."""
|
||||
cwd = tmp_path / "cwd"
|
||||
cwd.mkdir()
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(cwd)
|
||||
|
||||
exit_code = run(config_path=None, secrets_path=None, history_path=None)
|
||||
|
||||
assert exit_code == 1
|
||||
output = capsys.readouterr().out
|
||||
assert "secrets.yaml" in output
|
||||
assert "Traceback" not in output
|
||||
|
||||
def test_only_secrets_in_xdg_works(self, tmp_path, monkeypatch, capsys):
|
||||
"""Secrets in XDG only → defaults work, 'using built-in defaults' message visible."""
|
||||
xdg_dir = tmp_path / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True)
|
||||
(xdg_dir / "secrets.yaml").write_text(
|
||||
"librofm:\n username: alice\n password: secret\n"
|
||||
)
|
||||
|
||||
cwd = tmp_path / "cwd"
|
||||
cwd.mkdir()
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(cwd)
|
||||
|
||||
with (
|
||||
patch("librofm_downloader.cli.LibroFmClient") as mock_client_cls,
|
||||
patch("librofm_downloader.cli.download_book"),
|
||||
):
|
||||
mock_instance = mock_client_cls.return_value
|
||||
mock_instance.authenticate.return_value = "tok"
|
||||
mock_instance.fetch_library.return_value = []
|
||||
|
||||
exit_code = run(config_path=None, secrets_path=None, history_path=None)
|
||||
|
||||
assert exit_code == 0
|
||||
output = capsys.readouterr().out
|
||||
assert "Using built-in defaults" in output
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Issue #12: workers config field + --workers CLI flag
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
+157
-1
@@ -6,6 +6,12 @@ import pytest
|
||||
|
||||
from librofm_downloader.config import (
|
||||
load_config,
|
||||
_resolve_config_file,
|
||||
Config,
|
||||
ConfigError,
|
||||
CredentialsInConfigError,
|
||||
load_config,
|
||||
_resolve_config_file,
|
||||
Config,
|
||||
CredentialsInConfigError,
|
||||
MissingFieldError,
|
||||
@@ -275,4 +281,154 @@ class TestEdgeCases:
|
||||
)
|
||||
# config_minimal has no format, so it gets default
|
||||
# We just verify it doesn't raise for valid formats
|
||||
assert config.format in ("m4b_mp3_fallback", "mp3_only", "m4b_only")
|
||||
assert config.format in ("m4b_mp3_fallback", "mp3_only", "m4b_only")
|
||||
|
||||
|
||||
class TestResolveConfigFile:
|
||||
"""XDG-then-CWD path resolution for config files."""
|
||||
|
||||
def test_returns_path_when_file_in_xdg(self, tmp_path, monkeypatch):
|
||||
"""File found in XDG dir → returns resolved Path."""
|
||||
xdg_dir = tmp_path / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True)
|
||||
(xdg_dir / "config.yaml").write_text("librofm:\n format: m4b_only\n")
|
||||
|
||||
(tmp_path / "cwd").mkdir(exist_ok=True)
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(tmp_path / "cwd") # CWD has no file
|
||||
|
||||
result = _resolve_config_file("config.yaml")
|
||||
|
||||
assert result is not None
|
||||
assert result.name == "config.yaml"
|
||||
assert "librofm-downloader" in str(result)
|
||||
|
||||
def test_returns_path_when_file_only_in_cwd(self, tmp_path, monkeypatch):
|
||||
"""File only in CWD (not XDG) → returns CWD Path."""
|
||||
(tmp_path / "config.yaml").write_text("librofm:\n format: mp3_only\n")
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(tmp_path) # CWD has the file, XDG is empty
|
||||
|
||||
result = _resolve_config_file("config.yaml")
|
||||
|
||||
assert result is not None
|
||||
assert result.name == "config.yaml"
|
||||
# Should be resolved from CWD, not XDG
|
||||
assert ".config" not in str(result)
|
||||
|
||||
def test_xdg_wins_when_both_present(self, tmp_path, monkeypatch):
|
||||
"""File in both XDG and CWD → XDG path takes priority."""
|
||||
xdg_dir = tmp_path / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True)
|
||||
(xdg_dir / "config.yaml").write_text("xdg_version\n")
|
||||
|
||||
(tmp_path / "config.yaml").write_text("cwd_version\n")
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
result = _resolve_config_file("config.yaml")
|
||||
|
||||
assert result is not None
|
||||
assert "librofm-downloader" in str(result) # XDG path
|
||||
assert result.read_text() == "xdg_version\n"
|
||||
|
||||
def test_returns_none_when_file_absent_from_both(self, tmp_path, monkeypatch):
|
||||
"""File missing from XDG and CWD → returns None."""
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
result = _resolve_config_file("config.yaml")
|
||||
|
||||
assert result is None
|
||||
|
||||
def test_xdg_directory_auto_created(self, tmp_path, monkeypatch):
|
||||
"""XDG parent dir is created even when file is absent."""
|
||||
xdg_parent = tmp_path / ".config" / "librofm-downloader"
|
||||
assert not xdg_parent.exists()
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
_resolve_config_file("config.yaml")
|
||||
|
||||
assert xdg_parent.is_dir()
|
||||
|
||||
|
||||
class TestLoadConfigWithResolution:
|
||||
"""load_config wired to _resolve_config_file for None paths."""
|
||||
|
||||
def test_secrets_only_returns_defaulted_config(self, tmp_path, monkeypatch):
|
||||
"""config.yaml missing, secrets.yaml present → defaulted Config + creds."""
|
||||
xdg_dir = tmp_path / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True)
|
||||
(xdg_dir / "secrets.yaml").write_text(
|
||||
"librofm:\n username: alice\n password: s3cret\n"
|
||||
)
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
config = load_config(None, None)
|
||||
|
||||
# Credentials from secrets
|
||||
assert config.username == "alice"
|
||||
assert config.password == "s3cret"
|
||||
# Built-in defaults (config.yaml was missing)
|
||||
assert config.format == "m4b_mp3_fallback"
|
||||
assert config.output_dir == "./audiobooks"
|
||||
assert config.download_extras is True
|
||||
assert config.download_covers is True
|
||||
|
||||
def test_neither_file_raises_error_with_searched_paths(self, tmp_path, monkeypatch):
|
||||
"""Both files missing → ConfigError listing every path searched."""
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
with pytest.raises(ConfigError) as exc_info:
|
||||
load_config(None, None)
|
||||
|
||||
msg = str(exc_info.value)
|
||||
assert "secrets.yaml" in msg
|
||||
assert "librofm-downloader" in msg or ".config" in msg
|
||||
|
||||
def test_explicit_config_path_bypasses_search(self, tmp_path, monkeypatch):
|
||||
"""Explicit config path → used as-is; secrets still searches if None."""
|
||||
# Explicit config file
|
||||
explicit_config = tmp_path / "my_config.yaml"
|
||||
explicit_config.write_text(
|
||||
"librofm:\n format: mp3_only\n output_dir: ./custom\n"
|
||||
)
|
||||
|
||||
# Secrets only in XDG
|
||||
xdg_dir = tmp_path / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True)
|
||||
(xdg_dir / "secrets.yaml").write_text(
|
||||
"librofm:\n username: bob\n password: p4ss\n"
|
||||
)
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
config = load_config(explicit_config, None)
|
||||
|
||||
assert config.format == "mp3_only" # from explicit config
|
||||
assert config.output_dir == "./custom" # from explicit config
|
||||
assert config.username == "bob" # from resolved secrets
|
||||
|
||||
def test_missing_config_provides_detectable_signal(self, tmp_path, monkeypatch):
|
||||
"""Missing config.yaml → caller can detect defaults were used."""
|
||||
xdg_dir = tmp_path / ".config" / "librofm-downloader"
|
||||
xdg_dir.mkdir(parents=True)
|
||||
(xdg_dir / "secrets.yaml").write_text(
|
||||
"librofm:\n username: carol\n password: pw\n"
|
||||
)
|
||||
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
config = load_config(None, None)
|
||||
|
||||
# Signal: _config_path is None when config.yaml was missing
|
||||
assert config._config_path is None
|
||||
Reference in new issue
Block a user