# nstream

Adopt this skill: https://proskills.md/skills/other/gianlucamazza-nstream-skills-nstream

Page: https://proskills.md/skills/other/gianlucamazza-nstream-skills-nstream
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: skills/nstream/SKILL.md
size: 6982
upstream: https://github.com/gianlucamazza/nstream/blob/main/skills/nstream/SKILL.md

```text
---
name: nstream
description: >
  Play or cast movies and TV series headlessly via the nstream CLI. Use when the user wants to
  watch / put on / stream a specific film or series — locally on this laptop (mpv) or on the TV
  (Chromecast), and to stop/check/set-volume on the cast it started. Always non-interactive:
  drives `nstream --json` (no fzf, no TTY) and parses the JSON result. For mirroring the desktop
  or casting an arbitrary file/URL use the `skill-cast` skill instead. Trigger keywords: metti sul TV,
  guarda, riproduci, streaming film, casta il film, metti la serie, guarda l'episodio, mettimi un
  film, put on the TV, watch, play movie, stream series, cast the movie, watch the episode.
---

# nstream — headless play / cast

Drive the local `nstream` CLI in **`--json`** mode. **Contract (actions, fields, error codes,
guarantees):** repository file `docs/headless.md` — treat it as authoritative; this skill is
the agent playbook and must not contradict it.

## Before anything

- `command -v nstream` — if missing: `./install.sh` in the nstream repo (`uv tool install`).
- Confirm: `nstream --help | grep -q -- --json`. If absent, reinstall from source.

## Intent → command

Always pass `--json`. Quote the title.

| Intent | Command |
| ------ | ------- |
| Cast to TV | `nstream --json --cast "X"` |
| Local play | `nstream --json --local "X"` |
| Mirror cast (1080p SDR) | `nstream --json --mirror "X"` (not desktop mirror — use `skill-cast`) |
| Never mirror this run | `nstream --json --cast --no-mirror "X"` |
| Year | `… --year 1999` |
| Movies / series only | `… --movies` or `… --series` |
| Episode | `… --season 1 --episode 3` |
| Device | `… --device "Salotto"` |
| Subs | `… --subs` or `… --sub-lang ita` |
| Sub retime | `… --sub-offset -2.5` / `… --sub-fps 25:23.976` |
| Force dub | `… --audio-lang eng` |
| Quality | `… --quality 1080` (`4k`/`2160`, `720`, `auto`) |
| Probe (no play) | `nstream --json --probe "X"` |
| Episodes list | `nstream --json --probe "X"` without `--episode` → `action: "episodes"` |
| Continue / next | `nstream --json -c ["X"]` |
| Explain | `nstream --json --explain "X"` (add `--cast` for TV profile) |
| Browse | `nstream --json --cast --browse popolari\|nuovi\|top` |
| Lifecycle | `--stop` / `--status` / `--pause` / `--resume` / `--seek SEC` / `--volume N` (Cast 0–100% ↔ 0–1; ≠ TV OSD; MASTER/`step=null` on the Philips DMR; catt may quantize 14→13) |
| Subtitles early/late during a live cast | `nstream --json --sub-shift +1.5` (+ = later; cumulative) |
| Clear dead denylist | `nstream --json --forget-dead` |
| Clear addon circuit breakers | `nstream --json --forget-breakers` (ADR 0027; Open addons skipped without network) |

### Rules of engagement

- **Never invent stream URLs or tokens.** JSON never contains them (by design). Do not log or
  reconstruct Torrentio/debrid URLs.
- **`ok: true` means delivery started** for cast/play (ADR 0031). On live HLS that is
  PLAYING/PAUSED/BUFFERING, not a playlist GET (ADR 0044). On `cast_failed`, do not
  report success. If `cast_error` is `cast_never_started` and `notices` includes
  `cast_unconfirmed`, a library LOAD already went out — **do not recast** (that
  wipes the poster); check `--status` after ~60s. If `delivery: live` then
  `--status` shows `receiver_error`, the start lied — stop and recast; do not
  tell the user it is playing. `delivery: lan` is the ADR 0045 default for a
  remote debrid url (host Range-proxy, native video).
- **Do not silently change language or quality** on `audio_lang_unavailable` /
  `quality_unavailable` — show `available_*` and ask.
- A soft `audio_langs` preference may start a later language when the preferred dub
  needs a full remux and a direct MP4/WebM exists (ADR 0035). Read `notice` and
  `audio_lang` — that is the dub that started. `--audio-lang` still forces the dub.
- **`sources_removed` / `sources_truncated`:** do not blindly retry the same command.
- **Cast is fire-and-return by default**; use `--stop` to persist position; `--follow` only
  when the user wants the process to hold for the full runtime (JSONL events).
- **Local `--local` blocks** and opens a window — prefer `--cast` unless the user is at the
  machine.
- Series without season/episode → **S01E01**; no auto-binge in headless.
- Stream sources come from **config** (`torrentio_enabled`, `addons`, `playback_backend`) —
  no `--addon` flag. Guide the user through settings; never paste secret-bearing manifests
  into chat.

### Subtitles & audio (summary)

- Tiers: `subtitles_match` = `hash` | `audio` | `lang` (ADR 0020). Manual offset/fps win.
- `--audio-lang` is hard; ffprobe-verified when possible (`audio_verified`).
- `--quality` holds across reselects (ADR 0021). Combined with audio-lang: quality first.

### Tier-2 remux & mirror

- Dolby/DTS-only → host remux when `cast_remux` on; JSON `reencoded: true`. Prefer AAC picks.
- Large remux may auto-switch to mirror (`cast_mirror_over_remux_gb`); `--no-mirror` suppresses.
  The mirror needs Hyprland; `--doctor` says when it's off.
- `remux_infeasible` (ADR 0036): the remux would be refused (`reason`: disk/cap/ffmpeg) and no
  mirror or direct release could replace it. Don't retry unchanged — suggest `--quality 1080`,
  freeing disk, or `--local`.
- `audio_verified: false` with `audio_lang: null` after a cast = the remux failed mid-way and
  the file went out as-is: warn the user the audio may be missing.
- Remux/file via catt **≥0.13.2** (no castbridge): TV should show title + Cinemeta
  poster when `catt.api` is importable (ADR 0050). CLI-only hosts still get the
  title. catt 0.13.0/0.13.1 stay on the pre-0050 argv. Not a remux-720 issue.
- Details: `docs/user/cast.md`, `docs/headless.md`.

### Parsing

`notices` (every result/error) carries what stderr said; act on coded ones (`p2p_blocked`,
`p2p_no_vpn`, `audio_lang_absent`, `remux_failed`, `subs_not_delivered`) and relay the rest.

Read `ok`. On success surface `title`, `action`, `device`, short `stream` summary, and when
relevant: `quality`, `available_resolutions`, `audio_lang` / `available_audio` /
`audio_verified`, `duration_verified`, `reencoded`, `selection` (`exact`|`year`|`first`).
`stream.codec_source` is `probed` (ffprobe already ran) or `release_name` (claim;
the name can lie). Prefer `probed` when both appear across a session.

Full error table and recovery: **`docs/headless.md`** (codes include `no_result`,
`no_stream_sources`, `no_streams`, `id_untranslated`, `no_playable_stream`, `cast_failed`,
`sources_removed`, `sources_truncated`, `video_codec_unsupported`, `remux_infeasible`,
`audio_lang_unavailable`, `quality_unavailable`, `episode_not_found`, `series_completed`,
`device_not_found`, `network`, `usage`, `config`).

## Related repo docs

- Contract: `docs/headless.md`
- Ranking: `docs/selection.md`
- Config: `docs/user/config.md`
- Troubleshooting: `docs/user/troubleshooting.md`
```

