Dashboard Live uptimes + Recent runs from stream_sessions; overview.recent_sessions. WireGuard netns resolv.conf + missing-deps WARN. Support donations card. Agent start/stop/update, job_backoff default off, wvkey ensure/venv, phonecap retries, modhost YAML enrich, DRM SetCredentials requires keys.
10 KiB
Control plane and agent
Two long-running pieces: streamd serve holds the state and the dashboard, streamd agent run keeps credentials fresh using real phones.
New to Linux servers? Start with the copy-paste guide: streamd-server-setup.md (download, chmod, add MPD streams, screen/systemd so it survives closing the terminal).
streamd serve
./bin/streamd serve --bind 127.0.0.1:8083 --data .cache/streamd
| Flag | Default | Purpose |
|---|---|---|
--bind |
127.0.0.1:8083 |
listen address (loopback). Non-loopback logs a warning |
--data |
auto (see below) | SQLite, work dirs, HLS output, logs. If omitted: $STREAMD_DATA, else existing ./.cache/streamd, else existing <install>/.cache/streamd, else create ./.cache/streamd |
--token |
$STREAMD_TOKEN |
legacy admin API key (prefer dashboard API keys) |
--admin-user / --admin-pass |
— | create first admin on empty install |
--nre |
$NRE_PATH, bin/, PATH, auto-download |
N_m3u8DL-RE |
--ffmpeg |
$FFMPEG_PATH, bin/, PATH, auto-download |
ffmpeg |
--mp4decrypt |
$MP4DECRYPT_PATH, bin/, PATH, auto-download |
Bento4 mp4decrypt |
--bin-dir |
<repo>/bin |
where auto-downloaded tools are installed |
--skip-deps |
off | do not download missing tools |
On start, serve resolves media tools and downloads ffmpeg (BtbN static),
N_m3u8DL-RE (v0.6.0-beta), and mp4decrypt (Bento4) into bin/ when missing.
macOS ffmpeg is not auto-fetched — install with brew install ffmpeg.
Open http://127.0.0.1:8083 and sign in (or complete first-run setup). Auth is
session cookies for the dashboard and API keys (Settings → API keys) for
agents/scripts. Roles: admin, operator, viewer. GET /api/health stays
anonymous for liveness; stream list and mutations need a principal. Legacy
--token / STREAMD_TOKEN still works as an admin key and prints a migration
warning.
Keys, proxy, and egress
- MPD is required to start. Keys are optional (clear streams such as BBC).
- Per-stream
proxy(socks5://127.0.0.1:1080orhttp://…) is passed to N_m3u8DL-RE as--custom-proxy. The local MPD rewrite fetch uses the same proxy. Outbound HLS you serve is unaffected. - Per-stream
egressnames a profile from Settings → Egress (WireGuard netns + local SOCKS on Linux, or a plain SOCKS URL profile). Resolve order: explicitproxy→ named egress SOCKS → direct. Full-tunnel WG stays insidestreamd-<name>netns so SSH/UI keep the host route. On Linux Up, streamd writes/etc/netns/streamd-<name>/resolv.conf(public DNS) so SOCKS hostname lookups work when the host uses127.0.0.53. See streamd-server-setup.md §7. - The dashboard Live uptimes and Recent runs cards use
stream_runtime.uptime_splus durablestream_sessionsrows (opened when NRE starts, closed on stop / NRE exit).GET /api/overviewincludesrecent_sessions. - Variants (FHD / HD / SD): FHD is the source copy at
/hls/<name>/index.m3u8. Enabling HD/SD starts live ffmpeg ladders at/hls/<name>-hd/and/hls/<name>-sd/. The dashboard Copy button copies the absolute m3u8 URL without opening a player.
API
| Route | Purpose |
|---|---|
GET /api/health |
liveness + uptime + deps paths |
GET /api/overview |
dashboard totals, upcoming, recent events + sessions |
GET /api/apps |
modules under the panel store (--data/modules), channels, rewriters |
GET /api/modules |
list panel modules with yaml/package hashes + arches |
GET /api/modules/:name |
metadata; ?include=yaml returns YAML (operator+) |
GET /api/modules/:name/yaml |
raw module.yaml (operator / agent pull) |
GET /api/modules/:name/package |
download package.zip (operator / agent pull) |
PUT /api/modules/:name |
save module.yaml (operator; JSON {"yaml":…} or raw YAML) |
POST /api/modules/upload |
multipart zip upload (file + optional name) |
DELETE /api/modules/:name |
remove a module from the panel store |
GET /api/egress |
list egress profiles (viewer+) |
POST /api/egress |
create profile (admin) |
GET /api/egress/:name |
profile status |
PUT /api/egress/:name |
update enabled/kind/socks_url/conf (admin) |
PUT /api/egress/:name/conf |
upload WireGuard conf (admin) |
POST /api/egress/:name/up|down|test |
bring tunnel up/down / probe egress IP |
DELETE /api/egress/:name |
remove profile (admin) |
GET /api/streams |
all streams with runtime state |
POST /api/streams |
create |
PATCH /api/streams/:id |
update (incl. egress) |
DELETE /api/streams/:id |
remove |
POST /api/streams/:id/start|stop|restart |
desired state |
POST /api/streams/:id/capture |
ask connected agents to refresh credentials now |
POST /api/streams/:id/credentials |
push a fresh manifest + keys |
POST /api/streams/:id/claim |
agent claims the stream |
The dashboard's app and channel pickers are filled from /api/apps, so they reflect
whatever modules the binary was built with. Nothing about a provider is hardcoded in
the UI or the schema.
Creating a stream
./bin/streamd catalog --app tg4 --channel ioi --keys --wvd data/device.wvd --json > s.json
curl -X POST http://127.0.0.1:8083/api/streams \
-H 'Authorization: Bearer SECRET' -H 'Content-Type: application/json' \
--data @s.json
A stream created without app, video_select, audio_select or rewriter keeps
those empty on purpose. They are resolved when the stream starts:
stored row -> the stream's app module (app.StreamDefaults) -> neutral defaults
So a module decides its own downloader settings, an operator override in the row still wins, and an unknown app gets something harmless rather than another provider's preferences.
Refreshing credentials
curl -X POST http://127.0.0.1:8083/api/streams/1/credentials \
-H 'Authorization: Bearer SECRET' -H 'Content-Type: application/json' \
-d '{"mpd":"https://...","key":"KID:KEY\nKID:KEY","headers_json":"{}"}'
This is exactly what the agent does after a successful capture.
Manifest rewriting
If a stream's rewriter names a registered rewriter and the manifest is not HLS,
the supervisor starts a local rewrite server and points the downloader at it:
stream rewriter="rte" -> mpd.Lookup("rte") -> http://127.0.0.1:PORT/manifest.mpd
The log line is stream X: rewritten MPD http://127.0.0.1:…. Streamd never imports
a provider package to do this — the module registered the rewriter under that name
at init time.
streamd agent run
# Prefer an operator API key from the streamd dashboard (Settings → API keys).
export STREAMD_API_KEY=ndk_…
# or: export STREAMD_TOKEN=… (legacy alias)
./bin/streamd agent run --config apps/agent/agent.yaml
What it does, in a loop:
- poll streamd for enabled streams that are down or missing credentials
- enqueue a job in a durable SQLite queue
- claim a free ADB device that already has the app installed
- run a phone capture through the stream's app module
POST /api/streams/:id/credentials- force-stop the app and release the device
It never installs apps and never runs a downloader. A websocket heartbeat keeps its
claims alive, so claims expire automatically if the agent dies. Streamd can also
push a capture immediately (POST /api/streams/:id/capture or the dashboard
Refresh keys button).
Subcommands
./bin/streamd agent devices # phones it can use
./bin/streamd agent status # recent jobs
./bin/streamd agent enqueue --stream tg4-ioi --reason manual
./bin/streamd agent cancel --job 3
Config
apps/agent/agent.yaml:
streamd_url: http://127.0.0.1:8083
# Prefer an API key created in the streamd dashboard (operator role):
# api_key: ndk_…
# token: … # alias for api_key (legacy name)
# Or set STREAMD_API_KEY / STREAMD_TOKEN in the environment.
poll_interval_sec: 30
data_dir: .cache/agent
workers: 1
max_attempts: 5
capture_wait_sec: 180
# devices: [SERIAL1, SERIAL2] # empty = any authorised device
# python: path to python for wvkey.py
# wvd: data/device.wvd
# user_agent: ""
# agent_id: defaults to hostname
Modules on the panel
The dashboard Modules page is the source of truth for provider packages:
- Upload a release zip (
bbc.zip,c4.zip, … frommodules-v*tags) via drag-and-drop. - Edit
module.yamlin the panel (fill secrets after upload — release zips ship the publish template). - Agents with
sync_modules: truepullpackage.zip+ YAML into<data_dir>/modules/(default). YAML-only edits skip re-downloading the zip.
Panel storage is under --data/modules/ (not the repo modules/ tree). /api/apps channel pickers read that store. Local streamd capture without an agent still uses repo modules/ unless --modules-dir / STREAMD_MODULES_DIR points at a synced cache.
wvd must be set (here or on the phone capture) or key fetches fail.
Running both locally
# terminal 1
./bin/streamd serve --bind 127.0.0.1:8083 --data .cache/streamd
# terminal 2 — after creating an operator API key in the dashboard
export STREAMD_API_KEY=ndk_…
./bin/streamd agent run --config apps/agent/agent.yaml
Then create a stream, leave Enabled checked (required for on-demand wake), and watch the agent pick it up:
./bin/streamd agent status
External tools
The media supervisor shells out to three binaries. Put them on PATH, in bin/,
or name them with flags/env:
| Tool | Flag | Env |
|---|---|---|
| N_m3u8DL-RE | --nre |
NRE_PATH, N_M3U8DL_RE |
| ffmpeg | --ffmpeg |
FFMPEG_PATH, FFMPEG |
| mp4decrypt | --mp4decrypt |
MP4DECRYPT_PATH, MP4DECRYPT |
Streams can be created, claimed and credentialed without any of them; only actually pulling media needs them. The supervisor is the least exercised part of the system — treat its health reporting as control-plane bookkeeping.
Data
.cache/streamd/
streamd.db SQLite: streams, runtime, claims
work/<name>/ downloader scratch + keys.txt
www/<name>/ HLS output
logs/ per-stream downloader + ffmpeg logs
.cache/agent/
queue.db durable job queue
Back up streamd.db before upgrading — schema defaults change between versions.