docs: add MkDocs site and polished README (closes #10)
Add 8-page documentation site with Material theme covering quickstart, configuration, secrets, path patterns, format strategies, CLI usage, and troubleshooting. All code snippets verified against implementation. Rewrite README with badges, features, quickstart, and format comparison. Build HTML to docs/html/ with flat URLs.
This commit is contained in:
1 parent
69e9636996
commit
61543204a8
71 files changed
+19385
No files matched your search
@@ -0,0 +1,188 @@
|
||||
# CLI Usage
|
||||
|
||||
Command-line interface reference for `librofm-downloader`.
|
||||
|
||||
## Synopsis
|
||||
|
||||
```bash
|
||||
librofm-downloader [OPTIONS]
|
||||
```
|
||||
|
||||
## 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 |
|
||||
| `-v, --verbose` | | off | Print extra detail (URLs, paths, API responses) |
|
||||
| `--limit` N | | `0` (no limit) | Maximum number of books to download |
|
||||
|
||||
### --verbose
|
||||
|
||||
Shows internal pipeline state at each stage:
|
||||
|
||||
```
|
||||
── config ──────────────────────────────────────
|
||||
config: config.yaml
|
||||
secrets: secrets.yaml
|
||||
history: download_history.json
|
||||
format: m4b_mp3_fallback
|
||||
output: ./audiobooks
|
||||
extras: True
|
||||
covers: True
|
||||
user: me@example.com
|
||||
── auth ────────────────────────────────────────
|
||||
✓ authenticated
|
||||
── library ─────────────────────────────────────
|
||||
47 book(s) in library
|
||||
── filtering ───────────────────────────────────
|
||||
42 already downloaded, 5 new
|
||||
⬇ Book Title [dim](9780743565400)[/dim]
|
||||
authors: Brandon Sanderson
|
||||
narrators: Kate Reading, Michael Kramer
|
||||
...
|
||||
123,456,789 bytes
|
||||
```
|
||||
|
||||
### --limit
|
||||
|
||||
Cap how many books are downloaded in a single run. Useful for testing:
|
||||
|
||||
```bash
|
||||
# Download only 1 book (the first new one)
|
||||
librofm-downloader --limit 1
|
||||
|
||||
# Download up to 3 books
|
||||
librofm-downloader --limit 3 -v
|
||||
```
|
||||
|
||||
Books are processed in the order returned by the Libro.fm API. Already-downloaded books are filtered out **before** the limit is applied.
|
||||
|
||||
## Exit codes
|
||||
|
||||
| Code | Meaning |
|
||||
|------|---------|
|
||||
| `0` | Success — all done (including "nothing new to download") |
|
||||
| `1` | Fatal error — config problem, auth failure, or library fetch failure |
|
||||
| `130` | Interrupted — user pressed Ctrl+C during downloads |
|
||||
|
||||
### Exit code 0 scenarios
|
||||
|
||||
- All new books downloaded successfully
|
||||
- No new books to download (`All caught up!`)
|
||||
- Some books failed but the pipeline completed (failures are reported in the summary)
|
||||
|
||||
> [!NOTE]
|
||||
> Exit code 0 does **not** mean "zero failures" — it means the process ran to completion.
|
||||
> Check the summary line for `failed` count.
|
||||
|
||||
### Exit code 1 scenarios
|
||||
|
||||
```bash
|
||||
# Config error
|
||||
$ librofm-downloader --config missing.yaml
|
||||
Config error: [Errno 2] No such file or directory: 'missing.yaml'
|
||||
|
||||
# Auth failure
|
||||
$ librofm-downloader
|
||||
Authentication failed: Auth failed (401)
|
||||
|
||||
# Library fetch failure
|
||||
$ librofm-downloader
|
||||
Failed to fetch library: 502 Bad Gateway
|
||||
```
|
||||
|
||||
### Exit code 130
|
||||
|
||||
```bash
|
||||
$ librofm-downloader
|
||||
^CDownload interrupted by user (Ctrl+C).
|
||||
echo $?
|
||||
130
|
||||
```
|
||||
|
||||
Partial downloads are preserved as `.partial` files and will be **resumed** on the next run.
|
||||
|
||||
## Cron setup
|
||||
|
||||
### Basic daily sync
|
||||
|
||||
```cron
|
||||
# m h dom mon dow command
|
||||
0 4 * * * cd /path/to/librofm-downloader && .venv/bin/librofm-downloader >> /var/log/librofm.log 2>&1
|
||||
```
|
||||
|
||||
Runs every day at 4:00 AM, appends output to a log file.
|
||||
|
||||
### With email on failure
|
||||
|
||||
```cron
|
||||
0 4 * * * cd /path/to/librofm-downloader && .venv/bin/librofm-downloader || echo "librofm-downloader failed" | mail -s "DL failure" you@example.com
|
||||
```
|
||||
|
||||
### Weekly with limit
|
||||
|
||||
```cron
|
||||
0 3 * * 1 cd /path/to/librofm-downloader && .venv/bin/librofm-downloader --limit 10 >> /var/log/librofm-weekly.log 2>&1
|
||||
```
|
||||
|
||||
Runs Mondays at 3:00 AM, caps at 10 books.
|
||||
|
||||
### systemd timer (alternative to cron)
|
||||
|
||||
```ini
|
||||
# /etc/systemd/system/librofm-downloader.service
|
||||
[Unit]
|
||||
Description=Libro.fm Audiobook Downloader
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
WorkingDirectory=/path/to/librofm-downloader
|
||||
ExecStart=/path/to/librofm-downloader/.venv/bin/librofm-downloader
|
||||
|
||||
# /etc/systemd/system/librofm-downloader.timer
|
||||
[Unit]
|
||||
Description=Run librofm-downloader daily
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
```bash
|
||||
systemctl enable --now librofm-downloader.timer
|
||||
journalctl -u librofm-downloader -f
|
||||
```
|
||||
|
||||
## TTY vs non-TTY output
|
||||
|
||||
The tool auto-detects whether stdout is a terminal:
|
||||
|
||||
### TTY (interactive terminal)
|
||||
|
||||
- **Rich progress bars** with percentage, transfer speed, ETA, and size
|
||||
- Color-coded results (✓ green, ✗ red, ⏭ yellow)
|
||||
- Progress bars update in-place (no scrolling flood)
|
||||
|
||||
```
|
||||
Brandon Sanderson - The Way of Kings ████████████████████ 67.3% 2.1 MB/s 00:03 45.2 MB
|
||||
```
|
||||
|
||||
### Non-TTY (cron, pipe, redirect)
|
||||
|
||||
- **Plain text log lines** — one per event
|
||||
- No color, no progress bar updates
|
||||
- Same information, machine-friendly format
|
||||
|
||||
```
|
||||
Downloading: Brandon Sanderson - The Way of Kings (unknown size)
|
||||
Completed: Brandon Sanderson - The Way of Kings
|
||||
Summary: 1 downloaded, 0 skipped, 0 failed
|
||||
```
|
||||
|
||||
This means you get nice progress in your terminal and clean logs in cron — **no flags needed**.
|
||||
@@ -0,0 +1,106 @@
|
||||
# Configuration Reference
|
||||
|
||||
Complete reference for `config.yaml` and `secrets.yaml`.
|
||||
|
||||
## File locations
|
||||
|
||||
The CLI looks for these files in the **current working directory** by default:
|
||||
|
||||
```bash
|
||||
librofm-downloader --config config.yaml --secrets secrets.yaml
|
||||
```
|
||||
|
||||
Both files share the same top-level key: `librofm`.
|
||||
|
||||
## secrets.yaml
|
||||
|
||||
Credentials only. This file must **not** be committed to version control.
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|:--------:|-------------|
|
||||
| `username` | `string` | ✅ | Your Libro.fm account email |
|
||||
| `password` | `string` | ✅ | Your Libro.fm password |
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
username: your-email@example.com
|
||||
password: your-password
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Only `username` and `password` belong in this file. All other settings go in `config.yaml`.
|
||||
> If either field is missing, the tool exits with code **1** and an error message.
|
||||
|
||||
## config.yaml
|
||||
|
||||
All non-credential settings. Safe to commit.
|
||||
|
||||
| Field | Type | Default | Description |
|
||||
|-------|------|---------|-------------|
|
||||
| `format` | `string` | `"m4b_mp3_fallback"` | Audio download strategy. See [Format Strategies](format-strategies.md). |
|
||||
| `output_dir` | `string` | `"./audiobooks"` | Base directory for downloaded files. Relative paths resolve from CWD. |
|
||||
| `download_extras` | `boolean` | `true` | Download PDF extras (e.g., maps) when available. |
|
||||
| `download_covers` | `boolean` | `true` | Download cover art (JPEG/PNG) when available. |
|
||||
|
||||
### Full example
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
format: m4b_mp3_fallback
|
||||
output_dir: ./audiobooks
|
||||
download_extras: true
|
||||
download_covers: true
|
||||
```
|
||||
|
||||
### Minimal example
|
||||
|
||||
Only `format` is meaningful here — everything else has a default:
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
format: mp3_only
|
||||
```
|
||||
|
||||
## How merging works
|
||||
|
||||
`config.yaml` and `secrets.yaml` are **deep-merged** at startup:
|
||||
|
||||
1. `config.yaml` is loaded as the base
|
||||
2. `secrets.yaml` is layered on top (overrides on conflict)
|
||||
3. The merged result is validated
|
||||
|
||||
This means you could theoretically put any field in either file — but **credentials in `config.yaml` are explicitly rejected** at load time with a clear error:
|
||||
|
||||
```
|
||||
Config error: Credentials (username, password) found in config.yaml.
|
||||
Move them to secrets.yaml (which is gitignored).
|
||||
```
|
||||
|
||||
## Validation errors
|
||||
|
||||
| Error | Cause | Fix |
|
||||
|-------|-------|-----|
|
||||
| `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` |
|
||||
|
||||
## Download history
|
||||
|
||||
A third file, `download_history.json`, is created automatically on first run:
|
||||
|
||||
```json
|
||||
{
|
||||
"9780743565400": {
|
||||
"isbn": "9780743565400",
|
||||
"title": "The Way of Kings",
|
||||
"format": "m4b",
|
||||
"path": "./audiobooks/Brandon Sanderson/The Way of Kings/The Way of Kings.m4b",
|
||||
"downloaded_at": "2026-06-03T10:30:00+00:00"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- 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)
|
||||
@@ -0,0 +1,138 @@
|
||||
# Format Strategies
|
||||
|
||||
librofm-downloader supports three audio format strategies, controlled by the `format` field in `config.yaml`.
|
||||
|
||||
## Overview
|
||||
|
||||
| Strategy | Behavior | Best for |
|
||||
|----------|----------|----------|
|
||||
| `m4b_mp3_fallback` | Try M4B first; fall back to MP3 if unavailable | **Default** — maximum compatibility |
|
||||
| `mp3_only` | Download MP3 ZIP only (skip M4B entirely) | Players that don't support M4B |
|
||||
| `m4b_only` | Download M4B only; skip book if unavailable | Audiobook apps that prefer M4B |
|
||||
|
||||
## m4b_mp3_fallback (default)
|
||||
|
||||
The recommended strategy for most users.
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
format: m4b_mp3_fallback
|
||||
```
|
||||
|
||||
**Flow:**
|
||||
|
||||
1. Request the M4B download URL from Libro.fm API
|
||||
2. If available → download as a single `.m4b` file
|
||||
3. If the API returns **404** → fall back to fetching the MP3 manifest
|
||||
4. Download all MP3 ZIP parts and extract them
|
||||
|
||||
**What you get:**
|
||||
|
||||
- Most books: one `.m4b` file (AAC/ALAC audio, bookmarkable, chapter markers)
|
||||
- Older or region-locked books: extracted MP3 files (one or more per book)
|
||||
- **No books are skipped** — every downloadable title is fetched in some format
|
||||
|
||||
**Output examples:**
|
||||
|
||||
```
|
||||
# M4B succeeded
|
||||
audiobooks/Brandon Sanderson/The Way of Kings.m4b # single file, ~450 MB
|
||||
|
||||
# Fell back to MP3
|
||||
audiobooks/Some Author/Old Book/ # directory with MP3s
|
||||
├── part1.mp3
|
||||
├── part2.mp3
|
||||
└── part3.mp3
|
||||
```
|
||||
|
||||
## mp3_only
|
||||
|
||||
Skip M4B entirely and always use the MP3 ZIP pipeline.
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
format: mp3_only
|
||||
```
|
||||
|
||||
**Flow:**
|
||||
|
||||
1. Fetch the MP3 download manifest from Libro.fm API
|
||||
2. Download each ZIP part listed in the manifest
|
||||
3. Extract all files into the output directory
|
||||
|
||||
**When to use this:**
|
||||
|
||||
- Your media player doesn't support M4B/M4A containers
|
||||
- You want raw MP3 files for editing or conversion
|
||||
- You're feeding files into a system that only accepts MP3
|
||||
|
||||
**Output:** Always a directory with extracted MP3 files:
|
||||
|
||||
```
|
||||
audiobooks/Brandon Sanderson/The Way of Kings/
|
||||
├── part1.mp3
|
||||
├── part2.mp3
|
||||
└── ...
|
||||
```
|
||||
|
||||
## m4b_only
|
||||
|
||||
Only attempt M4B download. Skip books where M4B is not available.
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
format: m4b_only
|
||||
```
|
||||
|
||||
**Flow:**
|
||||
|
||||
1. Request the M4B download URL from Libro.fm API
|
||||
2. If available → download as a single `.m4b` file
|
||||
3. If the API returns **404** → log a skip message, move to next book
|
||||
|
||||
**When to use this:**
|
||||
|
||||
- You only want single-file audiobooks (cleaner library management)
|
||||
- Your audiobook app (Apple Books, etc.) handles M4B natively
|
||||
- You'd rather miss a book than get split MP3 files
|
||||
|
||||
**Output example:**
|
||||
|
||||
```
|
||||
# Success
|
||||
audiobooks/Brandon Sanderson/The Way of Kings.m4b
|
||||
|
||||
# Skipped (shows in summary)
|
||||
Summary: 5 downloaded, 2 skipped, 0 failed
|
||||
Skipped:
|
||||
⏭ Some Author - Old Book [9781234567890]
|
||||
```
|
||||
|
||||
## How to choose
|
||||
|
||||
```
|
||||
┌─────────────────────────┬──────────────────────────────┐│
|
||||
│ Want every book? │ → m4b_mp3_fallback (default) │
|
||||
│ Only need MP3? │ → mp3_only │
|
||||
│ Single-file or nothing? │ → m4b_only │
|
||||
└─────────────────────────┴──────────────────────────────┘
|
||||
```
|
||||
|
||||
## Technical details
|
||||
|
||||
### M4B downloads
|
||||
|
||||
- Single HTTP stream with **8 MB chunk** buffering
|
||||
- Written to `{title}.m4b.partial` during transfer
|
||||
- **Atomic rename** to final `.m4b` on completion
|
||||
- Supports **resume**: if a `.partial` file exists, sends `Range` header to continue
|
||||
- Progress reporting via `Content-Length` header (% complete, speed, ETA)
|
||||
|
||||
### MP3 downloads
|
||||
|
||||
- Fetches a **manifest** (`/api/v10/download-manifest?isbn=...`) listing ZIP part URLs
|
||||
- Each part is downloaded as a `.zip.partial` file, then renamed to `.zip`
|
||||
- ZIP contents are **extracted** into the output directory
|
||||
- The ZIP file is deleted after extraction
|
||||
- Each part supports resume via `Range` headers
|
||||
- Parts are downloaded sequentially within each book
|
||||
@@ -0,0 +1,46 @@
|
||||
# librofm-downloader
|
||||
|
||||
[](https://www.python.org/downloads/)
|
||||
[](https://github.com/AlexKucera/librofm-downloader/blob/main/LICENSE.md)
|
||||
|
||||
**Download owned audiobooks from your Libro.fm account** — a lightweight, dependency-minimal CLI tool written in Python.
|
||||
|
||||
No Docker. No JVM. Just `pip install` and go.
|
||||
|
||||
## Features
|
||||
|
||||
- **Full library sync** — fetches every audiobook in your Libro.fm account with automatic pagination
|
||||
- **M4B + MP3 formats** — downloads M4B (single file) or MP3 (ZIP parts extracted) with automatic fallback
|
||||
- **Resume support** — interrupted downloads pick up where they left off via `.partial` files
|
||||
- **Cover art & PDF extras** — optional download of cover images and accompanying PDFs
|
||||
- **Customizable output paths** — token-based patterns for organizing your library on disk
|
||||
- **TTY-aware progress** — rich progress bars in your terminal, clean log lines in cron jobs
|
||||
- **Download history** — tracks what's been downloaded so re-runs only fetch new books
|
||||
- **Graceful failure isolation** — one failed book doesn't stop the rest
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
# 1. Install
|
||||
pip install librofm-downloader
|
||||
|
||||
# 2. Configure
|
||||
cat > config.yaml << 'EOF'
|
||||
librofm:
|
||||
format: m4b_mp3_fallback
|
||||
output_dir: ./audiobooks
|
||||
download_extras: true
|
||||
download_covers: true
|
||||
EOF
|
||||
|
||||
cat > secrets.yaml << 'EOF'
|
||||
librofm:
|
||||
username: your-email@example.com
|
||||
password: your-password
|
||||
EOF
|
||||
|
||||
# 3. Run
|
||||
librofm-downloader
|
||||
```
|
||||
|
||||
See [Quickstart](quickstart.md) for the full walkthrough, or jump to [Configuration Reference](configuration.md) for every option.
|
||||
@@ -0,0 +1,58 @@
|
||||
site_name: librofm-downloader
|
||||
docs_dir: .
|
||||
site_dir: ../../docs/html
|
||||
use_directory_urls: false
|
||||
site_description: Download owned audiobooks from your Libro.fm account
|
||||
site_author: Alex Kucera
|
||||
repo_url: https://github.com/AlexKucera/librofm-downloader
|
||||
repo_name: AlexKucera/librofm-downloader
|
||||
|
||||
theme:
|
||||
name: material
|
||||
palette:
|
||||
- scheme: default
|
||||
primary: deep purple
|
||||
accent: amber
|
||||
toggle:
|
||||
icon: material/brightness-7
|
||||
name: Switch to dark mode
|
||||
- scheme: slate
|
||||
primary: deep purple
|
||||
accent: amber
|
||||
toggle:
|
||||
icon: material/brightness-4
|
||||
name: Switch to light mode
|
||||
features:
|
||||
- navigation.tabs
|
||||
- navigation.sections
|
||||
- content.code.copy
|
||||
- toc.follow
|
||||
|
||||
nav:
|
||||
- Home: index.md
|
||||
- Getting Started:
|
||||
- Quickstart: quickstart.md
|
||||
- Configuration Reference: configuration.md
|
||||
- Secrets: secrets.md
|
||||
- Guides:
|
||||
- Path Patterns: path-patterns.md
|
||||
- Format Strategies: format-strategies.md
|
||||
- CLI Usage: cli-usage.md
|
||||
- Troubleshooting: troubleshooting.md
|
||||
|
||||
markdown_extensions:
|
||||
- admonition
|
||||
- pymdownx.highlight:
|
||||
anchor_linenums: true
|
||||
line_spans: __span_0__
|
||||
pygments_lang_class: true
|
||||
- pymdownx.inlinehilite
|
||||
- pymdownx.superfences
|
||||
- pymdownx.tabbed:
|
||||
alternate_style: true
|
||||
- tables
|
||||
- attr_list
|
||||
- md_in_html
|
||||
|
||||
extra_css:
|
||||
- stylesheets/extra.css
|
||||
@@ -0,0 +1,146 @@
|
||||
# Path Patterns
|
||||
|
||||
How librofm-downloader organizes files on disk, and how to customize the layout with tokens.
|
||||
|
||||
## Default behavior
|
||||
|
||||
When no custom pattern is set, the output path is determined by **conditional logic** based on whether a book belongs to a series:
|
||||
|
||||
### Standalone book (no series)
|
||||
|
||||
```
|
||||
{FIRST_AUTHOR}/{BOOK_TITLE}
|
||||
```
|
||||
|
||||
Example: `Brandon Sanderson/The Way of Kings.m4b`
|
||||
|
||||
### Book in a series (with series number)
|
||||
|
||||
```
|
||||
{FIRST_AUTHOR}/{SERIES_NAME}/Book {SERIES_NUM} {BOOK_TITLE}
|
||||
```
|
||||
|
||||
Example: `Brandon Sanderson/Stormlight Archive/Book 1 The Way of Kings.m4b`
|
||||
|
||||
### Book in a series (no series number)
|
||||
|
||||
```
|
||||
{FIRST_AUTHOR}/{SERIES_NAME}/{BOOK_TITLE}
|
||||
```
|
||||
|
||||
Example: `J.K. Rowling/Harry Potter/Harry Potter and the Sorcerer's Stone.m4b`
|
||||
|
||||
### Subdirectory logic
|
||||
|
||||
A book gets its own subdirectory when **any** of these are true:
|
||||
|
||||
- The book has **PDF extras** available (`pdf_extras: true`)
|
||||
- `download_covers: true` **and** the book has a cover URL
|
||||
|
||||
Otherwise the audio file sits directly under the author directory as a flat file.
|
||||
|
||||
## Available tokens
|
||||
|
||||
Use these inside `{TOKEN}` placeholders in a custom pattern:
|
||||
|
||||
| Token | Source | Example value | Notes |
|
||||
|-------|--------|---------------|-------|
|
||||
| `{FIRST_AUTHOR}` | First item in authors list | `Brandon Sanderson` | Empty if no authors |
|
||||
| `{ALL_AUTHORS}` | Authors joined by `, ` | `Sanderson, Brandon` | Empty if no authors |
|
||||
| `{SERIES_NAME}` | Series name | `Stormlight Archive` | Empty string if not in a series |
|
||||
| `{SERIES_NUM}` | Series position integer | `1` | Empty if not in a series or no number |
|
||||
| `{BOOK_TITLE}` | Book title | `The Way of Kings` | Sanitized for filesystem safety |
|
||||
| `{ISBN}` | ISBN identifier | `9780743565400` | As returned by the API |
|
||||
| `{FIRST_NARRATOR}` | First narrator | `Kate Reading` | Empty if no narrators |
|
||||
| `{ALL_NARRATORS}` | Narrators joined by `, ` | `Kate Reading, Michael Kramer` | Empty if no narrators |
|
||||
| `{PUBLICATION_YEAR}` | Year published | `2024` | Empty if unknown |
|
||||
| `{PUBLICATION_MONTH}` | Month published | `8` | Empty if unknown |
|
||||
| `{PUBLICATION_DAY}` | Day published | `15` | Empty if unknown |
|
||||
|
||||
## Custom patterns
|
||||
|
||||
To override the default conditional logic, set a `path_pattern` key in your config:
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
format: m4b_mp3_fallback
|
||||
output_dir: ./audiobooks
|
||||
path_pattern: "{PUBLICATION_YEAR}/{FIRST_AUTHOR} - {BOOK_TITLE}"
|
||||
```
|
||||
|
||||
This would produce paths like:
|
||||
|
||||
```
|
||||
./audiobooks/2024/Brandon Sanderson - The Way of Kings.m4b
|
||||
./audiobooks/2023/Suzanne Collins - The Hunger Games.m4b
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> Custom patterns are applied via regex substitution (`{TOKEN_NAME}` → value).
|
||||
> Unknown tokens resolve to empty strings — no error is raised.
|
||||
> Each path component is sanitized (colons replaced, illegal chars stripped, capped at 255 chars).
|
||||
|
||||
## Pattern examples
|
||||
|
||||
### Flat by author
|
||||
|
||||
```yaml
|
||||
path_pattern: "{ALL_AUTHORS}/{BOOK_TITLE}"
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
audiobooks/Sanderson, Brandon/The Way of Kings.m4b
|
||||
audiobooks/Collins, Suzanne/The Hunger Games.m4b
|
||||
```
|
||||
|
||||
### Organized by series
|
||||
|
||||
```yaml
|
||||
path_pattern: "{FIRST_AUTHOR}/{SERIES_NAME}/{SERIES_NUM:03d} - {BOOK_TITLE}"
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
audiobooks/Brandon Sanderson/Stormlight Archive/001 - The Way of Kings.m4b
|
||||
audiobooks/Brandon Sanderson/Mistborn/001 - The Final Empire.m4b
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
> Python format specs like `:03d` are **not supported** — tokens produce plain strings only.
|
||||
> Use `{SERIES_NUM}` directly; it will render as `1`, `2`, etc.
|
||||
|
||||
### By narrator
|
||||
|
||||
```yaml
|
||||
path_pattern: "{FIRST_NARRATOR}/{BOOK_TITLE}"
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
audiobooks/Kate Reading/The Way of Kings.m4b
|
||||
```
|
||||
|
||||
### ISO-style date prefix
|
||||
|
||||
```yaml
|
||||
path_pattern: "{PUBLICATION_YEAR}-{PUBLICATION_MONTH}-{PUBLICATION_DAY}/{FIRST_AUTHOR}/{BOOK_TITLE}"
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
audiobooks/2024-8-15/Brandon Sanderson/The Way of Kings.m4b
|
||||
```
|
||||
|
||||
## Path sanitization
|
||||
|
||||
Every path component goes through sanitization before being written to disk:
|
||||
|
||||
1. **Colons** (`:`) → replaced with ` -`
|
||||
2. **Illegal characters** `< > / \ | ? *` → stripped
|
||||
3. **Control characters** (U+0000–U+001F) → stripped
|
||||
4. **Trailing dots** → removed
|
||||
5. **Whitespace** → trimmed
|
||||
6. **Length** → capped at 255 characters
|
||||
|
||||
Preserved characters include dashes, commas, apostrophes, parentheses, and non-trailing periods.
|
||||
@@ -0,0 +1,148 @@
|
||||
# Quickstart
|
||||
|
||||
Get librofm-downloader installed, configured, and running in three steps.
|
||||
|
||||
## 1. Install
|
||||
|
||||
### From PyPI (recommended)
|
||||
|
||||
```bash
|
||||
pip install librofm-downloader
|
||||
```
|
||||
|
||||
Requires **Python 3.11+**.
|
||||
|
||||
### From source
|
||||
|
||||
```bash
|
||||
git clone https://github.com/AlexKucera/librofm-downloader.git
|
||||
cd librofm-downloader
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate # or .venv\Scripts\activate on Windows
|
||||
pip install -e ".[dev]"
|
||||
```
|
||||
|
||||
The `[dev]` extra installs pytest for testing — omit it if you only want to run the tool.
|
||||
|
||||
## 2. Configure
|
||||
|
||||
librofm-downloader uses two YAML files:
|
||||
|
||||
| File | Purpose | Committed to git? |
|
||||
|------|---------|:-----------------:|
|
||||
| `config.yaml` | Preferences (format, output dir, toggles) | ✅ Yes |
|
||||
| `secrets.yaml` | Credentials only | ❌ No (gitignored) |
|
||||
|
||||
### config.yaml
|
||||
|
||||
```yaml
|
||||
# libro.fm downloader configuration
|
||||
# This file is safe to commit — no credentials here.
|
||||
# Credentials go in secrets.yaml (which is gitignored).
|
||||
|
||||
librofm:
|
||||
# Audio format preference:
|
||||
# m4b_mp3_fallback — try M4B first, fall back to MP3 ZIP (default)
|
||||
# mp3_only — download MP3 ZIP only
|
||||
# m4b_only — download M4B only, skip if unavailable
|
||||
format: m4b_mp3_fallback
|
||||
|
||||
# Where downloaded audiobooks are saved
|
||||
output_dir: ./audiobooks
|
||||
|
||||
# Whether to download PDF extras when available
|
||||
download_extras: true
|
||||
|
||||
# Whether to download cover art when available
|
||||
download_covers: true
|
||||
```
|
||||
|
||||
### secrets.yaml
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
username: your-email@example.com
|
||||
password: your-password
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
> Never commit `secrets.yaml`. It is listed in `.gitignore` by default.
|
||||
> If you accidentally put credentials in `config.yaml`, the tool will refuse to start and tell you to move them.
|
||||
|
||||
## 3. Run
|
||||
|
||||
### Basic sync
|
||||
|
||||
```bash
|
||||
librofm-downloader
|
||||
```
|
||||
|
||||
This:
|
||||
|
||||
1. Loads `config.yaml` + `secrets.yaml`
|
||||
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 with a progress bar
|
||||
6. Records successful downloads to history
|
||||
|
||||
### First run output (TTY)
|
||||
|
||||
```
|
||||
3 book(s) to download:
|
||||
|
||||
Author One - Book Title One ██████████████████████████ 100.0% 2.1 MB/s 00:01 45.2 MB
|
||||
✓ Book Title One
|
||||
Author Two - Another Book ██████████████████████████ 100.0% 1.8 MB/s 00:02 120.5 MB
|
||||
✓ Another Book
|
||||
Author Three - Third Book ██████████████████████████ 100.0% 2.3 MB/s 00:00 89.1 MB
|
||||
✓ Third Book
|
||||
|
||||
Summary: 3 downloaded, 0 skipped, 0 failed
|
||||
```
|
||||
|
||||
### Subsequent run (nothing new)
|
||||
|
||||
```
|
||||
All caught up! No new books to download.
|
||||
```
|
||||
|
||||
### Cron / non-TTY output
|
||||
|
||||
When stdout is not a terminal (e.g., cron, piped), output switches to plain text log lines:
|
||||
|
||||
```
|
||||
Downloading: Author One - Book Title One (unknown size)
|
||||
Completed: Author One - Book Title One
|
||||
Downloading: Author Two - Another Book (unknown size)
|
||||
Completed: Author Two - Another Book
|
||||
|
||||
Summary: 2 downloaded, 0 skipped, 0 failed
|
||||
```
|
||||
|
||||
## What gets downloaded?
|
||||
|
||||
Files land under your `output_dir` using this structure:
|
||||
|
||||
```
|
||||
audiobooks/
|
||||
├── Brandon Sanderson/
|
||||
│ ├── The Way of Kings/
|
||||
│ │ ├── The Way of Kings.m4b
|
||||
│ │ ├── cover.jpg
|
||||
│ │ └── map.pdf
|
||||
│ └── Words of Radiance.m4b ← no extras = flat file
|
||||
└── Suzanne Collins/
|
||||
└── The Hunger Games.m4b
|
||||
```
|
||||
|
||||
- Books with **cover art or PDF extras** get a subdirectory (`Author/Title/`)
|
||||
- Books without extras are flat files (`Author/Title.m4b`)
|
||||
- See [Path Patterns](path-patterns.md) for customization options
|
||||
|
||||
## Next steps
|
||||
|
||||
- [Configuration Reference](configuration.md) — every field documented
|
||||
- [Format Strategies](format-strategies.md) — choose the right mode for your setup
|
||||
- [CLI Usage](cli-usage.md) — all flags, exit codes, cron examples
|
||||
- [Troubleshooting](troubleshooting.md) — common problems and solutions
|
||||
@@ -0,0 +1,101 @@
|
||||
# Secrets
|
||||
|
||||
Why `secrets.yaml` exists, how it works, and common mistakes to avoid.
|
||||
|
||||
## Purpose
|
||||
|
||||
Libro.fm authentication requires your email and password. These are stored in a **separate file** from your regular configuration so you can safely commit `config.yaml` to version control without leaking credentials.
|
||||
|
||||
## File format
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
username: your-email@example.com
|
||||
password: your-password
|
||||
```
|
||||
|
||||
Two fields, both required, both strings. That's it.
|
||||
|
||||
## Why it's gitignored
|
||||
|
||||
The `.gitignore` entry:
|
||||
|
||||
```
|
||||
secrets.yaml
|
||||
```
|
||||
|
||||
This is set up by default in the project template. If you clone the repo and create `secrets.yaml`, Git will never track it.
|
||||
|
||||
## Common mistakes
|
||||
|
||||
### 1. Putting credentials in config.yaml
|
||||
|
||||
If you accidentally add `username` or `password` to `config.yaml`:
|
||||
|
||||
```yaml
|
||||
# ❌ Wrong — config.yaml
|
||||
librofm:
|
||||
username: me@example.com # <-- this will be rejected
|
||||
password: secret # <-- this will be rejected
|
||||
format: m4b_mp3_fallback
|
||||
```
|
||||
|
||||
The tool refuses to start:
|
||||
|
||||
```
|
||||
Config error: Credentials (username, password) found in config.yaml.
|
||||
Move them to secrets.yaml (which is gitignored).
|
||||
```
|
||||
|
||||
**Fix:** Remove those lines from `config.yaml` and put them in `secrets.yaml`.
|
||||
|
||||
### 2. Committing before gitignore
|
||||
|
||||
If you `git add secrets.yaml` **before** the `.gitignore` rule was added, Git may already be tracking it:
|
||||
|
||||
```bash
|
||||
# Check if Git is tracking it
|
||||
git ls-files | grep secrets.yaml
|
||||
|
||||
# If it shows up, remove it from tracking (keeps local file)
|
||||
git rm --cached secrets.yaml
|
||||
git commit -m "Stop tracking secrets.yaml"
|
||||
```
|
||||
|
||||
### 3. Missing fields
|
||||
|
||||
If `secrets.yaml` exists but is missing `username` or `password`:
|
||||
|
||||
```
|
||||
Missing required fields in secrets.yaml: username, password.
|
||||
Add them to your secrets.yaml file.
|
||||
```
|
||||
|
||||
Both fields are **required** — there are no defaults for credentials.
|
||||
|
||||
### 4. Wrong indentation
|
||||
|
||||
YAML is whitespace-sensitive. The `librofm:` key must be at column 0, and `username`/`password` must be indented with exactly 2 spaces:
|
||||
|
||||
```yaml
|
||||
# ✅ Correct
|
||||
librofm:
|
||||
username: me@example.com
|
||||
password: secret
|
||||
|
||||
# ❌ Wrong — no indentation
|
||||
librofm:
|
||||
username: me@example.com
|
||||
password: secret
|
||||
|
||||
# ❌ Wrong — wrong key name (not under librofm:)
|
||||
username: me@example.com
|
||||
password: secret
|
||||
```
|
||||
|
||||
## Security notes
|
||||
|
||||
- The password is stored in **plaintext** on disk — this is a CLI tool for personal use, not a multi-user service
|
||||
- The password is sent to Libro.fm's OAuth2 token endpoint over HTTPS; it is never logged or transmitted elsewhere
|
||||
- If your Libro.fm account has 2FA enabled, you may need an [app-specific password](https://libro.fm/settings) depending on how Libro.fm handles OAuth2 password grants
|
||||
- Never share your `secrets.yaml` file — if you do, **rotate your Libro.fm password immediately**
|
||||
@@ -0,0 +1,4 @@
|
||||
/* Custom overrides for librofm-downloader docs */
|
||||
md-typeset table {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
# Troubleshooting
|
||||
|
||||
Common errors, their causes, and how to fix them.
|
||||
|
||||
## Authentication failures
|
||||
|
||||
### "Authentication failed: Auth failed (401)"
|
||||
|
||||
**Cause:** Wrong email or password in `secrets.yaml`.
|
||||
|
||||
**Fix:**
|
||||
|
||||
1. Verify you can log in to [libro.fm](https://libro.fm) in a browser with the same credentials
|
||||
2. Check for typos in `secrets.yaml` (YAML is case-sensitive)
|
||||
3. If you changed your Libro.fm password recently, update `secrets.yaml`
|
||||
|
||||
### "Authentication failed: Auth failed (xxx)" (non-401)
|
||||
|
||||
**Cause:** Network issue or Libro.fm API temporarily down.
|
||||
|
||||
**Fix:**
|
||||
|
||||
1. Check your internet connection
|
||||
2. Try again in a few minutes
|
||||
3. Check [Libro.fm status](https://status.libro.fm) if available
|
||||
|
||||
## Configuration errors
|
||||
|
||||
### "Config error: Credentials (...) found in config.yaml"
|
||||
|
||||
**Cause:** You put `username` or `password` in `config.yaml` instead of `secrets.yaml`.
|
||||
|
||||
**Fix:** Remove those lines from `config.yaml`. They belong only in `secrets.yaml`. See [Secrets](secrets.md).
|
||||
|
||||
### "Missing required fields in secrets.yaml: username"
|
||||
|
||||
**Cause:** `secrets.yaml` is missing a required field.
|
||||
|
||||
**Fix:** Add both `username` and `password` under the `librofm:` key:
|
||||
|
||||
```yaml
|
||||
librofm:
|
||||
username: your-email@example.com
|
||||
password: your-password
|
||||
```
|
||||
|
||||
### "Invalid format 'xyz'"
|
||||
|
||||
**Cause:** The `format` value in `config.yaml` is not one of the three valid strategies.
|
||||
|
||||
**Fix:** Use one of:
|
||||
|
||||
- `m4b_mp3_fallback`
|
||||
- `mp3_only`
|
||||
- `m4b_only`
|
||||
|
||||
### "[Errno 2] No such file or directory: 'config.yaml'"
|
||||
|
||||
**Cause:** The config file doesn't exist at the specified path (default: current directory).
|
||||
|
||||
**Fix:**
|
||||
|
||||
```bash
|
||||
# Run from the directory that contains config.yaml
|
||||
cd /path/to/your/project
|
||||
|
||||
# Or specify the path explicitly
|
||||
librofm-downloader --config /path/to/config.yaml --secrets /path/to/secrets.yaml
|
||||
```
|
||||
|
||||
## Download issues
|
||||
|
||||
### Download stops partway through
|
||||
|
||||
**Cause:** Network interruption, timeout, or you pressed Ctrl+C.
|
||||
|
||||
**Behavior:**
|
||||
- Exit code **130** if Ctrl+C
|
||||
- Partial file saved as `{filename}.m4b.partial` or `{filename}.zip.partial`
|
||||
|
||||
**Fix — resume on next run:**
|
||||
The tool automatically detects `.partial` files and sends an HTTP `Range` header to resume from where it stopped. Just run again:
|
||||
|
||||
```bash
|
||||
librofm-downloader
|
||||
```
|
||||
|
||||
### "Failed: Author - Title [ISBN] (connection error)"
|
||||
|
||||
**Cause:** Intermittent network failure during a single book's download.
|
||||
|
||||
**Behavior:**
|
||||
- That book is marked as **failed** in the summary
|
||||
- All other books continue downloading normally
|
||||
- Exit code is still **0** (pipeline completed)
|
||||
|
||||
**Fix:**
|
||||
Run again — the failed book will be retried (it wasn't recorded in history since it didn't complete):
|
||||
|
||||
```bash
|
||||
$ librofm-downloader
|
||||
Summary: 0 downloaded, 0 skipped, 1 failed
|
||||
Failed:
|
||||
✗ Brandon Sanderson - The Way of Kings [9780743565400] (connection error)
|
||||
|
||||
# Run again — it will retry the failed book
|
||||
$ librofm-downloader
|
||||
```
|
||||
|
||||
### Book shows as skipped with m4b_only mode
|
||||
|
||||
**Cause:** The book has no M4B format available from Libro.fm (API returns 404).
|
||||
|
||||
**Behavior:**
|
||||
- Book appears under `Skipped:` in summary
|
||||
- Not written to download history
|
||||
|
||||
**Fix options:**
|
||||
- Switch to `m4b_mp3_fallback` to get the MP3 version instead
|
||||
- Accept that some books aren't available in M4B format
|
||||
|
||||
## History file problems
|
||||
|
||||
### "Corrupt history file download_history.json: ... Starting with empty history."
|
||||
|
||||
**Cause:** The `download_history.json` file exists but contains invalid JSON.
|
||||
|
||||
**Behavior:**
|
||||
- Tool starts with empty history (all books appear as "new")
|
||||
- Already-downloaded books will be re-downloaded
|
||||
|
||||
**Fix:**
|
||||
|
||||
```bash
|
||||
# Option 1: Delete and let it rebuild
|
||||
rm download_history.json
|
||||
librofm-downloader
|
||||
|
||||
# Option 2: Fix the JSON manually (if you know what's in there)
|
||||
# Check for trailing commas, missing braces, etc.
|
||||
```
|
||||
|
||||
### Books re-downloading after already being downloaded
|
||||
|
||||
**Cause:** The ISBN in the library response doesn't match what's stored in history.
|
||||
|
||||
**Check:**
|
||||
|
||||
```bash
|
||||
# See what's recorded
|
||||
cat download_history.json | python -m json.tool
|
||||
|
||||
# Look for the ISBN of the book that's re-downloading
|
||||
```
|
||||
|
||||
**Possible reasons:**
|
||||
- The book was re-published under a new ISBN
|
||||
- History file was deleted or moved
|
||||
- You're running from a different directory with a different history file
|
||||
|
||||
## Output / path issues
|
||||
|
||||
### Files going to wrong directory
|
||||
|
||||
**Cause:** `output_dir` setting or CWD mismatch.
|
||||
|
||||
**Check:**
|
||||
|
||||
```bash
|
||||
# Verify your config
|
||||
grep output_dir config.yaml
|
||||
|
||||
# Check where you're running from
|
||||
pwd
|
||||
|
||||
# Use absolute paths to avoid ambiguity
|
||||
librofm-downloader --config /absolute/path/to/config.yaml
|
||||
```
|
||||
|
||||
### "Permission denied" when writing files
|
||||
|
||||
**Cause:** The user running the tool doesn't have write access to `output_dir`.
|
||||
|
||||
**Fix:**
|
||||
|
||||
```bash
|
||||
# Check permissions
|
||||
ls -la ./audiobooks/
|
||||
|
||||
# Fix ownership or choose a writable directory
|
||||
chmod u+w ./audiobooks/
|
||||
# or set output_dir to somewhere writable in config.yaml
|
||||
```
|
||||
|
||||
## Performance
|
||||
|
||||
### Downloads are slow
|
||||
|
||||
**Check:**
|
||||
|
||||
1. Your internet connection speed
|
||||
2. Whether a VPN/proxy is adding latency
|
||||
3. Libro.fm CDN responsiveness (varies by region)
|
||||
|
||||
The tool downloads in a **single stream per book** (no parallelism within one book), but processes books sequentially. There is no built-in rate limiting or parallel download feature.
|
||||
|
||||
### Large library takes a long time
|
||||
|
||||
Audiobooks are large (200 MB – 1 GB each). A library of 50 books at 2 MB/s would take ~7 hours just for transfer time. This is expected behavior.
|
||||
|
||||
Use `--limit` to process smaller batches:
|
||||
|
||||
```bash
|
||||
# Download 5 books at a time
|
||||
librofm-downloader --limit 5
|
||||
```
|
||||
|
||||
## Getting help
|
||||
|
||||
If none of the above covers your issue:
|
||||
|
||||
1. Run with `-v` (`--verbose`) to get detailed output including URLs and tracebacks
|
||||
2. Check the [GitHub Issues](https://github.com/AlexKucera/librofm-downloader/issues) for known problems
|
||||
3. Open a new issue with:
|
||||
- The error message (from `-v` output)
|
||||
- Your `format` setting
|
||||
- Whether it happens on every book or specific ones
|
||||
- Your OS and Python version (`python --version`)
|
||||
Reference in new issue
Block a user