Fix M3U tvg-logo URLs hardcoding localhost #1

Closed
opened 2026-02-26 23:45:44 +01:00 by timothy · 2 comments
Owner

Problem

The M3U playlist generated by ErsatzTV hardcodes http://localhost:8409 for tvg-logo URLs. When Jellyfin (running in a separate Docker container) tries to fetch these logos, localhost resolves to Jellyfin itself — not ErsatzTV. This causes channel logos to break after every Jellyfin guide refresh.

Root Cause

Two code paths generate logo URLs:

  1. ChannelPlaylist.ToM3U() (ErsatzTV.Core/Iptv/ChannelPlaylist.cs, lines 65-71) — correctly uses _scheme://{_host}{_baseUrl} from the incoming request for uploaded artwork logos (line 70), but the fallback generated logo path at line 65 also uses {_scheme}://{_host} correctly.

  2. ChannelLogoGenerator.GenerateChannelLogoUrl() (ErsatzTV.Core/Images/ChannelLogoGenerator.cs, line 82) — hardcodes http://localhost:{Settings.StreamingPort}. This static method may be used in contexts where the request host is unavailable.

Investigation Needed

  • Trace all callers of GenerateChannelLogoUrl() to understand where the hardcoded localhost actually leaks into the M3U
  • Check if the _host parameter in ChannelPlaylist is being correctly set when Jellyfin fetches the M3U via http://ersatztv:8409/iptv/channels.m3u (the Host header should be ersatztv:8409)
  • Check if IptvController correctly passes the request scheme/host through to the MediatR query
  • It's possible we're misconfiguring something rather than this being a code bug — verify the request flow end-to-end

Current Workaround

Script that downloads logos from ErsatzTV and base64-uploads them to Jellyfin's /Items/{id}/Images/Primary API. Documented in server-management repo. Tracked there as issue #171.

## Problem The M3U playlist generated by ErsatzTV hardcodes `http://localhost:8409` for `tvg-logo` URLs. When Jellyfin (running in a separate Docker container) tries to fetch these logos, `localhost` resolves to Jellyfin itself — not ErsatzTV. This causes channel logos to break after every Jellyfin guide refresh. ## Root Cause Two code paths generate logo URLs: 1. **`ChannelPlaylist.ToM3U()`** (`ErsatzTV.Core/Iptv/ChannelPlaylist.cs`, lines 65-71) — correctly uses `_scheme://{_host}{_baseUrl}` from the incoming request for uploaded artwork logos (line 70), but the fallback generated logo path at line 65 also uses `{_scheme}://{_host}` correctly. 2. **`ChannelLogoGenerator.GenerateChannelLogoUrl()`** (`ErsatzTV.Core/Images/ChannelLogoGenerator.cs`, line 82) — **hardcodes `http://localhost:{Settings.StreamingPort}`**. This static method may be used in contexts where the request host is unavailable. ## Investigation Needed - Trace all callers of `GenerateChannelLogoUrl()` to understand where the hardcoded localhost actually leaks into the M3U - Check if the `_host` parameter in `ChannelPlaylist` is being correctly set when Jellyfin fetches the M3U via `http://ersatztv:8409/iptv/channels.m3u` (the Host header should be `ersatztv:8409`) - Check if `IptvController` correctly passes the request scheme/host through to the MediatR query - It's possible we're misconfiguring something rather than this being a code bug — verify the request flow end-to-end ## Current Workaround Script that downloads logos from ErsatzTV and base64-uploads them to Jellyfin's `/Items/{id}/Images/Primary` API. Documented in `server-management` repo. Tracked there as issue #171.
timothy added the apibugjellyfinpriority: high labels 2026-03-08 23:02:37 +01:00
Author
Owner

