# arr-tui — Specification A terminal UI to search for movies and series, add them to Radarr / Sonarr, and watch the downloads progress in SABnzbd. - **Language:** Go - **TUI library:** [tview](https://github.com/rivo/tview) (on top of tcell) - **License:** MIT - **Module:** `git.stinnesbeck.com/nils/arr-tui` - **Status:** M10 done ## 1. Goals 1. Search for movies (Radarr) and series (Sonarr) from one place. 2. Add a result to Radarr/Sonarr with sensible defaults (quality profile, root folder, monitored) and trigger a search so it gets downloaded. 3. Show the SABnzbd queue and history with live progress. 4. Be fast and keyboard-driven; usable over SSH. ### Non-goals (for now) - Managing indexers, download clients, or Radarr/Sonarr settings. - Replacing the Radarr/Sonarr web UIs for library management. - Torrent clients (SABnzbd / Usenet only). - Multi-user / auth beyond API keys. ## 2. How the pieces fit together ``` ┌────────────┐ lookup / add / release search ┌──────────┐ │ │ ────────────────────────────────▶ │ Radarr │──┐ │ arr-tui │ └──────────┘ │ sends NZB │ │ ────────────────────────────────▶ ┌──────────┐ │ │ │ │ Sonarr │──┤ └─────┬──────┘ └──────────┘ │ │ queue / history / pause / resume ▼ └────────────────────────────────────────▶ ┌──────────────┐ │ SABnzbd │ └──────────────┘ ``` Radarr/Sonarr are expected to already have SABnzbd configured as their download client. arr-tui talks to all three APIs directly; it does **not** send NZBs to SABnzbd itself, except possibly via the manual-release flow, which still goes through Radarr/Sonarr (see 4.3). ## 3. External APIs | Service | API | Auth | Endpoints used | |---|---|---|---| | Radarr | v3 REST (JSON) | `X-Api-Key` header | `GET /api/v3/movie/lookup?term=`, `GET /api/v3/movie`, `POST /api/v3/movie`, `GET /api/v3/qualityprofile`, `GET /api/v3/rootfolder`, `GET /api/v3/queue`, `GET /api/v3/release?movieId=`, `POST /api/v3/release`, `POST /api/v3/command` (`MoviesSearch`), `GET /api/v3/system/status` | | Sonarr | v3 REST (JSON) | `X-Api-Key` header | `GET /api/v3/series/lookup?term=`, `GET /api/v3/series`, `POST /api/v3/series`, `GET /api/v3/qualityprofile`, `GET /api/v3/rootfolder`, `GET /api/v3/queue`, `GET /api/v3/release?episodeId=` / `?seriesId=&seasonNumber=`, `POST /api/v3/release`, `POST /api/v3/command` (`SeriesSearch`, `SeasonSearch`, `EpisodeSearch`), `GET /api/v3/system/status` | | SABnzbd | `/api?mode=...&output=json` | `apikey` query param | `mode=queue`, `mode=history`, `mode=pause` / `resume`, `mode=queue&name=delete`, `mode=version` | Notes: - Endpoint shapes should be verified against each instance's own Swagger / the official docs when implementing; Radarr and Sonarr occasionally change fields between versions. - Lookup results include an `id` of `0` when the item is not yet in the library; a non-zero `id` means it is already added. We use this to show an "in library" badge. ## 4. Features ### 4.1 MVP (v0.1) - **Config:** load URLs + API keys from a config file; fail with a clear message if missing or unreachable. - **Search:** a Movies view (Radarr) and a Series view (Sonarr), each with a search box. Results list with title, year, rating, status, and an "in library" marker. Detail pane with overview, runtime, genres, network/studio. - **Add:** from a result, open a small form: quality profile, root folder, monitored (yes/no), "search now" (yes/no); for series also monitor mode (all / future / first season / none). Submit calls `POST /movie` or `POST /series` with `addOptions.searchForMovie` / `searchForMissingEpisodes`. - **Interactive release search:** for a movie (or a series' season/episode) in the library, list releases from indexers (`GET /release`) with title, indexer, size, quality, age, and rejection reasons; sort/filter; grab a chosen one (`POST /release`). Rejected releases can be grabbed only after an explicit confirmation. The list can be filtered by quality, codec (x265/x264/AV1), HDR/DV/SDR, audio format and language; releases carry no media info, so codec and HDR are read from the title, quality and custom formats (a release that does not name its codec never matches a codec filter). - **Downloads view:** all downloads and queues in one place, auto-refreshing every few seconds: - SABnzbd queue (name, size, progress, ETA, speed) and history (completed / failed, with retry). - Radarr and Sonarr queues (status, warnings, import errors), so stuck imports are visible. - Global speed / pause state in the status bar. Pause/resume and delete a SABnzbd job. - **Status bar / help:** the bottom bar lists the keys that work in the current view or panel; the top right shows the connection state of each service; `?` opens the full key reference. - **Posters:** the detail panes show the poster at the top right; the head (title, facts, path) and the plot are one text that flows along the poster's left side and continues at full width below it (text is wrapped by arr-tui itself, with a narrower width for the first lines); on panes too small for the poster, the text simply uses the full width. Two ways to draw the poster, chosen by `ui.cover_style`: - **Real images** (`kitty`, and `auto` in kitty/Ghostty): the Kitty graphics protocol with Unicode placeholders. The poster (kept up to 640 px tall) is uploaded once as PNG (`a=t,f=100,q=2`, 4096-byte base64 chunks), placed virtually with the cell footprint (`a=p,U=1,c=,r=`; a new size deletes and recreates the placement), and shown by writing U+10EEEE placeholder characters whose combining marks give row and column (the 297-entry table from the protocol) and whose foreground color is the image id. Since it is ordinary text, popups, dialogs and view changes cover it correctly and tcell's diffing keeps it in place. The footprint uses the real cell size in pixels (from the terminal's window size) and a box whose shape is within 3% of the poster's; the remaining sliver is cropped from the poster's edges before upload (one upload per size, the previous one is deleted), because the terminal letterboxes an image that does not fit its box exactly. As a second safeguard the placeholder cells use the panes' background color, so anything the picture does not cover blends in (without it the terminal's own, slightly different, default background showed as grey bars beside the poster). Writes to the terminal go through the screen's tty on the UI goroutine, so they cannot interleave with drawing. Requires 24-bit color; otherwise, and inside tmux/screen, the block fallback is used. Terminals are recognised from `TERM`/`TERM_PROGRAM`/`KITTY_WINDOW_ID`/`GHOSTTY_RESOURCES_DIR`. The go-termimg library was looked at and not used: its placeholder support is marked experimental, its diacritic table does not match the protocol's, and it writes images straight to the terminal instead of through the screen. - **Block characters** (`quadrant`, `sextant`, and the fallback): every cell shows several pixels in the best two-color split (`quadrant`: 2×2 pixels, glyphs from the Block Elements range every font has; `sextant`: 2×3 pixels, sharper, glyphs from Symbols for Legacy Computing). `auto` picks sextants on kitty, WezTerm, foot and Ghostty, and on other terminals when fontconfig lists a font with the sextant characters (`fc-list :charset=1fb00`, about 20 ms at startup; terminals draw glyphs their font lacks from fallback fonts; skipped over SSH because the installed fonts are the remote machine's), and quadrants otherwise. Posters are JPEG/PNG, decoded and downscaled in the process. Library items fetch `/MediaCover//poster-250.jpg` from their Radarr/Sonarr instance with the API key; search results fall back to the provider's `remoteUrl` (fetched without credentials). Posters are cached in memory (the terminal's copies are deleted when the cache is dropped and on exit), failed downloads are not retried for two minutes, and the poster shrinks or disappears when the pane is too short. `ui.covers: false` disables it. - **Calendar view (F5):** a two-week window (starting today, moved a week at a time with `[`/`]`, `t` returns to today) with the library's movie releases and airing episodes, grouped by day. Radarr `GET /calendar` supplies the cinema, digital and physical release dates (taken as written: midnight UTC means that calendar day) and Sonarr `GET /calendar?includeSeries=true` the episodes with their air time (shown in local time). Unmonitored items are included with `u`. A movie appears once per release date in the window. Each entry shows type, title, episode or release kind and status (downloaded / missing / upcoming); the detail pane shows poster and plot; `Enter`/`i` starts the release search and `s` an automatic search. - **Download notifications:** a background poller (independent of the visible view) reads SABnzbd's history every 15 s and announces downloads that reach `Completed` or `Failed` as a popup and log entry; the first poll only records the current state. `ui.notify_downloads` (default true) and `ui.bell` (default false, rings the terminal bell) control it. Connection errors are not reported here, the indicators and the log already do that. - **Config view (F7):** a form for every setting of the config file, in four sections (Radarr, Sonarr, SABnzbd, Interface) plus Test connections / Save / Revert. The fields start from the settings in use; API keys are masked (a checkbox shows them). `Test connections` builds temporary clients from the typed values and reports each service. `Save` validates like startup does (URLs, non-empty keys, refresh 1–3600 s), then writes the file from the file's own contents plus the edits (`config.LoadFile`), so values that only come from `ARR_TUI_*` environment variables are left as the file has them and are shown greyed out; the write is atomic (temp file + rename) and keeps the file's permissions (`0600` when new); defaults such as `covers: true` stay out of the file unless it already named them. Everything then applies without a restart: the Radarr/Sonarr/SABnzbd clients are re-pointed (`Reconfigure`, guarded by a mutex), the connection indicators, add-form defaults and options are refreshed, the library and calendar reload, the Downloads interval, notifications, bell and poster style are switched live. `q` and `?` are typed text in this view (`F9` opens the help). - **Notifications and log (F6):** feedback about actions (added, deleted, grabbed, failures) appears as popups in the bottom right that fade away (errors stay longer). Everything is also kept in the Log view; only connection changes of the background polling are logged, not every failed poll. ### 4.2 v0.2 (done, M8) - **Library view:** movies (top) and series (below) with the details of the selected item on the right; Tab switches between the two lists. Filters (status: all, missing, downloaded, monitored, unmonitored), a file-property filter (`F`: quality 2160p/1080p/720p/SD, codec x265/x264/AV1, HDR/DV/SDR, audio format Atmos/TrueHD/DTS:X/DTS-HD/DTS/DD+/DD/AAC/FLAC/Opus, audio language; changes apply live to the list behind the dialog, including while moving through an open dropdown, and Esc restores the previous filter; each dropdown only lists options that, together with the other chosen criteria, still match at least one item (series files are read when the dialog opens so this is accurate)) act only on the focused list, and each list keeps its own status filter, property filter and text; the lists show their active filters in their titles. Movie properties come from the movie list; series properties are read per series from `GET /episodefile?seriesId=` only while a property filter is active, cached while a series' file count and size stay the same, and a series matches when any of its files does. `t` toggles monitoring, `s` starts an automatic search, `d` removes the item from the library (a dialog with "Delete files from disk" and "import exclusion" checkboxes, both off by default and Cancel focused first; `DELETE /movie|series/{id}?deleteFiles=&addImport(List)Exclusion=`), `i`/Enter opens the release search (movies) or the drill-down (series). - **Series drill-down:** seasons and episodes, toggle monitoring per season/episode, trigger season/episode search and release search. ### 4.3 Later / ideas - Poster preview via sixel / kitty graphics where supported. ## 5. UI Design (tview) Layout sketch (Library view; the other views follow the same frame): ``` ┌ arr-tui ───────────────────────────────────────────────────────────┐ │ 1 Movies 2 Series 3 Library 4 Downloads 5 Log ● Radarr ● Sonarr ● SAB │ ← tab bar + connection state │ Library · Movies 12/40 · Series 5/9 · filter: missing │ │ Filter: ______________________ │ ├─ Movies ───────────────────────┬─ Details ─────────────────────────┤ │ ● Movie One (2021) missing │ Title (Year) │ │ ● Movie Two (2019) ✓ WEB-DL │ ★ 7.8 · 142 min · Sci-Fi │ ├─ Series ───────────────────────┤ Overview text wraps here... │ │ ● Show One (2008) 12/62 │ │ │ ○ Show Two (2015) 10/10 │ │ ├────────────────────────────────┴───────────────────────────────────┤ │ Tab movies/series · f filter · / text · t monitor · ? help · q quit │ ← key hints of the current view └────────────────────────────────────────────────────────────────────┘ ``` Popups for action feedback appear in the bottom right and fade away; the Log view (F6) keeps the history. tview primitives: `Pages` (views and stacked overlays), `Flex` (layout), `InputField` (search), `List`/`Table` (results, queues, library), `TextView` (details, log), `Form` (add dialog), `Modal` (confirmations). Popups are drawn by a wrapper around the root primitive. Keybindings (the status bar shows the ones that apply to the current view): | Key | Action | |---|---| | `F1-F7` | Switch view (Movies, Series, Library, Downloads, Calendar, Log, Config); also while typing, and from full-screen views. Dialogs block them. | | `Tab` / `Shift+Tab` | Switch panel within the current view (never the view): search box / results, Downloads panels, Library lists | | `?` / `F9` | Help (`F9` also works while typing) | | `q` / `Ctrl+C` | Quit | | `Esc` | Close a dialog or a full-screen view | | `/` | Movies, Series, Library: focus the search / text filter | | `Enter` / `a` | Movies, Series: add the selected result (dialog: ↑↓ move, ←→ change dropdowns) | | `i` | Movies, Series, Library: interactive release search (series: seasons and episodes) | | `F` | Library and release list: filter by properties (quality, codec, HDR/DV, audio, language) | | `f` | Library: cycle the status filter; release list: hide rejected releases | | `[` `]` `t` `u` | Calendar: week back / forward, today, include unmonitored | | `d` | Library: remove the item from the library (asks first) | | `t` | Library, episodes: toggle monitored; Downloads history: retry a failed download | | `s` | Library, episodes: automatic search; release list: cycle sort (best / size / age) | | `Enter` / `g` | Release list: grab the selected release (rejected ones ask for confirmation) | | `Enter` | Library: open; episodes: expand a season or search releases for an episode | | `p` / `d` / `b` / `r` | Downloads: pause/resume SABnzbd, delete job / history entry / arr queue item, remove from arr queue + blocklist, refresh | | `r` | Library, episodes: reload | | `G` / `c` | Log: follow new entries / clear | ## 6. Architecture - All network I/O runs in goroutines; UI updates go through `app.QueueUpdateDraw`. Never block the UI thread. - Debounced search (e.g. 300 ms) with request cancellation via `context.Context`. - A single ticker drives SABnzbd/queue polling, only while the Downloads view (or the status bar) needs it. - HTTP client per service with timeouts, and a typed error that the UI can show in the status bar rather than crashing. Proposed layout: ``` arr-tui/ ├── cmd/arr-tui/main.go # entry point, wires config + UI ├── internal/ │ ├── config/ # load/validate config │ ├── radarr/ # client + types │ ├── sonarr/ # client + types │ ├── sabnzbd/ # client + types │ ├── arr/ # shared bits (HTTP helper, quality profile, root folder types) │ └── ui/ # tview views: search, add form, downloads, status bar ├── SPECS.md ├── go.mod └── README.md ``` Dependencies: `github.com/rivo/tview`, `github.com/gdamore/tcell/v2`. Prefer the standard library `net/http` and `encoding/json` for the API clients — no generated SDKs. ## 7. Configuration Format: JSON. Location: `$XDG_CONFIG_HOME/arr-tui/config.json` (fallback `~/.config/arr-tui/config.json`), overridable with `--config`. Environment variables override file values (e.g. `ARR_TUI_RADARR_APIKEY`) so secrets don't have to live in the file. Parsed with the standard library `encoding/json` (unknown fields rejected to catch typos). ```json { "radarr": { "url": "http://localhost:7878", "apikey": "...", "default_quality_profile": "HD-1080p", "default_root_folder": "/movies" }, "sonarr": { "url": "http://localhost:8989", "apikey": "...", "default_quality_profile": "HD-1080p", "default_root_folder": "/tv" }, "sabnzbd": { "url": "http://localhost:8080", "apikey": "..." }, "ui": { "refresh_seconds": 3 } } ``` The default quality profile / root folder fields are optional. The file should be created with mode `0600`; warn if it is more permissive. API keys are never logged. ## 8. Testing - Unit tests for each client using `httptest.Server` with recorded JSON fixtures. - Config parsing / validation tests. - UI logic (formatting, state) kept out of tview widgets so it can be tested without a terminal. - Manual testing against real Radarr/Sonarr/SABnzbd instances (`dev/up.sh` starts pinned Radarr/Sonarr/SABnzbd containers, see `dev/README.md`). ## 9. Milestones - [x] **M0** — Project skeleton: `go mod init`, config loading, empty tview app with tabs and status bar. - [x] **M1** — Radarr client: system status, lookup, quality profiles, root folders, add movie. - [x] **M2** — Movie search + add flow in the UI. - [x] **M3** — Sonarr client and series search + add flow. - [x] **M4** — SABnzbd client and Downloads view (queue + history) with live updates and pause/resume/delete. - [x] **M5** — Radarr/Sonarr queues merged into the Downloads view. - [x] **M6** — Interactive release search (movies, then series seasons/episodes) and grab. - [x] **M7** — Polish: help screen (`?`/F9), per-service connection indicators, README, Makefile release builds, `--version`. - [x] **M8** — Library view (movies/series, filters, text filter, monitor toggle, automatic search) and series drill-down (seasons/episodes, monitoring, search, release search). - [x] **M9** — Popup notifications, Log view (F6), context-sensitive key hints in the status bar. - [x] **M10** — Download completion notifications, remove from library, calendar view (F5; the Log moves to F6). Multiple instances per service are out of scope. - [ ] **M11+** — ideas: more library actions (edit quality profile, root folder), history of grabs per title. ## 10. Open Questions Open: none. Decided: - Go module path: `git.stinnesbeck.com/nils/arr-tui`. - One instance each of Radarr, Sonarr and SABnzbd (multi-instance is out of scope). - Minimum Go version: latest stable. - License: MIT (Nils Stinnesbeck). The tool will be published, so keep secrets out of the repo, include a `config.example.json`, and write a proper README. - Config format: JSON. - Interactive release search: in the MVP. - Downloads view: shows SABnzbd and the Radarr/Sonarr queues from the start.