## File: README.md
upstream: https://github.com/gianlucamazza/nstream/blob/main/README.md

````text
# nstream

Native, terminal-first Stremio alternative. No Electron, no embedded browser, no Node
server — Python 3.13+ **stdlib only**, driving `fzf`, `mpv`, and optional cast/P2P CLIs over
Stremio addon HTTP APIs.

**Docs hub:** [docs/README.md](docs/README.md)

## What it does

1. **Search / browse** titles (Cinemeta and other catalog addons).
2. **Pick** title and episode in a fzf TUI (or headless `--json` for scripts/agents).
3. **Optional subtitles** (OpenSubtitles v3 + alignment; ADR 0020).
4. **Fetch streams** from Torrentio and/or extra manifests (Comet, MediaFusion, … — ADR 0024).
5. **Rank & filter** for your GPU or Chromecast (hardware-aware + cast-aware).
6. **Play** in mpv and/or **cast** (castbridge / catt / remux / mirror).
7. **Resume** and continue-watching; series binge with next-episode overlay.

Playback backends: **local P2P** (TorrServer, default), **debrid** (eight Torrentio providers),
**auto** hybrid, or **native** provider API (TorBox / Premiumize). See
[docs/user/config.md](docs/user/config.md).

## Why

The Stremio Flatpak beta (Rust shell) crashes on Wayland/Hyprland (ozone-X11 `Missing X server`);
the Qt build is heavy. nstream reuses the Stremio addon ecosystem with a fraction of the
footprint and native mpv / Cast integration.

