Merge branch 'develop' into feature/parallel-downloads

This commit is contained in:
AlexKucera committed 2026-06-04 11:04:19 +02:00
commit 44fc544a3e
22 files changed
+1051 -113

No files matched your search

@@ -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*
+9 -9
View File
@@ -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
View File
@@ -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 &lt; 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">&quot;9780743565400&quot;</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">&quot;isbn&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;9780743565400&quot;</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">&quot;title&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;The Way of Kings&quot;</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">&quot;format&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;m4b&quot;</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">&quot;path&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;./audiobooks/Brandon Sanderson/The Way of Kings/The Way of Kings.m4b&quot;</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">&quot;downloaded_at&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;2026-06-03T10:30:00+00:00&quot;</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">&quot;9780743565400&quot;</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">&quot;isbn&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;9780743565400&quot;</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">&quot;title&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;The Way of Kings&quot;</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">&quot;format&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;m4b&quot;</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">&quot;path&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;./audiobooks/Brandon Sanderson/The Way of Kings/The Way of Kings.m4b&quot;</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">&quot;downloaded_at&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;2026-06-03T10:30:00+00:00&quot;</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>
+12 -3
View File
@@ -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
View File
@@ -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 &amp; 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 &gt; config.yaml &lt;&lt; 'EOF'\nlibrofm:\n format: m4b_mp3_fallback\n output_dir: ./audiobooks\n download_extras: true\n download_covers: true\nEOF\n\ncat &gt; secrets.yaml &lt;&lt; '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 &amp; 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 &gt; config.yaml &lt;&lt; 'EOF'\nlibrofm:\n format: m4b_mp3_fallback\n output_dir: ./audiobooks\n download_extras: true\n download_covers: true\nEOF\n\ncat &gt; secrets.yaml &lt;&lt; '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.
+23 -12
View File
@@ -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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;s re-downloading</span>
</span></code></pre></div>
<p><strong>Possible reasons:</strong>
- The book was re-published under a new ISBN
+6 -6
View File
@@ -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
+47 -9
View File
@@ -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)
+14 -9
View File
@@ -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)
+16 -5
View File
@@ -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