Downloads
Taking a copy of an episode to keep on a device, checking it in, and reporting progress from it.
DownloadService issues grants: a recorded, revocable right to hold a
copy of one file on one install. Playback hands out a credential that lasts
minutes and bytes that are fetched as they are watched; a download is the
opposite bargain — fetched once, kept for weeks, played where no request
reaches a hub. The grant is what keeps that honest: an owner can see it and
take it back, a server can switch downloads off, and a copy that stops
checking in stops playing.
There is no DRM. The copy is a file on a device the viewer owns; the lock described below is the client's promise, kept on the owner's behalf.
Whether, and at what quality
ListDownloadOptions { server_slug, episode_uuid, media_file_uuid?, capabilities }Returns allowed and, when false, a refusal — SERVER_DISABLED when the
owner has downloads off, NO_FILE when nothing on an active hub carries the
episode. Alongside: the file's media facts, the audio_tracks, the
subtitle_tracks with delivery already negotiated (a track with
EXTERNAL delivery can travel beside the copy), and options — one per
quality:
{
"options": [
{ "rung": { "id": "source", "width": 3840, "height": 1600, "bitrateBps": 24000000, "isSource": true, "available": true }, "estimatedBytes": 21474836480, "exact": true },
{ "rung": { "id": "1080p", "width": 1920, "height": 800, "bitrateBps": 8000000, "available": true }, "estimatedBytes": 7160000000 },
{ "rung": { "id": "720p", "width": 1280, "height": 534, "bitrateBps": 4000000, "available": true }, "estimatedBytes": 3580000000 }
]
}source is the original; its size is exact. Every other rung is an
encode produced by the file's hub, and its size is the rung's rate over
the file's duration — say "about". A rung is available: false with
RUNG_REQUIRES_TRANSCODE when the hub has no encoder, in which case only the
original can be taken.
capabilities is the same ClientCapabilities you send StartPlayback. The
encoded rungs are planned against it — video the device cannot decode is
re-encoded, everything else is copied — and the original is marked when it
would not play. supports_hls is ignored here: a download client never plays
a playlist.
Taking one
StartDownload {
server_slug, episode_uuid, media_file_uuid?,
quality_id, // "source" or a rung id
capabilities, client, // client.install_id is REQUIRED
preferred_audio_languages?, preferred_subtitle_languages?,
audio_track_id? // the one track an encoded copy carries
}Refused with FAILED_PRECONDITION when downloads are off, NOT_FOUND when
nothing carries the episode, INVALID_ARGUMENT for a rung not on the
ladder, and UNIMPLEMENTED for a rung this hub cannot produce.
The response is the download (the grant), an issue (everything the copy
needs beside its bytes) and the caller's progress:
{
"download": {
"id": "…", "serverSlug": "home", "episodeUuid": "…", "mediaFileUuid": "…",
"qualityId": "1080p", "state": "DOWNLOAD_STATE_ACTIVE",
"createdAt": "…", "validUntil": "…",
"client": { "kind": "CLIENT_KIND_PHONE", "installId": "…", "label": "Luke's phone" },
"title": "The Expanse", "episodeTitle": "Dulcinea", "seasonNumber": 1, "episodeNumber": 1,
"durationMs": 2760000
},
"issue": {
"delivery": {
"kind": "DOWNLOAD_KIND_ENCODED",
"url": "https://<hub>.<stream-domain>/media/<file>/hls/<session>/manifest.json?t=…",
"localUrls": ["https://10-1-2-50.<label>.xmbsrv.com:8443/media/…"],
"mediaToken": "…", "expiresAt": "…", "renewAfter": "…",
"hubUuid": "…", "hubName": "study"
},
"media": { … }, "audioTracks": [ … ], "subtitleTracks": [ … ],
"chapters": [ … ], "trickplay": { … }, "markers": [ … ], "transcode": { … }
}
}Fetching the bytes
DOWNLOAD_KIND_ORIGINAL — url is the file. Fetch it with HTTP byte
ranges and resume by Range; contentLength and mimeType say how much and
what to name it.
DOWNLOAD_KIND_ENCODED — url is a manifest the hub keeps current while
it encodes. Poll it and fetch each segment as it appears; the copy is
downloading while it is still being produced, and you never wait for the
last segment before fetching the first.
{
"state": "encoding",
"init": "init.mp4",
"targetDurationS": 4,
"segmentCount": 690,
"encodedToMs": 412000,
"segments": [186231, 190044, 0, 0, …]
}state—encoding,doneorfailed.init— the initialisation segment, relative to the manifest. Fetch it first.segments— one entry per segment index; its byte size when the segment is complete,0when it is not yet. A listed size is a finished file: the hub never lists a segment it is still writing.- Segments are
seg00000.m4s,seg00001.m4s, … relative to the manifest, and each is immutable once listed.
Concatenate init.mp4 followed by every segment in order and the result is
one fragmented MP4 that plays and seeks as a file. Poll the manifest at
roughly the segment duration while state is encoding; a poll that finds
nothing new should back off.
Segment durations can vary. When video is copied, each segment spans one source keyframe interval; when video is encoded, the target is four seconds. Use the manifest's segment count and entries rather than calculating them from the film's duration.
The hub keeps a download encode for as long as the platform holds the grant
open, not for the three idle minutes a live encode gets. A hub reboot wipes
its encode tree; if the manifest starts answering 404, call RenewDownload
— it restarts the encode from the spec the grant kept, and the manifest
comes back listing what has been re-produced.
Every URL in issue carries the token in its query string, and the token
lasts hours (expiresAt). RenewDownload re-issues the whole issue with
a fresh token; call it after renewAfter if the fetch is still running.
localUrls are the same resource on the hub's own network, in preferred
order — try them first when present, exactly as for playback.
Beside the bytes
subtitleTracks entries with a url can be fetched and kept. chapters
image URLs and trickplay sheets can too. markers and media are plain
data; keep them with the copy. Artwork comes from the title's own
poster_url/thumb_url on the browse surface, not from here.
Finishing, deleting, renewing
CompleteDownload { download_id, bytes }once every byte is held. The grant moves toCOMPLETEand the hub drops its encode.DeleteDownload { download_id }when the viewer removes the copy.RenewDownload { download_id }for a fresh token and fresh URLs, or after a manifest 404.
Checking in
CheckInDownloads { download_ids } → { checks: [{ download_id, verdict, valid_until? }] }Call it whenever the app has a connection, with every grant the install holds. Each check answers one of:
VALID— keep playing;valid_untilhas moved forward.REVOKED— an owner took it back, or the viewer deleted it elsewhere. Delete the copy.SOURCE_GONE— the file it was taken from is no longer on any active hub. Delete the copy.DISABLED— the server has downloads off now. Delete the copy.DENIED— the caller is no longer a member of the server, or the grant is not theirs. Delete the copy.
valid_until is the lock. A copy whose valid_until has passed without
a VALID check-in must not play until the app can check in again. The
window is thirty days by default, and every successful check-in restarts
it — a device used online at all never sees the lock.
ListDownloads { server_slug?, install_id? } lists the caller's grants;
revoked and deleted rows are included so a client can reconcile.
Drawing a downloaded title offline
GetOfflineSnapshot { server_slug, series_uuid, episode_uuids }Returns the TitleDetail the online title page draws and an
EpisodeSummary per named episode, with progress — the same messages, so
nothing is rendered two ways. Fetch it when a download is taken and again on
each check-in, and keep it with the copies. Only the named episodes come
back: the offline surface draws what it holds.
Reporting progress from a copy
ReportProgress and SetWatched take an optional observed_at: when
the position was true by the client's clock. Queue beats while offline, stamp
each with its own time, and send them in order when a connection returns.
The server drops a stamped report that is older than the row's last play — by then another device, or a later evening on the same one, has moved the playhead, and applying the stale beat would drag it back. An unstamped report is "now" and always applies, which is what every online player sends. A stamp from the future is clamped to now.
For administrators
ListServerDownloads { server_slug }— every grant on the server, withuser_nameand the device's label.RevokeDownload { server_slug, download_id }— takes a copy back; the holder's client deletes it on its next check-in.ServerSettings.downloads_enabled(viaGet/SetServerSettings) — on by default. Off refuses new grants and, at their next check-in, revokes the copies already out.SetServerSettingsRequest.downloads_enabledis optional: absent leaves it as it was.