How ludviglundgren/qbittorrent-cli works
1. What this repo is
- qbittorrent-cli is a Go-based command-line tool, not a server or web app.
- Its job is to automate qBittorrent administration through the qBittorrent WebUI API and by editing qBittorrent’s local state files.
2. Top-level execution model
- The binary entrypoint is cmd/qbt/main.go.
- Commands are organized with a Cobra-style CLI under cmd/, with subcommands for app info, categories, tags, torrent lifecycle actions, bencode editing, import/export, compare, and self-update.
3. Configuration boundary
- Global config is loaded from ~/.config/qbt/.qbt.toml by default, with --config override.
- internal/config and internal/domain/config.go define config parsing and app-level settings.
- Config is not just connection details; it also drives behavior rules such as limits on active downloads and automation defaults.
4. Primary external system: qBittorrent WebUI API
- The main integration is in pkg/qbittorrent/.
- client.go, methods.go, and domain.go form the API client and data model layer for qBittorrent requests/responses.
- Most torrent/category/tag commands ultimately translate into WebUI API calls against one qBittorrent instance, and torrent compare uses two client connections.
5. Core domain layer
- pkg/torrent/torrent.go is the repo’s generic torrent domain layer.
- It likely normalizes torrent identity and metadata such as hash, name, category, tags, trackers, and state so higher-level commands can work across API results and local files.
- This is the main abstraction between command logic and qBittorrent-specific wire formats.
6. Filesystem and bencode operations
- internal/fs/ contains local file utilities for copying and directory handling.
- cmd/bencode.go and pkg/qbittorrent/fastresume.go show that the tool directly manipulates bencoded qBittorrent state, especially .fastresume files in BT_backup.
- This is an important second boundary: some commands operate entirely on disk without calling the remote API.
7. Import pipeline from other clients
- internal/importer/deluge.go and internal/importer/rtorrent.go convert Deluge and rTorrent state into qBittorrent-compatible state.
- The import flow reads source client session/state files, maps torrent data into qBittorrent’s BT_backup format, and writes fastresume/torrent files into the target qBittorrent backup directory.
- The README’s warnings reflect that this is a state migration workflow, not a full data move.
8. Export/archive pipeline
- pkg/archive/archive.go supports exporting torrents and fastresume data out of qBittorrent storage.
- The torrent export command filters by category/tag and writes a portable export set, optionally with a manifest of used tags/categories.
- This forms the inverse of import: qBittorrent state on disk is packaged for backup or migration.
9. Command families and data flow
- category and tag commands manage qBittorrent metadata objects.
- torrent add, pause, resume, remove, recheck, reannounce, tracker edit, and category set/move/unset all act on torrents identified by hashes, names, categories, or tags.
- torrent list, compare, and hash are read-heavy commands that inspect torrent state either from the API or from .torrent/magnet inputs.
10. Automation-oriented flows
- torrent add can apply category, tags, path, speed limits, pause state, and skip-hash options, which makes it suitable for integration with autodl-irssi/rutorrent.
- torrent category move supports seed-time and tag filters, enabling automated tiering such as moving torrents from fast storage to slower storage.
- torrent tag issues and torrent reannounce are operational maintenance workflows for tracker health.
11. Self-update and release distribution
- cmd/update.go suggests the CLI can update itself, and .github/workflows/release.yml plus .goreleaser.yml indicate GitHub Releases are the distribution channel.
- That means the repo has a build/release pipeline separate from runtime behavior, but it directly affects how binaries are installed and updated.
12. Testing and fixtures
- Tests under cmd/ and internal/importer/ use fixture data in test/.
- The fixtures include real-looking qBittorrent BT_backup, Deluge state files, and torrent samples, which indicates the important edge cases are file-format and migration correctness rather than UI behavior.
Main entry points: torrent.go Torrent · main.go Main · client.go Client · torrent_compare.go Compare
Components 22
CLI
Cobra command entrypoints and command families
- Main · Binary entrypoint and root command setup
cmd/qbt/main.go - App info · Global app and status command
cmd/app.go - Category · Category management commands
cmd/category.go - Tag · Tag management commands
cmd/tag.go - Torrent · Torrent lifecycle and inspection commands
cmd/torrent.go - Add · Add torrents with automation options
cmd/torrent_add.go - Move set · Set, move, and unset torrent categories
cmd/torrent_category.go - Compare · Compare torrent state across clients or inputs
cmd/torrent_compare.go - Export · Export qBittorrent torrents and backup state
cmd/torrent_export.go - Import · Import state from other clients into qBittorrent format
cmd/torrent_import.go - Ops · Pause, resume, remove, recheck, reannounce, list, hash, tracker, and tag issue workflows
Core
Shared configuration, domain, and filesystem support
- Config · Config loading and app settings
internal/config/config.go - Rules · Application-level configuration domain
internal/domain/config.go - FS utils · Local file and directory helpers
internal/fs - Torrent model · Repository-wide torrent abstraction and normalization
pkg/torrent/torrent.go
qBittorrent
Remote API client and qBittorrent-specific models
Disk flows
Local bencode, archive, and migration workflows
- Fastresume · qBittorrent fastresume parsing and writing
pkg/qbittorrent/fastresume.go - Archive · Portable torrent and backup export packaging
pkg/archive/archive.go - Deluge import · Deluge state conversion into qBittorrent backup format
internal/importer/deluge.go - rTorrent import · rTorrent state conversion into qBittorrent backup format
internal/importer/rtorrent.go
Delivery
Build, release, and self-update mechanics
- Update · Self-update and release channel command
cmd/update.go
Connections 30
- Main → App info: wires · Root command includes global app info command
- Main → Category: wires · Root command includes category commands
- Main → Tag: wires · Root command includes tag commands
- Main → Torrent: wires · Root command includes torrent command family
- Main → Update: wires · Root command includes self-update command
- Torrent → Add: contains · Torrent family includes add workflow
- Torrent → Move set: contains · Torrent family includes category mutation workflow
- Torrent → Compare: contains · Torrent family includes comparison workflow
- Torrent → Export: contains · Torrent family includes export workflow
- Torrent → Import: contains · Torrent family includes import workflow
- Torrent → Ops: contains · Torrent family includes operational actions and inspection
- App info → Config: loads · Commands read global configuration
- Category → Client: uses · Category commands call qBittorrent API
- Tag → Client: uses · Tag commands call qBittorrent API
- Ops → Client: uses · Torrent operations are primarily API-driven
- Compare → Client: uses · Comparison can connect to one or two qBittorrent instances
- Add → Torrent model: normalizes · Add command maps inputs into shared torrent domain
- Compare → Torrent model: reads · Compare works across torrent identity and metadata
- Export → Archive: packages · Export command writes portable archive sets
- Import → Deluge import: uses · Import flow supports Deluge source state
- Import → rTorrent import: uses · Import flow supports rTorrent source state
- Deluge import → Fastresume: writes · Deluge migration emits qBittorrent fastresume data
- rTorrent import → Fastresume: writes · rTorrent migration emits qBittorrent fastresume data
- Deluge import → FS utils: reads/writes · Import pipeline handles local state files and directories
- rTorrent import → FS utils: reads/writes · Import pipeline handles local state files and directories
- Archive → FS utils: packages · Archive flow reads and writes local backup files
- Fastresume → QBT model: encodes · Fastresume handling is qBittorrent-specific
- Client → QBT model: serializes · API client marshals qBittorrent wire models
- Torrent model → QBT model: bridges · Shared torrent abstraction normalizes qBittorrent results
- Config → Rules: defines · Config parsing feeds application config rules