## Requirements

| | Packages |
| - | -------- |
| **Required** | `python3` ≥ 3.13 (zero third-party deps), `mpv`, `fzf` |
| **Strongly recommended** | `ffmpeg`/`ffprobe` (tracks, remux), `foot` (desktop launcher) |
| **Optional** | `catt` (cast discovery/fallback), `chafa` (posters), `vainfo`/`libva-utils` (HW ranking), TorrServer (local P2P) |
| **Optional native cast** | castbridge (`$CASTBRIDGE_BIN`), mirror sender (`$CAST_MIRROR_BIN`) — openscreen-fork builds; fallback without them |

Install/dev tooling: `uv`.

## Install

| Method | Command | Notes |
| ------ | ------- | ----- |
| From source (dev) | `./install.sh` | `uv tool install` → `~/.local/bin/nstream` |
| PyPI | `pipx install nstream` | or `uv tool install nstream` |
| Git | `uv tool install git+https://github.com/gianlucamazza/nstream` | tagged releases too: `…@vX.Y.Z` |
| AUR | `yay -S nstream` | source package |
| Arch (local) | `cd packaging && makepkg -si` | from the GitHub source tarball |

nstream does not host, index, or distribute video files. Catalogs, stream addons, and
debrid backends are configured by the user. Use only sources you are entitled to access.

The Arch package installs binaries + desktop entry + `config.example.json` under
`/usr/share/nstream/`; it does **not** write `$HOME`. `./install.sh` bootstraps
`~/.config/nstream/config.json` from the example when missing.

## Quickstart

```sh
# 1) Config (defaults = local P2P; no paid service)
#    For debrid: set playback_backend to "debrid" and put the key in torrentio_base —
#    see docs/user/config.md
nstream --settings

# 2) Play
nstream "the matrix"          # TUI search → Enter plays best stream
nstream --cast "dune"         # Chromecast
nstream --json --cast "dune"  # headless JSON for scripts/agents
```

Full config tables: [docs/user/config.md](docs/user/config.md).  
TUI keys: [docs/user/tui.md](docs/user/tui.md).  
Cast guide: [docs/user/cast.md](docs/user/cast.md).  
Headless contract: [docs/headless.md](docs/headless.md).

## Develop

```sh
uvx ruff check . && uvx ruff format --check .
uvx ty check
uv run python -m pytest          # not bare pytest — see CONTRIBUTING.md
uv run nstream "the matrix"
```

