feat(media): subtitles that travel with the film — CLI, browser <track>, ExoPlayer

`shade media put Film.mkv` seals Film.srt / Film.no.srt / Film.en.vtt
found beside it and carries their grants in the film's sealed meta
(extra["shade.subtitles"]), so they follow the film alone or in an album
and the relay sees unrelated objects. /watch/ adds them as <track>s (SRT
to VTT, labels in the viewer's language, the viewer's language on, one at
a time); `media get` writes them back; Android opens them with
ShadeMedia.openFilm and gives them to ExoPlayer as side-loaded tracks
(ShadeMediaDataSource now resolves readers by URI).

Verified: 76 TS tests; Chromium nb-NO shows the Norwegian track only, en-US
the English one; film + subtitles round-trip bit-identical; Robolectric
ExoPlayer sees both text tracks with the Norwegian one default; a shared
vector checks the meta field in Kotlin (82/0).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-18 22:01:33 +02:00
parent 9efe1bcfd3
commit 422a37e830
19 changed files with 536 additions and 26 deletions

View File

@@ -60,6 +60,7 @@ import type { LiveContent } from '../packages/shade-media/src/live/frame.js';
import { encodeGrant } from '../packages/shade-media/src/grant.js';
import type { MediaGrant } from '../packages/shade-media/src/grant.js';
import { albumMeta, encodeAlbum } from '../packages/shade-media/src/album.js';
import { withSubtitles } from '../packages/shade-media/src/subtitles.js';
import { ed25519PublicKeyFromSeed as edPub } from '../packages/shade-crypto-web/src/index.js';
const VECTOR_FILE_VERSION = 2;
@@ -1108,6 +1109,19 @@ async function generateMediaVectors(): Promise<Vector[]> {
itemKinds: ['shade.media-grant/v1', 'shade.media-grant/v1', 'shade.live-grant/v1'],
itemNames: ['Episode 1.mkv', 'Ekstra', grant.meta?.name ?? ''],
});
// Subtitles: a film's meta carrying its subtitle grants.
const subMeta = withSubtitles({ name: 'Film.mkv', mime: 'video/x-matroska' }, [
{ grant: { ...film, mediaId: new Uint8Array(16).fill(0x55), meta: { name: 'Film.no.srt' } }, lang: 'no', label: 'Norsk' },
{ grant: { ...film, mediaId: new Uint8Array(16).fill(0x66), meta: { name: 'Film.en.vtt' } }, lang: 'en' },
]);
vectors.push({
description: 'subtitles: film meta with extra["shade.subtitles"] naming two sealed subtitle files',
meta: JSON.stringify(subMeta),
langs: ['no', 'en'],
labels: ['Norsk', null],
mediaIds: [hex(new Uint8Array(16).fill(0x55)), hex(new Uint8Array(16).fill(0x66))],
});
return vectors;
}