On Demand through the relay: one catalog, and search
Superseded 2026-11-03. The Swift server (
StationServer,RelayServer,antenna-tower-server,control-room, the Manager's launchd helper and MCP assistant) was replaced by the Go tower intower/(ADR 0005). What follows is history.
Design agreed 2026-09-28. Nothing here is built yet.
Today each screen fetches On Demand one folder at a time (sources, categories,
titles, seasons, episodes) straight from each Xtream login and Plex server, and
keeps its own copy on disk (OnDemandCatalog). Nothing knows a title until its
category has been opened, so there's nothing to search, and every screen fetches
the same catalogs for itself. The relay (docs/manager-relay.md) fetches the
catalogs once, holds one index of every title, and answers browsing and search
for every screen.
Decisions #
- Search from everywhere. On the TV: a Search row at the top of On Demand with a retro letter grid steered by the remote, matches narrowing with each letter. A Keyboard key on the grid (and Play/Pause) opens the tvOS keyboard, for dictation and typing from an iPhone. In the Manager and through the MCP: search, then "play on a screen…".
- One entry per title, copies inside it. The same film on several logins
(and Plex) is one entry, matched by cleaned name and year (TMDB id where the
provider gives one). Play takes the best copy: the preferred login, then
Plex, then quality. Select lists each copy (login, 4K/HD/SD from the name,
file type) to choose from. The row says so:
1995 · 3 copies · 4K,· Plexwhen there's a Plex copy, and a mark when every copy is a file AVPlayer can't open (MKV, AVI). - The relay caches the catalog, descriptions and posters. Names, years,
categories, which login has what, and the search index, refreshed nightly
and from the Manager on demand. Plots (today
Synopses, per screen) and posters are fetched once, by the relay, and kept. - Without the relay, browsing works as today and search waits. Screens
fall back to fetching folders directly; the Search row says "Search needs
the relay (Mac mini)". VOD is served when the Manager hosts the relay (it has
the logins and the Plex token);
retro-relayalone has no VOD. - Search follows your preferences, not your hand-picked categories. Languages, hidden kinds and hidden sources apply; categories picked to keep the menus short don't, so a film in one you left out still turns up. The Manager and MCP have a "search everything" switch.
- Adult never enters the index. A whole-catalog fetch returns every
title, adult ones too (a title carries only its category id), so the relay
drops titles in categories
Adult.categorymatches, as live channels do (Xtream.allChannels), and in categories Jev taggedadult, whatever the settings say. Nothing can find them: TV, Manager, MCP or "search everything".
The catalog #
- Per login, two calls:
get_vod_streamsandget_serieswithout a category return the whole catalog. With the categories (and their tags), that's the login's part of the index. Refreshed nightly (staggered across logins, one at a time, so no login sees a burst); a login that doesn't answer keeps its last copy. - Plex: each movie and show library's contents, from
PlexClient. - Merging: a title's key is its cleaned name (provider prefixes like
EN -,4K-,|UK|and quality marks stripped, seeChannelName) plus its year. Copies whose key matches merge; a TMDB id, when both have one, decides. - Episodes are fetched when a show is opened, then kept (a day), as today.
- Kept on disk in the Manager's container, so a restart serves at once.
The protocol #
Version 1 routes, same token and client tracking as the planes feed:
| Request | Answer |
|---|---|
GET /v1/vod/sources |
The sources (each login's movies and series, each Plex library). |
GET /v1/vod/sources/<id>/categories |
A source's categories, with their tags. |
GET /v1/vod/sources/<id>/categories/<cat> |
Its titles, merged, each with its copies. |
GET /v1/vod/shows/<id> |
A show's seasons and episodes, each with its copies. |
GET /v1/vod/search?q=…&lang=…&hide=…&all=1 |
Matching titles, best first, at most 50. The screen sends its preferences; all is the Manager's switch. |
GET /v1/vod/titles/<id>/plot |
The description. |
GET /v1/vod/titles/<id>/poster |
The poster, from the relay's cache. |
Search matches word prefixes, ignoring case and accents ("dark kn" finds The Dark Knight), ranked: whole name, then name start, then word start, then newer. Play URLs aren't served: the screen builds them from the copy's login as today, so streams don't pass through the Mac mini.
In the code #
- RetroRelay:
VODSource(catalog fetch, merge, index, search) inRelayServer; the route and result types inRelayKit. It needs the logins and Plex, which the host passes in (aVODBackend, likeRelayAdminBackend). - Manager:
RelayHostgives the relay its backend; the Relay pane shows each login's catalog (titles, last refresh, Refresh now); an On Demand search field with "play on a screen…"; MCP toolssearch_vodandplay_vod. - Screens:
OnDemandCatalogasks the relay first and falls back to its direct fetches;OnDemandBrowsergains the Search level and the copy chooser.
Built (2026-09-29) #
Phase 1, with these changes from the plan above:
-
The catalog is built on a Mac, never on the TV. Measured: each login lists ~190,000 movies and ~47,000 series, 50–80 MB per whole-catalog call (3–16 s).
VODLibrary(Sources/Shared/Channels/OnDemand) fetches it on the Mac hosting the relay, or on any Mac (the Manager, the Mac app) that finds no relay. An Apple TV only asks the relay for a category or a search; without a relay it browses each provider directly as before, and the Search row says it needs the relay (category names still match).VODAccess.backend()picks. -
Only the languages you want. The catalog keeps the categories
OnDemandSettings.keptlists (worked out by the Manager from Jev's tags: your languages and kinds, plus hand picks, never adult) and drops titles whose own prefix names another language (VODName.language: "GR - …", "SC - …" titles sit in "English" new-release categories, subtitles burned in). Jev tags many such categories English, so the prefix is what catches them. With English only: ~57,000 merged titles from two logins and Plex. -
Merging is by TMDB id first (91% of titles have one), then cleaned name and year. A login listing a title twice the same way (same picture, same file type, in "Top 100" and "Drama") is one copy. The name is Plex's, else the plainest a provider gives; the year the one most copies agree on.
-
Routes are
/v1/vod/sources,/v1/vod/sources/<id>/titles?category=,/v1/vod/search?q=and/v1/vod/shows/<id>; 404 means no catalog (the screen falls back). The relay's hello saysvod: truewhen it serves them. No "search everything" switch: other languages aren't in the catalog. -
Search also matches category names ("christmas", "marvel") from each screen's kept category lists, shown as folders above the titles.
-
The TV: a Search row at the top of On Demand with a letter grid (Select types, → to the results). Its Keyboard key, or Play/Pause, opens the system keyboard full screen (dictation, typing from an iPhone) with the results under it; picking one closes it, Menu goes back to the grid. On the Mac you just type. Select on a title with several copies lists them; Play/Pause plays the best.
-
The Manager: a search field in the On Demand pane (Play plays the best copy, its menu any copy; a link to the title on The Movie Database), and a Catalog section there (not the Relay pane) with each source's titles, size, last fetch and Refresh Now. MCP:
search_vodandvod_catalog. -
Kept on the Mac as screens ask (
VODArchive): a series' episodes and each description (a movie's from its copies, a series' and an episode's from the provider or TVMaze) are looked up the first time any screen asks, then served from disk (/v1/vod/titles/<id>/plot). A kept episode list over a day old is fetched again behind the scenes, for new episodes. Anything no screen has asked for in a week goes, as does what's kept for a title that leaves the catalog. Screens fall back to their own lookups without a relay.
Not built yet: posters, and "play on a screen…" (screens can't be told to play yet).
Phase 2: downloads into Plex #
(Redesigned 2026-10-17 with playing: see vod-fetch.md. The relay fetches both a play buffer and a kept copy, and streams do pass through the Mac mini.)
(Not the same thing as a screen playing a title while it downloads, which is built: see read-ahead.md. That copy is a buffer and is deleted when the title stops.)
"Download" on a title (or a whole series) has the relay fetch a copy into
your Plex library on a shared drive, set in the Plex pane (one folder for
movies, one for TV, kept on the relay's Mac only), named as Plex expects:
Movies/Heat (1995)/Heat (1995).mkv, TV Shows/Show/Season 01/Show - S01E02.mkv.
Then it asks Plex to scan, and the title gains a · Plex copy, first choice
from then on. No remuxing: Plex transcodes what AVPlayer can't open. A download
takes one of the login's streams while it runs (trex allows one), so downloads
queue one at a time per login and wait while that login is playing.
- Plex runs on the NAS. The relay's Mac writes to the NAS's movie and TV shares over SMB, picked in the Plex pane's Downloads section with a folder picker (a plain path: the Manager isn't sandboxed). Not iCloud Drive: it can offload files, and Plex scans them badly.
- The share has to be there. Before each download the relay checks the folder is mounted, remounts it if it can, and otherwise holds the queue and says so in the Relay pane. A file is written under a temporary name and renamed when complete, so Plex never picks up half a film.
- Scanning. The NAS sees the same files under its own path
(
/volume1/Movies), so the relay asks Plex to scan the whole library section, which needs no path of Plex's. An optional "Plex sees this folder as" path narrows the scan to the new title's folder.
Built: shelves and poster rows (2026-10-12) #
On Demand opens on rows of posters, as a streaming app does, not on the list of logins. Separate from the Video Store (docs/video-store.md), which is its own channel and untouched; they share the poster cache and the relay's poster route.
- Shelves (
VODShelfIndex, RetroLineup): built besideVODIndexon the Mac that holds the catalog. Providers name their categories by service and genre ("NETFLIX MOVIES", "|EN| ACTION/THRILLER", "DISNEY+ KIDS SERIES"), so a category's name decides:VODShelves.service(in:)(Netflix, Disney+, Apple TV+, HBO Max, Prime Video, Hulu, Paramount+, Peacock, Discovery+, Showtime & Starz, AMC+ & MGM+, Universal, Viaplay, Crunchyroll, BritBox, Acorn TV) andVODShelves.genres(in:)(a category may be several: "DRAMA/ROMANCE"). A service's category ("NETFLIX KIDS") is that service's and not a genre. Shelves merge across logins: one Netflix. Plex libraries have no categories and are one shelf, "On Your Plex". New is the categories of new releases plus anything added in the last month this or last year; Top Rated is 7 and up, 1980 on. A service needs 8 titles to be a row, a genre 12. - What the catalog now keeps per title: the poster's TMDB file name (when the provider's icon is one of TMDB's), when it was added, and its rating, from the whole-catalog call it already makes. A catalog built before this has none, so rows are plain tiles until the next refresh; the Manager's Refresh does it.
- Order on a shelf: titles with a poster first, then newest added, then year.
- Protocol:
GET /v1/vod/rows?n=20(the home screen: New and Top Rated as movies then series, each service, Plex, each genre,ntitles each) andGET /v1/vod/shelves/<id>?kind=movies|series&offset=&limit=(a whole shelf, at most 200 at a time). 404 means no catalog, and the screen keeps the list of sources as its menu. Sources you've turned off are filtered as for search. - The TV (
OnDemandPostersView): a row of Search / Recently Watched / By Source, then a row of posters per shelf. The poster in focus enlarges where it stands; Select opens its card (poster, year, rating, plot, copies, Play or Resume and Start Over, Choose a Copy); Select again plays. A series' card opens its seasons. Play/Pause plays the best copy at once. The last tile in a row, See all, opens the shelf as a wall of posters six across. A wall (a shelf, or what the drawer narrowed to) is had 120 titles at a time: within four rows of the end of what's here, the next page is asked for (offset=) and joins it, until a page comes back short. Seasons, episodes, copies and Search are still the older list screens. - Adult never enters (the catalog drops it before any of this), and shelves follow the kept categories and your languages, as search does.
- Not yet: a Movies / Series switch on the home screen; hiding a service you don't have; posters for titles whose provider icon isn't on TMDB (the relay could look them up by TMDB id).
Built: the filter drawer, and modern lists (2026-10-12) #
- Left from the first column (on the home rows or any wall) opens a drawer: Search, then Type (Any / Movies / Series), Genre, Service, Year (by decade, and before 1980), Sort (Newest, Top Rated, A to Z) and Clear Filters. A choice applies at once: the screen behind becomes a wall of what passes every filter at once ("Comedy · 1990s · Movies"), and Left from that wall's first column opens the drawer again to change it. Clearing every filter goes back to the home rows. Left once more inside the drawer changes channel; Back or Right closes it.
- The catalog (
VODShelfIndex.browse, RetroLineup): genre and service are the shelves' member sets intersected, kind and decade checked per title, ordered by positions worked out once at build (newest, rating, name). Genres and services offered are the ones the catalog has, biggest first (VODFilter). - Protocol:
GET /v1/vod/shelves(every shelf with its counts, for the drawer) andGET /v1/vod/browse?kind=&genre=&service=&decade=&sort=&offset=&limit=(at most 200). - Seasons are tiles; episodes, copies and Recently Watched are a clean
list with the series' poster, plot and what Select does beside it. The older
gold menu is gone from On Demand; what remains of it is the player's own
pause menu (
OnDemandControls). - Search is a field with filter chips (All / Movies / Series / 4K) over a poster wall; on the Apple TV the system keyboard opens straight away, and the remote's mic dictates into it.
Built: watched, other copies, and the card (2026-10-13) #
- Watched (
OnDemandWatched, each profile's, in iCloud with its history). A title is seen when it plays to its end or is left in its credits (the last minute, or the last twentieth:OnDemandDecisions.nearEnd), in whichever copy; a series once every episode is. A movie's card can say so by hand (Mark as Watched). Seen titles carry a tick on their poster and in episode lists; a season's tile says "8 episodes · 3 left", a series' card "24 episodes · 3 left". A series' seasons and a season's episodes open on the next you haven't seen. Watched: Hide in the drawer leaves seen titles off the shelves and walls (done on the screen: what you've seen isn't the catalog's to know). The newest 1,500 are kept: iCloud's key-value store holds a megabyte in all, and the station's settings share it. - A place belongs to the title, not the copy. Resume, the progress bars and
the card look for the copy with a place kept (
OnDemandEntry.playTitle), not the best one. Start Over plays the best and drops any other copy's place. - Another copy when one won't play.
OnDemandPlayback.playtakes the title's other copies. A copy whose login doesn't answer, whose file won't open, or whose download stops is followed by the next, from the same place, the loading screen saying "STRONG WOULDN'T PLAY". The place and the Recently Watched entry move with it. A title played from Continue Watching remembers its copies from when it was first played (OnDemandRecent.Played.others). - Logins in use. Before a title with copies on more than one login plays,
each login is asked how many streams it has open (
IPTVLoad.rooms, as live channels do). If the best copy's login is full and another's isn't (Plex never is), that one plays: "STRONG IS IN USE". A copy picked by hand from Choose a Copy is played as asked; the list marks full logins "In use". It doesn't say which screen: the provider gives a count, and screens don't tell the relay what they're playing. - Remove from Continue Watching on the card of anything with a place kept: the place goes, the title stays in Recently Watched.
- The next episode in Continue Watching. An episode seen to the end (played
out, skipped past its credits, or left in them) keeps the one after it on its
Recently Watched entry (
OnDemandRecent.Played.next), and Continue Watching shows the series as "Up next · S1 E5" until that's started or seen. A series is one tile: the episode of it played last speaks for it. Played from there, the episode knows its series (OnDemandRecent.known), so Up Next follows it. The next is looked up when the episode finishes in On Demand's player, so it needs the series in the merged catalog, as Up Next does. - The card says how long a title runs and when it would end ("2h 50m ·
Ends 10:42 PM", from where you'd resume): the file's own length when it has
played here, else the relay's details, the provider's, or Plex's. And which
services it's on ("On Netflix · HBO Max"), which the shelves now hand out
with each title (
VODTitle.services; needs the relay's Mac on this build). - New Episodes: a home row of series you follow (on What I'm Watching, or with an episode in Recently Watched; the newest twelve) that have more episodes than when you last opened them. Asked for every half hour at most; opening the series' seasons clears it.
- Sleep Timer and After This Episode: Stop in the paused menu
(
OnDemandSleep): off, 15, 30, 60 or 90 minutes, then whatever's playing on demand (here or in the Video Store) stops with its place kept, and no next episode is offered. On Demand only: live channels play on. - Skip Intro, Next Episode for Plex copies, where the server has marked the
intro and credits (
PlexClient.markers): Select over the intro jumps past it; over an episode's closing credits it ends the episode, and the next is offered. Play/Pause still pauses. Providers' files have no such marks. - Not run against real failures yet: the copy change (a login down, a full login) and Plex's markers are built from the code's own paths and the rules' tests, not seen on a TV.
- More Like This on a card: a wall of the same kind of thing (movies or
series) in the title's narrowest genre, from its decade, best rated first.
The shelves hand out each title's genres for it (
VODTitle.genres), so like the services it needs the relay's Mac on this build, and a title had from search or a provider's category has neither. - Not yet: marking an episode or a season watched by hand; naming the screen a login is in use on; a shelf as a channel.
Built: collections and cast (2026-10-14) #
- A TMDB key in the Manager's On Demand pane (Collections and Cast), synced
like the OpenSubtitles key (
TMDBKey.key). The API Read Access Token is sent as a header; a short v3 key has to go in the address, so a failure is only ever reported in words, never with its request. Check the Key looks up The Godfather. - The relay's Mac asks TMDB (
TMDBStore, beside the posters undertmdb/): a title's collection and top 12 cast in one request (creditsappended for a film,aggregate_creditsfor a series, so a series' cast is over every season), a collection's films, and each person's combined credits (without the ones as themselves). Each answer is kept a month; one TMDB doesn't know, a week; a failure isn't kept, and an old answer stands in for it. - Matched to the catalog by kind and id (
TMDBRef,VODShelfIndex.titles(_:)): a film's ids and a series' are separate, and a provider's0isn't an id. Only what's here is shown: a collection with two or more films here, and cast with at least one other title here. GET /v1/vod/extras/<movies|series>/<id>answers aVODExtras;GET /v1/vod/people/<id>the titles here with that person, newest first.- On the TV, a card asks for its title's extras as it opens. With any, More Like This opens a list: titles like it (the wall from before), the collection ("The Godfather Collection · 3 here", a wall in release order), then the cast ("Al Pacino · Michael Corleone · 14 more here", each a wall). Without, it goes straight to the wall as before, and a title with no genres but a collection or cast gets the action once they're found. The card gains no actions, so it still fits.
- Needs the relay's Mac (the Manager) on this build and a key; untested against TMDB with a key (the paths answer 401 without one).
Designed, not built: a shelf as a channel (2026-10-14) #
Put on hold partway through the design. What was decided:
- A real schedule. A shelf's channel plays on a clock, the same on every screen: tuning in joins a title under way, and the guide lists what's on and next.
- You choose which shelves. "Add as a Channel" on a shelf's see-all wall on the TV, in the Manager and over MCP. It takes the next free number and is renamed, renumbered and removed like any channel.
- Films and series. Series play in blocks of two or three episodes, each block carrying on from the last.
- On the half hour. Titles start at :00 or :30. A gap is filled with a short episode from the shelf that fits, else a "Coming Up" card. This needs runtimes, which providers often leave out: the relay looks them up while scheduling, and a title with none is never filler and only scheduled once known.
- The remote works like live TV. No pausing; Select shows the title's info with Watch from the Beginning, which opens it in On Demand.
- Open: repeats and watched marks (proposed: ignore watched, no film again within a week, series start over after their last episode); a channel without a relay; which login a channel's playing holds.
Phin Tech docs
Rabbit Ears Manager in the store →