IPTV relay: provider traffic through PIA, by country
Draft, 2026-09-27. Nothing here is built yet; two decisions are still open (see Open decisions).
Why #
- trex's country DNS servers (
es.uhdp.top,gr.uhdp.top,it.uhdp.top) turn every request from home away with a 403. trex's welcome mail says to use them "with VPN". From a Spanish exit they'd likely answer. - trex recommends a VPN "for better stability and performance".
- Some channels may play better (or at all) from their own country.
The apps play video through AVPlayer, which can't be pointed at a proxy per request. So video has to come to the Apple TV from something that already fetched it through the VPN: a relay on the home network.
The shape #
┌─▶ gluetun-es (PIA Spain) :8888 ─▶ es.uhdp.top, Spanish channels
Apple TV ─▶ iptv-relay ───┼─▶ gluetun-uk (PIA UK) :8888 ─▶ UK channels
└─▶ direct ────────────────────────▶ everything else
- gluetun, one container per country: an off-the-shelf VPN client with
PIA built in (
VPN_SERVICE_PROVIDER=private internet access,SERVER_REGIONS=Spain), health check and reconnects included. Each runs its HTTP proxy (HTTPPROXY=on, port 8888) for the relay to send requests through. Nothing else on the network goes through the VPN. - iptv-relay: a small Go service (~300 lines) we write. It answers the apps' Xtream requests and, per request, fetches from the provider directly or through one country's gluetun.
- Hosted in the homelab with a LAN hostname, e.g.
iptv.house.48farragut.com.
What the relay does #
| Request from the app | Relay |
|---|---|
player_api.php (login, categories, guides, connection counts) |
Forwards it as is. Your username and password pass through; the relay keeps no credentials. |
/live/…/123.m3u8 (HLS) |
Fetches it, follows the provider's redirect to its token server, and rewrites every segment address in the playlist to point back at the relay, so segments take the same route. |
/live/…/123.ts, /timeshift/…, /movie/…, /series/… |
Streams them through as they come (no buffering the whole thing), passing Range along so On Demand seeking works. |
xmltv.php, get.php |
Forwards them. |
/healthz |
Each route's state: tunnel up, exit country and IP. |
- Failover across the provider's servers, in the same order the apps use (the last that answered first; ones that turn the login away last). As in the apps, a 401 or 403 is a refusal (not asked again), and anything else, 404s included, a miss worth another try: trex's main server sits behind Cloudflare and answers a 404 to one request in a few.
- Stream limits still apply: trex allows 1 stream; it just sees PIA's address instead of yours.
Routing by country #
Each request goes one way:
- By server. A server tied to a country always goes through it:
es.uhdp.top→ Spain,gr.uhdp.top→ Greece,it.uhdp.top→ Italy. - By channel. For a stream, the relay looks the stream id up in the
provider's channel list (fetched and kept a day, like the apps do) and reads
the region off its name: "UK: BBC ONE" → UK, "ES| LA 1" → Spain, the same
parsing as
ChannelName.region. A stream's segments follow its playlist. - Rules override both: "stream 4411 via Spain", "category US Sports direct".
- Everything else goes direct, or through a default route if one is set. API calls and guides don't pay VPN latency for nothing.
A region with no exit set up goes direct. Adding a country is one gluetun container and one line of config.
Config sketch #
listen: :8080
routes: # exits, by name
es: http://gluetun-es:8888
uk: http://gluetun-uk:8888
default: direct
providers:
trex:
servers: [http://vpn.uhdp.top, http://tv.wd.uhdp.top, http://es.uhdp.top, http://gr.uhdp.top, http://it.uhdp.top]
server_routes: { es.uhdp.top: es, gr.uhdp.top: gr, it.uhdp.top: it }
by_region: true # "UK: …" → uk, "ES| …" → es, when that route exists
rules:
- { stream: 4411, route: es }
- { category: "US SPORTS", route: direct }
The relay tells logins apart by username, so one relay serves every provider.
In the apps #
Almost nothing changes: a login's servers are just URLs.
- Add the relay as trex's first server and keep
vpn.andtv.wd.after it. If the relay or a tunnel is down, or the Mac is away from home, the apps' server ordering falls back to going direct, and moves the relay back first when it answers again. - The Manager's Details… sheet gets Add a Server…; its server check then shows the relay beside the rest.
- Stream URLs are built from the login's server, so video follows.
Open decisions #
- How a stream's country is chosen.
- (a) Automatically from the region in its name, with rules for exceptions (the config above). No app changes. Recommended.
- (b) Picked per channel in the Manager ("Route: Direct / Spain / UK"),
synced, with the app putting the route in the URL (
/es/live/…). Most control; app work, set on every channel. - (c) (a), with a per-feed override in the Manager for the odd channel.
- Where the relay's code lives.
- (a) This repo, under
Relay/, its own Go module and Dockerfile: it only serves these apps, and changes with them. Recommended. - (b) A new repo,
phin-tech/iptv-relay, with its own CI building the image. - (c) The homelab GitOps repo.
- (a) This repo, under
Trying it #
- Locally first: a Compose file with
gluetun-es(PIA Spain) and the relay, PIA login in a local.env. - Point a Debug Manager's trex login at
http://localhost:8080and check: the login, a live HLS channel, Earlier Shows, a movie with seeking, the connection count at tune-in, and whetheres.uhdp.topanswers through Spain. - Then the homelab, via the deploy-to-homelab setup.
Alternatives looked at #
- iptv-proxy (pierre-emmanuelJ): proxies Xtream with URL rewriting, and could be given your real login. Set aside: one upstream server only (no mirror failover), unclear coverage of catch-up, seeking and connection counts, and it's old.
- A VPN in the app (a Network Extension running WireGuard, only for the
providers' addresses, with a PIA WireGuard config pasted into the Manager,
generated with PIA's manual-connections scripts). Possible since tvOS 17,
but whether
wireguard-applebuilds for a tvOS extension is unproven, and pasted PIA keys may stop working and need generating again. Worth a spike only if the relay falls short. Routing by channel country would be much harder there. - A VPN on the router for the Apple TV only: no code, but all or nothing per device, and no choice of country per channel.
Phin Tech docs
Rabbit Ears Manager in the store →