Contributor guide: [CONTRIBUTING.md](CONTRIBUTING.md).  
Module map: [docs/architecture.md](docs/architecture.md).  
Stream ranking: [docs/selection.md](docs/selection.md).  
Decisions: [docs/adr/](docs/adr/README.md).

## Usage

```sh
# Interactive
nstream "the matrix"              # search; Enter = auto-play; Tab = manual
nstream                           # continue-watching or prompt
nstream --cast "dune"             # cast (castbridge, else catt)
nstream --mirror "dune"           # realtime mirror (1080p SDR)
nstream --local "dune"            # force mpv when prefer_cast is on
nstream --play "dune"             # force auto-pick
nstream --subs / --sub-menu / --sub-lang eng …
nstream --sub-offset -2.5 …       # constant subtitle shift (seconds)
nstream --sub-fps 25:23.976 …     # framerate drift correction
nstream --browse [popolari|nuovi|top]
nstream --movies | --series …
nstream -c / --continue           # resume from history
nstream --no-history              # do not read/write watch history this run
nstream --no-autoplay             # skip next-episode overlay
nstream --settings
nstream --explain "dune"          # ranking dump, no play
nstream --quality 1080 "matrix"   # hard resolution filter (aliases: 4k, 720, auto)
nstream --forget-dead             # clear proven-gone denylist (ADR 0025)
nstream --forget-breakers         # clear per-addon circuit breakers (ADR 0027)
nstream --debrid-test INFOHASH    # native debrid diagnostics
nstream --debug / --version

# Headless (--json): one JSON object on stdout — see docs/headless.md
nstream --json --cast --device TV "dune"
nstream --json --cast --follow …          # JSONL until end
nstream --json --local "dune"
nstream --json --probe "dune"             # languages / resolutions (no play)
nstream --json --year 1999 --movies "X"
nstream --json --season 1 --episode 3 "Show"
nstream --json --audio-lang eng --quality 4k --cast "…"
nstream --json --stop | --status | --pause | --resume
nstream --json --seek 1250 | --volume 35
nstream --json --no-mirror --cast "…"
nstream --json -c "Show"                  # continue / next episode
```

Launcher: app menu → home (continue · search · watchlist · Film · Serie · settings).  
Cheatsheet: [docs/user/tui.md](docs/user/tui.md).

## Logging & security

- Log: `$XDG_STATE_HOME/nstream/nstream.log` (rotating); `--debug` / `NSTREAM_DEBUG=1` → stderr.
- Dead sources: `$XDG_STATE_HOME/nstream/dead-sources.json` (ADR 0025).
- Debrid token only in `config.json` (`chmod 600`). Redacting formatter scrubs tokens from
  **every** log line including tracebacks. nstream never prints stream URLs.
- mpv gets `--no-resume-playback` (nstream owns resume); URLs stay out of `watch_later`.

Diagnostics detail: [docs/user/troubleshooting.md](docs/user/troubleshooting.md).

## Documentation map

| Doc | Role |
| --- | ---- |
| [docs/README.md](docs/README.md) | Audience hub |
| [docs/user/config.md](docs/user/config.md) | Every config key |
| [docs/user/cast.md](docs/user/cast.md) | Chromecast delivery |
| [docs/user/tui.md](docs/user/tui.md) | Menus & keys |
| [docs/user/troubleshooting.md](docs/user/troubleshooting.md) | Failures & recovery |
| [docs/headless.md](docs/headless.md) | `--json` contract |
| [docs/selection.md](docs/selection.md) | How streams are chosen |
| [docs/architecture.md](docs/architecture.md) | Where code lives |
| [docs/adr/](docs/adr/README.md) | Why (ADRs) |
| [docs/roadmap.md](docs/roadmap.md) | Non-goals & Proposed ADRs |
| [CONTRIBUTING.md](CONTRIBUTING.md) | Dev workflow |
| [CHANGELOG.md](CHANGELOG.md) | Release notes |

## License

MIT — see [LICENSE](LICENSE).
````