Investigation (paused — resuming after #3/#4 CI/CD lands)

Root cause confirmed. Live test against the running ersatztv container shows the tvg-logo host is purely a function of the incoming Host header — there is no hardcoded localhost in the M3U/XMLTV path:

curl -H "Host: localhost:8409" .../iptv/channels.m3u -> tvg-logo="http://localhost:8409/iptv/logos/...jpg"
curl -H "Host: ersatztv:8409"  .../iptv/channels.m3u -> tvg-logo="http://ersatztv:8409/iptv/logos/...jpg"
  • ChannelPlaylist.ToM3U() (M3U) and GetChannelGuideHandler {RequestBase} (XMLTV) both correctly use Request.Scheme/Request.Host/Request.PathBase.
  • The hardcoded http://localhost:{StreamingPort} in ChannelLogoGenerator.GenerateChannelLogoUrl() is used only by WatermarkSelector.cs (FFmpeg overlay, in-container — correct there). It's a red herring for this issue.

So the broken localhost:8409 URLs were baked in because a client fetched ErsatzTV with Host: localhost:8409 (misconfigured Jellyfin tuner/XMLTV URL). The operational fix (use a Jellyfin-resolvable host, never localhost) belongs to server-management (#171).

Planned durable fix (this repo): ErsatzTV has no advertised/base-URL setting today — every absolute URL is hostage to the request Host. Add an optional iptv.base_url ConfigElement (no EF migration needed; ConfigElement is key/value) + a "Base URL" settings field, wired into GetChannelPlaylistHandler + GetChannelGuideHandler to override scheme/host/base when set. Cover with unit tests on ChannelPlaylist.ToM3U().

Full write-up in docs/m3u-xmltv.md. Deferring implementation until CI/CD test/prod envs (#3, #4) exist so changes can be tested safely before deploy.

### Investigation (paused — resuming after #3/#4 CI/CD lands) **Root cause confirmed.** Live test against the running `ersatztv` container shows the `tvg-logo` host is purely a function of the incoming `Host` header — there is **no hardcoded localhost** in the M3U/XMLTV path: ``` curl -H "Host: localhost:8409" .../iptv/channels.m3u -> tvg-logo="http://localhost:8409/iptv/logos/...jpg" curl -H "Host: ersatztv:8409" .../iptv/channels.m3u -> tvg-logo="http://ersatztv:8409/iptv/logos/...jpg" ``` - `ChannelPlaylist.ToM3U()` (M3U) and `GetChannelGuideHandler` `{RequestBase}` (XMLTV) both correctly use `Request.Scheme`/`Request.Host`/`Request.PathBase`. - The hardcoded `http://localhost:{StreamingPort}` in `ChannelLogoGenerator.GenerateChannelLogoUrl()` is used **only** by `WatermarkSelector.cs` (FFmpeg overlay, in-container — correct there). It's a red herring for this issue. So the broken `localhost:8409` URLs were baked in because a client fetched ErsatzTV with `Host: localhost:8409` (misconfigured Jellyfin tuner/XMLTV URL). The **operational fix** (use a Jellyfin-resolvable host, never `localhost`) belongs to `server-management` (#171). **Planned durable fix (this repo):** ErsatzTV has no advertised/base-URL setting today — every absolute URL is hostage to the request `Host`. Add an optional `iptv.base_url` ConfigElement (no EF migration needed; `ConfigElement` is key/value) + a "Base URL" settings field, wired into `GetChannelPlaylistHandler` + `GetChannelGuideHandler` to override scheme/host/base when set. Cover with unit tests on `ChannelPlaylist.ToM3U()`. Full write-up in `docs/m3u-xmltv.md`. **Deferring** implementation until CI/CD test/prod envs (#3, #4) exist so changes can be tested safely before deploy.
Author
Owner

Closing — root cause is configuration/topology, not a code bug. No code change.

Re-investigated from scratch (the earlier "confirmed" was based on one curl test and several unverified assertions). This time I looked at the actual live settings/logs/code on bumblebee (192.168.1.99), all read-only.

Key finding: the premise is stale — Jellyfin no longer tuners ErsatzTV directly

Jellyfin's livetv.xml has no ErsatzTV tuner at all. Its only Live TV source is Dispatcharr (http://dispatcharr:9191/output/m3u + /output/epg), which ingests ErsatzTV and re-serves it. That funnel didn't exist when this issue was filed (Feb 2026).

ErsatzTV ──(Dispatcharr fetches via ersatztv:8409)──▶ Dispatcharr ──▶ Jellyfin
  • channel logos   → Dispatcharr re-hosts as dispatcharr:9191   (HTTP 200 image/png ✓)
  • programme icons → passed through as ersatztv:8409 (3095×)     (HTTP 200 image/png ✓)
  • localhost references anywhere Jellyfin consumes: 0

Evidence (all read-only)

  • ErsatzTV fetched via ersatztv:8409 returns correct ersatztv:8409 URLs — no localhost. The host is purely request-driven.
  • All 44 cached guide fragments (/config/cache/channel-guide/*.xml) contain the {RequestBase} placeholder — zero baked localhost. Nothing is persisted as an absolute host.
  • Dispatcharr's M3U + EPG output (what Jellyfin actually consumes): grep -c localhost → 0 and 0. Sample logo (dispatcharr:9191) and sample programme icon (ersatztv:8409) both return HTTP 200 image/png from inside the Jellyfin container.

Root cause

Configuration/topology, not code. The historical http://localhost:8409 logo URLs were produced because a client fetched ErsatzTV with Host: localhost:8409 — ErsatzTV faithfully echoed it, and localhost from a separate Jellyfin container points at Jellyfin itself. That request path no longer exists (everything goes through Dispatcharr, fetched via ersatztv:8409). Not reproducible today.

Corrections to the prior investigation

  • ChannelLogoGenerator.GenerateChannelLogoUrl() localhost — confirmed only callers are WatermarkSelector.cs (×4), an in-container FFmpeg overlay. Red herring (as previously noted). ✔
  • Forwarded-headers theory is wrong — clearing both KnownProxies and KnownNetworks in Startup.cs sets checkKnownIps = false, which trusts all proxies, not none. And there's no proxy between Jellyfin↔ErsatzTV anyway. Not the cause.
  • Background refresh — verified it never bakes an absolute host; writes {RequestBase} only. ✔

Latent fragility (noted, not broken)

The EPG Jellyfin consumes still carries 3095 absolute ersatztv:8409 programme-icon URLs that work only because Dispatcharr fetches ErsatzTV with a resolvable host. ErsatzTV has no advertised/base-URL setting, so absolute URLs remain hostage to the request Host. Documented as an optional, not-committed hardening (iptv.base_url ConfigElement — key/value, no EF migration) in docs/m3u-xmltv.md. Deliberately not built, since the problem no longer manifests.

Files changed

  • No code change.
  • docs/m3u-xmltv.md — updated with the live evidence, the Dispatcharr topology, the resolution, and the optional-hardening note.

Disposition

Closing as resolved by topology / configuration. Operational guidance (use a Jellyfin-resolvable host for any ErsatzTV IPTV source, never localhost) lives with server-management (#171). If the latent fragility ever bites, reopen / file an enhancement for the base-URL setting.

Follow-up

The jellyfin skill doc (server-management-owned) still lists ErsatzTV as a direct Jellyfin tuner and states logos break "because M3U uses localhost:8409" — now stale. Worth correcting in server-management.

## Closing — root cause is configuration/topology, **not** a code bug. No code change. Re-investigated from scratch (the earlier "confirmed" was based on one curl test and several unverified assertions). This time I looked at the actual live settings/logs/code on **bumblebee** (192.168.1.99), all read-only. ### Key finding: the premise is stale — Jellyfin no longer tuners ErsatzTV directly Jellyfin's `livetv.xml` has **no ErsatzTV tuner at all**. Its only Live TV source is **Dispatcharr** (`http://dispatcharr:9191/output/m3u` + `/output/epg`), which ingests ErsatzTV and re-serves it. That funnel didn't exist when this issue was filed (Feb 2026). ``` ErsatzTV ──(Dispatcharr fetches via ersatztv:8409)──▶ Dispatcharr ──▶ Jellyfin • channel logos → Dispatcharr re-hosts as dispatcharr:9191 (HTTP 200 image/png ✓) • programme icons → passed through as ersatztv:8409 (3095×) (HTTP 200 image/png ✓) • localhost references anywhere Jellyfin consumes: 0 ``` ### Evidence (all read-only) - ErsatzTV fetched via `ersatztv:8409` returns **correct `ersatztv:8409` URLs** — no `localhost`. The host is purely request-driven. - All **44** cached guide fragments (`/config/cache/channel-guide/*.xml`) contain the `{RequestBase}` placeholder — **zero** baked `localhost`. Nothing is persisted as an absolute host. - Dispatcharr's M3U + EPG output (what Jellyfin actually consumes): `grep -c localhost` → **0** and **0**. Sample logo (`dispatcharr:9191`) and sample programme icon (`ersatztv:8409`) both return **HTTP 200 `image/png`** from inside the Jellyfin container. ### Root cause **Configuration/topology, not code.** The historical `http://localhost:8409` logo URLs were produced because a client fetched ErsatzTV with `Host: localhost:8409` — ErsatzTV faithfully echoed it, and `localhost` from a *separate* Jellyfin container points at Jellyfin itself. That request path no longer exists (everything goes through Dispatcharr, fetched via `ersatztv:8409`). Not reproducible today. ### Corrections to the prior investigation - **`ChannelLogoGenerator.GenerateChannelLogoUrl()` localhost** — confirmed only callers are `WatermarkSelector.cs` (×4), an in-container FFmpeg overlay. Red herring (as previously noted). ✔ - **Forwarded-headers theory is wrong** — clearing *both* `KnownProxies` and `KnownNetworks` in `Startup.cs` sets `checkKnownIps = false`, which *trusts all* proxies, not none. And there's no proxy between Jellyfin↔ErsatzTV anyway. Not the cause. - **Background refresh** — verified it never bakes an absolute host; writes `{RequestBase}` only. ✔ ### Latent fragility (noted, not broken) The EPG Jellyfin consumes still carries 3095 absolute `ersatztv:8409` programme-icon URLs that work only because Dispatcharr fetches ErsatzTV with a resolvable host. ErsatzTV has no advertised/base-URL setting, so absolute URLs remain hostage to the request `Host`. Documented as an **optional, not-committed** hardening (`iptv.base_url` ConfigElement — key/value, no EF migration) in `docs/m3u-xmltv.md`. Deliberately not built, since the problem no longer manifests. ### Files changed - No code change. - `docs/m3u-xmltv.md` — updated with the live evidence, the Dispatcharr topology, the resolution, and the optional-hardening note. ### Disposition Closing as **resolved by topology / configuration**. Operational guidance (use a Jellyfin-resolvable host for any ErsatzTV IPTV source, never `localhost`) lives with `server-management` (#171). If the latent fragility ever bites, reopen / file an enhancement for the base-URL setting. ### Follow-up The `jellyfin` skill doc (server-management-owned) still lists ErsatzTV as a direct Jellyfin tuner and states logos break "because M3U uses localhost:8409" — now stale. Worth correcting in server-management.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#1