docs: close #1 — M3U localhost is config/topology, not a code bug
Re-investigated ersatztv#1 against the live stack: ErsatzTV emits
request-host-driven URLs (44 cached guide fragments use {RequestBase},
zero baked localhost), and Jellyfin no longer tuners ErsatzTV directly —
it funnels through Dispatcharr. The historical localhost came from a
client fetching with Host: localhost:8409, a path that no longer exists.
Document the live topology + evidence + resolution; reframe the optional
base-URL setting as not-built; note the latent fragility. Remove the now
spent handoff doc.
refs #1
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
# Handoff — ersatztv#1: M3U `tvg-logo` (and channel-logo) URLs hardcoding localhost
|
||||
|
||||
**How to use:** start a fresh session and say something like
|
||||
*"Read `docs/handoffs/m3u-tvg-logo-fix.md` and execute ersatztv#1"* (optionally *"with ultracode"* /
|
||||
*"use a workflow"*). Read **ersatztv#1** in full (Gitea, `timothy/ersatztv`) before acting.
|
||||
|
||||
This is the first **feature/bug** task after the engineering-foundations batch (all 8 done: CPM, vuln
|
||||
deps, analyzers, arch tests, golden tests, migration checks, IPTV E2E, contributors guide). #1 is
|
||||
`priority: high` (Jellyfin channel logos break after every guide refresh) and was deliberately
|
||||
**unblocked + protected** by that work.
|
||||
|
||||
## ⚠️ Investigation first — the issue's stated root cause is partly a RED HERRING
|
||||
|
||||
A quick trace (do not skip — it'll save you from the wrong rabbit hole):
|
||||
|
||||
- `ChannelLogoGenerator.GenerateChannelLogoUrl()` (`ErsatzTV.Core/Images/ChannelLogoGenerator.cs:81`)
|
||||
**does** hardcode `http://localhost:{StreamingPort}…`. **But its only callers are in
|
||||
`ErsatzTV.Core/FFmpeg/WatermarkSelector.cs`** (4×) — i.e. it's the URL **ffmpeg** fetches to draw the
|
||||
channel logo as a *watermark*, and ffmpeg runs **inside the ErsatzTV container**, where
|
||||
`localhost:8409` correctly reaches ErsatzTV. So this `localhost` is **not** the M3U bug — leave it
|
||||
(or confirm before touching).
|
||||
- The **M3U** `tvg-logo` is built in `ChannelPlaylist.ToM3U()`
|
||||
(`ErsatzTV.Core/Iptv/ChannelPlaylist.cs:65,70`) from `{_scheme}://{_host}{_baseUrl}` — i.e. the
|
||||
**request** host. That's already "correct" given a correct request host.
|
||||
- The **XMLTV** guide (`GetChannelGuideHandler`) and artwork (`RefreshChannelDataHandler:~1114`) use a
|
||||
**`{RequestBase}` placeholder** substituted at request time with `{Scheme}://{Host}{BaseUrl}` — also
|
||||
request-host based.
|
||||
- `Startup` **does** configure `ForwardedHeaders.All` (`Startup.cs:126`) + `app.UseForwardedHeaders()`
|
||||
(`:534`), and `ETV_BASE_URL` → `UsePathBase` (`:505`).
|
||||
|
||||
**So: where does `localhost` actually reach Jellyfin?** Most likely one of:
|
||||
1. **Request flow / proxy**: Jellyfin (or a reverse proxy) fetches the M3U via a host that resolves to
|
||||
`localhost` from ErsatzTV's perspective, **or** `UseForwardedHeaders()` runs too late / the proxy
|
||||
isn't sending `X-Forwarded-Host`, so `Request.Host` ends up `localhost:8409`. Check middleware
|
||||
**ordering** (forwarded-headers must run before anything reading `Request.Host`) and what host
|
||||
ErsatzTV actually sees.
|
||||
2. **A cached value**: `channels.xml` / per-channel fragments are generated by `RefreshChannelList`/
|
||||
`RefreshChannelData` (background, **no** request) — confirm every host-bearing field there is a
|
||||
`{RequestBase}` placeholder, not a baked absolute URL. A baked `localhost` there would leak into the
|
||||
guide regardless of the request.
|
||||
3. **Genuine misconfiguration** (the issue flags this): the Jellyfin-side M3U URL points at `localhost`.
|
||||
|
||||
**Reproduce first.** You can run the real image on bumblebee (Docker host, `ssh timothy@192.168.1.99`,
|
||||
registry `192.168.1.95:3000/timothy/ersatztv:latest`) and curl `/iptv/channels.m3u` +
|
||||
`/iptv/xmltv.xml` with different `Host`/`X-Forwarded-*` headers to see exactly when `localhost`
|
||||
appears. (This is how #16's E2E was validated.)
|
||||
|
||||
## Likely fix shapes (decide after repro)
|
||||
- If it's forwarded-headers ordering/config → fix middleware order / `KnownProxies`/`KnownNetworks`,
|
||||
or honor an explicit configured public base URL.
|
||||
- If a background-generated cache bakes a host → switch it to the `{RequestBase}` placeholder pattern
|
||||
(copy `GetChannelGuideHandler.cs:51` / `RefreshChannelDataHandler.cs:~1114`).
|
||||
- If purely Jellyfin/proxy config → document it (and this may belong in server-management, not here).
|
||||
|
||||
## Regression net (already in place — use it)
|
||||
- **M3U golden tests**: `ErsatzTV.Core.Tests/Iptv/ChannelPlaylistGoldenTests.cs`. If your fix changes
|
||||
`ToM3U` output, the goldens **will** fail — review the diff, then regenerate intentionally with
|
||||
`ETV_UPDATE_GOLDENS=1` (or the `[Explicit] Regenerate_goldens` test) and commit. (ersatztv#11)
|
||||
- **Container E2E**: the smoke step asserts `/iptv/channels.m3u`→`#EXTM3U` and `/iptv/xmltv.xml`→`<tv`
|
||||
on the built image (main/tag builds). (ersatztv#16)
|
||||
- The **XMLTV icon URLs are not golden-tested yet** (that's ersatztv#28). If #1 touches the guide's
|
||||
logo/icon URLs, consider adding an XMLTV golden as part of this work (or at least a focused test),
|
||||
since the M3U goldens won't cover it.
|
||||
|
||||
## Process (non-negotiable — see CLAUDE.md + `docs/contributing.md`)
|
||||
- **Root cause**: document WHY (this is a bug fix). If it's config not code, say so and close with that.
|
||||
- Follow established patterns (`docs/contributing.md`); diverge only with a stated reason.
|
||||
- **One branch = one PR.** PR runs `test` + `migrations` (both now **required** to merge); merge to
|
||||
`main` runs `test`+`migrations`+`build`+smoke/E2E. Verify green before closing.
|
||||
- Adversarial self-review of the diff before closing. Task Completion Protocol / `/done 1`.
|
||||
- CI poll: `curl -u timothy:ded89Lm4 …/api/v1/repos/timothy/ersatztv/actions/tasks` (jobs by name).
|
||||
|
||||
## Repo state at handoff
|
||||
- All foundations merged to `main`; `main` requires `Build & test (.NET)` **and** `EF migration
|
||||
integrity (SQLite + MySql)` to merge a PR. Image `build` now `needs: [test, migrations]`.
|
||||
- Versioning is CalVer `vYY.N.P`; a bug-fix release for #1 would be `v26.4.0` (first release with app
|
||||
changes) — but only tag when the user asks.
|
||||
- `ssh-mcp`/`docker-mcp` target `192.168.1.99` (bumblebee); if they fail "auth", their `.mcp.json`
|
||||
needs `--key=~/.ssh/id_rsa` + a client restart. Plain Bash `ssh timothy@192.168.1.99` works.
|
||||
+36
-9
@@ -49,9 +49,11 @@ XMLTV data is pre-generated from Scriban templates (`ErsatzTV/Resources/Template
|
||||
|
||||
## Jellyfin Integration
|
||||
|
||||
### Tuner Setup
|
||||
> **Current homelab topology (2026-06):** Jellyfin does **not** tuner ErsatzTV directly — it funnels ErsatzTV through **Dispatcharr** (`dispatcharr:9191`), which ingests ErsatzTV and re-serves the channels/EPG. The direct-tuner setup below is the generic reference for pointing *any* tuner at ErsatzTV; see "Resolution (2026-06-27)" under the Logo URL Issue for the live pipeline.
|
||||
|
||||
In Jellyfin, add an IPTV tuner pointing to:
|
||||
### Tuner Setup (direct — reference)
|
||||
|
||||
To point an IPTV tuner directly at ErsatzTV:
|
||||
```
|
||||
http://ersatztv:8409/iptv/channels.m3u
|
||||
```
|
||||
@@ -96,10 +98,9 @@ curl -H "Host: ersatztv:8409" .../iptv/channels.m3u -> tvg-logo="http://ersat
|
||||
|
||||
So the `http://localhost:8409` URLs that broke in Jellyfin were baked in because a client fetched ErsatzTV using `Host: localhost:8409` (a misconfigured tuner/XMLTV URL in Jellyfin's Live TV settings, or a proxy passing that Host). The original issue framing ("hardcoded localhost in code") is a red herring — see Investigation Findings above.
|
||||
|
||||
This is therefore **not a code bug in the M3U/XMLTV generators**. There are two complementary fixes:
|
||||
This is therefore **not a code bug in the M3U/XMLTV generators**. The fix is operational, not code:
|
||||
|
||||
1. **Operational (server-management):** Jellyfin's M3U tuner URL and XMLTV listing URL must use a host that is resolvable *and* correct from Jellyfin's network context (e.g. `http://ersatztv:8409`), never `localhost`. Owned by `server-management` (related: its issue #171).
|
||||
2. **Durable hardening (ersatztv, deferred — Gitea #1):** add an optional advertised **Base URL** override so generated URLs stop depending on the fragile `Host` header. See below.
|
||||
- **Operational (server-management):** Jellyfin's IPTV source must reach ErsatzTV via a host that is resolvable *and* correct from Jellyfin's network context (e.g. `http://ersatztv:8409`), never `localhost`. Owned by `server-management` (related: its issue #171).
|
||||
|
||||
### Architecture: absolute-URL generation (relevant for future work)
|
||||
|
||||
@@ -115,10 +116,36 @@ Implications for future work:
|
||||
- Any client that connects via a different host (localhost, a reverse-proxy alias, split-DNS name) gets that host echoed back into stream + logo + artwork URLs. This affects the planned REST API (#2) and any reverse-proxy fronting (server-management) too.
|
||||
- **Settings are stored in the `ConfigElement` table as simple key/value** (`ConfigElementKey` in `ErsatzTV.Core/Domain/ConfigElementKey.cs`; read/write via `IConfigElementRepository.GetValue<T>` / upsert). Adding a new setting needs **no EF migration**.
|
||||
|
||||
### Planned fix for #1 (deferred until CI/CD #3/#4 land)
|
||||
### Resolution (2026-06-27) — Gitea #1 closed as config/topology, no code change
|
||||
|
||||
Add an optional `iptv.base_url` ConfigElement + a "Base URL" field on the settings page. When set, `GetChannelPlaylistHandler` and `GetChannelGuideHandler` parse it into scheme/host/base and use it instead of the request values; when blank, behaviour is unchanged (request-derived). Cover with unit tests on `ChannelPlaylist.ToM3U()` (pure class — easy to assert logo/stream hosts) plus the override-resolution logic. Run the existing suite before and after to guard against regressions.
|
||||
A second live investigation (against the running stack on **bumblebee**, 192.168.1.99) confirmed the original symptom is **not reproducible in the current architecture**, because the topology changed since #1 was filed (Feb 2026):
|
||||
|
||||
### Current Workaround
|
||||
**Jellyfin no longer tuners ErsatzTV directly.** Per Jellyfin's `livetv.xml`, its only Live TV source is **Dispatcharr** (`http://dispatcharr:9191/output/m3u` + `/output/epg`). ErsatzTV is funneled *through* Dispatcharr:
|
||||
|
||||
A script downloads logos from ErsatzTV and base64-uploads them directly to Jellyfin's `/Items/{id}/Images/Primary` API, bypassing the M3U logo URLs entirely. Documented in `server-management` repo (issue #171).
|
||||
```
|
||||
ErsatzTV ──(Dispatcharr fetches via ersatztv:8409)──▶ Dispatcharr ──▶ Jellyfin
|
||||
• channel logos → Dispatcharr re-hosts as http://dispatcharr:9191/... (HTTP 200 image/png ✓)
|
||||
• programme icons → passed through as http://ersatztv:8409/... (3095 of them, HTTP 200 image/png ✓)
|
||||
• localhost references anywhere Jellyfin consumes: 0
|
||||
```
|
||||
|
||||
Evidence gathered (all read-only):
|
||||
- ErsatzTV fetched via `ersatztv:8409` returns correct `ersatztv:8409` URLs (no `localhost`).
|
||||
- All 44 cached guide fragments under `/config/cache/channel-guide/*.xml` contain the `{RequestBase}` placeholder — **zero** baked `localhost`. Nothing is persisted absolute.
|
||||
- Dispatcharr's M3U + EPG output contain **0** `localhost`; sample logo and icon both fetch HTTP 200 `image/png` from inside the Jellyfin container.
|
||||
|
||||
**Root cause = configuration/topology, not code.** The historical `localhost:8409` came from a client fetching ErsatzTV with `Host: localhost:8409`; that path no longer exists. Closed without a code change.
|
||||
|
||||
> Note — the forwarded-headers theory (`KnownProxies.Clear()` in `Startup.cs` making `X-Forwarded-*` be *ignored*) is **incorrect**: clearing *both* `KnownProxies` and `KnownNetworks` sets `checkKnownIps = false`, which *trusts all* proxies, not none. And there is no proxy between Jellyfin and ErsatzTV. Red herring.
|
||||
|
||||
### Latent fragility (not currently broken)
|
||||
|
||||
The EPG Jellyfin consumes still contains 3095 absolute `http://ersatztv:8409/...` programme-icon URLs. They work **only** because Dispatcharr fetches ErsatzTV with a Jellyfin-resolvable host, and Jellyfin shares the Docker network. ErsatzTV still has no advertised/base-URL setting — every absolute URL is hostage to the request `Host`. If a client ever fetches ErsatzTV with a host that downstream consumers can't resolve, the same class of breakage returns.
|
||||
|
||||
### Optional future hardening (NOT committed)
|
||||
|
||||
If that fragility is ever worth removing: add an optional `iptv.base_url` ConfigElement (key/value, **no EF migration**) + a "Base URL" settings field; when set, `GetChannelPlaylistHandler` / `GetChannelGuideHandler` parse it into scheme/host/base instead of the request values; when blank, behaviour is unchanged. Cover with unit tests on `ChannelPlaylist.ToM3U()`. Deliberately **not** built for #1 — the problem no longer manifests, so this stays a documented option rather than committed work.
|
||||
|
||||
### Historical Workaround (pre-Dispatcharr)
|
||||
|
||||
Before the Dispatcharr funnel, a script downloaded logos from ErsatzTV and base64-uploaded them directly to Jellyfin's `/Items/{id}/Images/Primary` API, bypassing the M3U logo URLs. Documented in `server-management` (issue #171). No longer needed for the current pipeline.
|
||||
|
||||
Reference in New Issue
Block a user