Fetched subtitles
A file with no subtitle track in a language its library wants can be given one from a subtitle database. The platform never talks to those databases itself: one shared retrieval service in front of every provider is asked with everything the platform knows about the file, and the hub the file lives on pulls the winner and writes it beside the file as a sidecar. Playback then serves the sidecar like any other.
The library's policy
Each library carries a subtitles policy on Library under xmb.api.v1,
written whole through LibraryService.UpdateLibrary:
| Field | Meaning |
|---|---|
mode | off (the default) — the nightly pass leaves the library alone. suggest — it searches and records the best candidate for a person to apply, downloading nothing. automatic — it fetches and writes the winner beside the file when a hash match makes it certain. |
providers | The sources to ask, best first, each with enabled. Read back with every provider the retrieval service knows, configured saying whether the platform holds credentials for it and quota_bound whether fetching from it spends a daily allowance. A provider left out of a write trails the ones named, enabled. |
languages | ISO 639-1 codes, best first. A file with a text track in any of these already needs nothing. |
allow_hearing_impaired, allow_forced, allow_machine_translated | Whether those kinds of track may be chosen. Off, they are hidden rather than ranked lower. |
trusted_only | Only uploads the provider vouches for. |
The policy is refused when the mode is not one of the three, a provider is not one the service knows, or an active mode names no language.
What the nightly pass does
Every day at 4:41 each server's library.subtitles run:
- Reads every library's policy and, for each library that is
suggestorautomatic, lists files that are available, probed, attached to a real episode or a feature, and have no text subtitle track in the library's languages — embedded or sidecar. Bitmap tracks (PGS, VobSub) do not count. Recently added files first, a bounded batch per library per night. - Asks the retrieval service about each one with the file's OpenSubtitles hash and size, the title's IMDb, TMDB and TVDB ids, season and episode, file name and duration, and the library's policy. The service ranks what the providers have under that policy; the best candidate is kept.
- In
automaticmode, when the best candidate is a hash match — the same release, byte for byte — the service caches the file and the hub pulls it into<stem>.<lang>[.sdh][.forced].<ext>beside the media file. A candidate matched by title alone is recorded as a suggestion instead; certainty is what an automatic write needs. - Records the outcome on the file: written, suggested, nothing found (asked again in a month), or failed (backed off).
A sidecar is never written over a file that is already there. When a person's
own <stem>.en.srt exists the pass tries <stem>.en.xmb.srt, and when that
exists too it records the suggestion and moves on. A file whose subtitle a
person applied by hand is never revisited by the pass.
The whole environment can hold the pass at "suggest": with fetching disabled platform-wide, automatic libraries still search and record suggestions but nothing is downloaded and nothing lands on a hub. One shared account serves every environment, so a download is paid for once however many servers want the same file.
Picking one by hand
Two viewer-level RPCs on LibraryService, both keyed by media_file_uuid
and scoped AUTH_SCOPE_USER_READ — a person watching is who asks, from the
player's subtitle menu ("Find more…") or the admin title page:
SearchSubtitles— everything the sources have for the file, ranked under its library's policy:provider,file_id,language,release,hash_match, the kind-of-track flags,downloads,rating,cached(already fetched by the platform, so applying costs nobody a download) andscore.languagesnarrows the ask;any_kindshows tracks the policy would hide.suggestedis what the nightly pass last chose for the file;applied_*names a subtitle already written beside it.ApplySubtitle(provider, file_id)— the service caches the file, the hub pulls it beside the media under a sidecar-purpose grant, and the file is re-probed on the spot so the answer carriessubtitle_track_id: the idStartPlaybackwill list, which a player selects without a second round trip.ALREADY_EXISTSwhen a different file already has both names the sidecar could take;RESOURCE_EXHAUSTEDwhen the provider's allowance is spent;FAILED_PRECONDITIONwhen the hub cannot write beside its files.
A hand-applied subtitle is recorded as that person's and the nightly pass never revisits the file.
What the hub needs
The hub must be able to write beside its files — the same writable media mount ingest needs — and be on a build that carries sidecar fetching. A hub that cannot write is reported on the run as an issue and its files are backed off rather than failed for good.