Files
librofm-downloader/docs/mkdocs/cli-usage.md
T
AlexKucera a9a169d4c2 docs: update docs for XDG path resolution, bump v1.1.0
Update all documentation to reflect XDG-first config search
introduced in #22/#23. configuration.md gains a new Default File
Locations section with search order, auto-creation, missing-config
vs missing-secrets behavior, CLI flag overrides, and new error
messages. quickstart.md, cli-usage.md, troubleshooting.md, and
README.md updated accordingly. Bump version 0.1.0 → 0.2.0.

Closes #24
2026-06-04 10:54:43 +02:00

5.2 KiB

CLI Usage

Command-line interface reference for librofm-downloader.

Synopsis

librofm-downloader [OPTIONS]

Options

Option Short Default Description
--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

--verbose

Shows internal pipeline state at each stage:

── config ──────────────────────────────────────
  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
  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:

# 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

# 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

$ 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

# 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

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

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)

# /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
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.