caption_extractor — video-site caption extraction
Add caption support for a new video site to the browser extension. The host sends the enabled extractor scripts to the extension; the extension runs on every web page, and only pages matched by
match(url)have their captions captured.
Declaration
{
"id": "example.caption.extractor",
"name": "示例:自定义视频站字幕提取",
"version": "1.0.0",
"target_app_version": "0.2",
"type": "caption_extractor",
"entrypoint": "extractor.js",
"enabled": false,
"tags": ["字幕", "示例"]
}entrypoint points at an extractor.js. Defaults to enabled: false.
Script skeleton
// Copy this file, change the id and match, and you can provide captions for a new video site.
TransBoxExtractors.register({
id: "my_site",
match(url) { return /example\.com/.test(String(url || "")); },
videoId(url) { return new URL(url).pathname; },
// Option A: use when the site has a full timed track file
async fetchManifest(videoId, ctx) {
return {
src_lang: ctx.preferredLang || "en",
cues: [{ start: 0, end: 1.2, text: "Hello" }],
trackName: "my site",
};
},
// Option B: use when captions only exist on screen and there is no timed track file
collectLines(doc) {
return TransBoxCaptionHost.linesFromSelector(".player-caption");
},
});(fetchManifest and collectLines are either/or — or provide both.)
Interface
| Member | Description |
|---|---|
id | Extractor identifier (required) |
match(url) | Only enabled on a matching site; return falsy to stay out of the way |
videoId(url) | Extract the video ID from the URL (used for dedup / change detection) |
fetchManifest(videoId, ctx) | Returns {src_lang, cues: [{start, end, text}], trackName}; return null when there is no timed track |
collectLines(doc) | Returns each line currently visible on screen; omit it and the built-in YouTube / Bilibili selectors are used instead |
ctx.preferredLang is the source language the user currently prefers.
Available globals
The script runs in the browser extension's isolated world and may only rely on these two objects (do not rely on page globals):
| Object | Methods |
|---|---|
TransBoxExtractors | register({...}) |
TransBoxCaptionHost | cleanCaptionText(raw), parseRawTimedText(raw, lang), preferredLang(), linesFromSelector(css) |
How it takes effect
After enabling the extractor, refresh the page that is playing; the desktop app hands the script to the extension during the handshake.
For the chain the captions take after reaching the desktop app, see Captions & translation. For the end-user side of the browser extension, see Browser native captions.
caption_bridgeis the web caption bridge itself (plugincommunity_web_caption_bridge, plugin IDcommunity.caption.browser); it ships through the Steam Workshop and is not bundled into the official installer. Third parties must not write a second bridge — to add a site, use thecaption_extractoron this page.
