← Back to README · 简体中文 · Architecture Spec
This guide is structured as an exact, self-contained specification so both human developers and AI coding agents (Claude Code, Codex, Cursor, Antigravity, etc.) can scaffold, validate, package, and publish MikuTV plugins without guesswork.
MikuTV discovers plugins on GitHub via topic mikutv-plugin (or direct owner/repo lookup) and installs strictly verified archives.
| Requirement | Rule enforced by internal/plugin/ |
|---|---|
| GitHub Topic | Add repository topic mikutv-plugin (and keep repo non-archived) to appear in Settings → Plugins → Discover. |
| Release Asset | Publish a GitHub Release with an asset named exactly plugin.zip (max 8 MiB). |
| Version Alignment | Release tag must match v<version> in plugin.json (e.g. tag v1.0.0 ↔ "version": "1.0.0", strict canonical semver). |
| Archive Hygiene | All files live at the archive root (plugin.json at root, NOT wrapped inside a top-level folder). No symlinks, no backslashes, no control chars, no case-insensitive duplicate paths. |
| Manifest Integrity | Strict JSON decoding (DisallowUnknownFields). Unknown keys fail validation immediately. |
| Integrity & Ownership | Host records SHA-256 digest and binds plugin.json id to its source repository on install. Updates cannot change kind. |
{
"id": "my-plugin",
"name": "My Plugin",
"description": "Concise one-line description.",
"kind": "source",
"version": "1.0.0",
"apiVersion": 1,
"minAppVersion": "0.1.0",
"license": "Apache-2.0",
"artwork": {
"cover": "cover.png"
}
}id: matches^[a-z0-9][a-z0-9._-]{0,127}$apiVersion: currently1minAppVersion: semantic version ("0.1.0")artwork.cover: optional PNG/JPEG/WebP inside the zip- Include a root
LICENSE/LICENSE.txt/NOTICEfile so MikuTV displays your license cleanly in Settings → About MikuTV.
Source plugins are ES modules (.js or .mjs) executed inside MikuTV's isolated pure-Go moejs sandbox.
{
"id": "example-source",
"name": "Example Source",
"description": "Video catalog adapter.",
"kind": "source",
"version": "1.0.0",
"apiVersion": 1,
"minAppVersion": "0.1.0",
"license": "Apache-2.0",
"main": "index.js",
"permissions": {
"network": [
"api.example.com",
"*.cdn.example.com"
]
},
"authentication": {
"methods": ["qrCode"],
"presentation": {
"guestTitle": "Sign in",
"guestDescription": "Scan with the companion mobile app."
}
},
"locales": {
"en": {
"name": "Example Source",
"description": "Video catalog adapter."
}
},
"capabilities": [
"catalog.browse",
"catalog.item",
"catalog.search",
"playback.resolve",
"account.signIn"
]
}- Every outbound
fetch/ WebSocket host MUST be declared inpermissions.network. - Users explicitly review this list before installing and again whenever an update adds new domains.
- Private IPs, loopback (
127.0.0.1), link-local, CGNAT (100.64.0.0/10), andlocalhostare rejected in staticpermissions.network. - Wildcards (
*.example.com) require a valid eTLD+1 base domain. - Self-Hosted User Server Origin (
authentication.serverURL): When a source declares"methods": ["credentials"]and"serverURL": "required"(or"optional"),permissions.networkmay be empty. At sign-in time, MikuTV validates the user-enteredhttp://orhttps://address and grants a strict per-session single-origin allowlist (exactscheme://host:portonly) forfetch, artwork, and playback requests — including LAN servers — while still blocking every other LAN IP, port, or undeclared domain.
By default, MikuTV fetches external artwork URLs without cookies and without following redirects. Starting in host version 0.1.4, sign-in source plugins whose thumbnails or backdrops live behind cookie-authenticated HTTPS endpoints (such as cloud drives) may opt in via permissions.artwork:
"minAppVersion": "0.1.4",
"permissions": {
"network": [
"api.example.com",
"*.cdn.example.com"
],
"artwork": {
"hosts": [
"api.example.com"
],
"referer": "https://api.example.com/"
}
}- Requires the
account.signIncapability and"minAppVersion": "0.1.4"(or higher). hostsaccepts 1–16 exact public HTTPS hostnames (wildcards such as*.example.comare rejected), and every host MUST also be permitted bypermissions.network.- Optional
refererMUST be a validhttps://URL (max 512 characters) whose host is permitted bypermissions.network. - At runtime, MikuTV attaches the active session's cookies and declared
Refereronly to exact declaredartwork.hosts, follows up to 5 validated HTTPS redirects, and strips cookies on any cross-origin redirect. Non-declared hosts and plugins withoutpermissions.artworkkeep the zero-cookie, no-redirect default.
Source plugins targeting self-hosted media servers (e.g. Jellyfin) or username/password accounts declare "credentials" in authentication.methods:
"authentication": {
"methods": ["credentials"],
"serverURL": "required",
"presentation": {
"guestTitle": "Connect to Jellyfin",
"guestDescription": "Sign in with your Jellyfin server URL and account.",
"credentialsTitle": "Sign In to Jellyfin",
"credentialsDescription": "Enter your server URL, username, and password.",
"serverURLPlaceholder": "http://192.168.1.10:8096",
"usernamePlaceholder": "Username"
}
}- Export
signInWithCredentials(req)receiving{ serverURL, username, password }and returning{ account, secret }. - MikuTV stores
secretand the normalizedserverOriginin the tvOS Keychain, passessecretdirectly torestoreAccount(secret)andsignOut(secret), and automatically injectsreq.secretinto all authenticated read and write calls for that session (includingbrowse,getItem,search,searchSuggest,readSeries,readLive,readCreator,readFollowing,videoComments,videoFavoriteFolders,resolvePlayback,readSubtitles,readDanmaku,readDanmakuRules,readAccount, and account/playback mutations). - Reference implementation:
yuchanns/mikutv-plugin-jellyfin.
Inside moejs, plugins have standard ES module syntax, restricted fetch, and the host global object (internal/plugin/host.go, internal/plugin/host_crypto.go, internal/plugin/cache.go):
host.storage.get(key)/host.storage.set(key, value)/host.storage.delete(key)— Per-plugin persistent key-value store (8 KiB total quota).host.cache.get(key)/host.cache.set(key, value, ttlSeconds?)/host.cache.delete(key)/host.cache.clear()— Session-scoped in-memory LRU + TTL cache shared across exported calls (minAppVersion: "0.1.5"). Capped at 4 MiB total, 256 KiB per entry (key + value), and 4096 live keys; omittingttlSeconds(or0) keeps the entry until LRU eviction. Automatically cleared on account switch or entry close, and isolated as a no-op duringaccount.signIn.host.locale.current()— Returns the currently active normalized BCP-47 language tag (e.g."zh-Hans","en","ja"), allowing source plugins to localize tab titles, shelf labels, and API requests dynamically.host.crypto— Built-in cryptographic primitives (all"bytes"outputs return an indexableUint8Array):sha256(input)/md5(input)— Accepts a UTF-8 string orUint8Array(up to 1 MiB) and returns a lowercase hex digest.hmac(algo, key, data)— Supports"sha1","sha256", and"md5", returning lowercase hex.aesEncrypt(opts)/aesDecrypt(opts)— Supportsmode"cbc","ecb","ctr", and"gcm",padding"pkcs7"(default forcbc/ecb) or"none", and field encodings"utf8","hex","base64", and"bytes"(Uint8Array). Input capped at 1 MiB for encryption and 4 MiB for decryption.rsaEncrypt(opts)— Supportsmode"oaep-sha256"(default),"pkcs1v15", and"raw", keyed by eitherpem(PEM or base64 SPKI/PKCS#1 DER) ormodulusHex+exponentHex(512–4096 bits), withoutputEncoding"hex"(default),"base64", or"bytes".encryptRSAOAEP(base64SPKIDer, plaintext)— Shorthand returning hex-encoded RSA-OAEP-SHA256 ciphertext.randomBytes(length, encoding?)— Cryptographic random bytes (1–1024),encodingdefaults to"hex"("hex","base64","utf8", or"bytes").
host.compress.inflateZlib(bytes)/host.compress.gunzip(bytes)— Zlib / Gzip decompression (up to 4 MiB);gunzipreturns aUint8Array.
Source plugins can serve audio-only or dual audio/video media ("minAppVersion": "0.1.5"):
- Audio-Only Streams: In
resolvePlayback, return aPlaybackStream(format: "direct"or"hls") with emptyvideo.resource.urlsand a populatedaudiotrack (resource.urls, plus optionalcontentType/codec/bandwidth). MikuTV switches automatically to the ambient audio stage with large artwork, background playback, sidebar "Now Playing" entry, and 48 MiB in-memory direct buffering. - Synced Lyrics: Reuse
playback.subtitlesby listing lyric tracks inPlaybackPlan.subtitles(optionalresource.urls) and returning{ cues: [{ start, end, text }] }fromreadSubtitles(embed\ninsidetextfor bilingual/multi-line lyrics). - Audio/Video Switching: Return
availableKinds: ["audio", "video"]inPlaybackPlan. When the user switches modes, MikuTV invokesresolvePlaybackwithreq.mediaKind("audio"or"video"). - Playback Modes & Auto-Queue (
playback.modes): Declare"playback.modes"incapabilities(no extra export required) to enable loop-all, loop-one, and shuffle controls and automatically queue the surrounding list when starting an item from Home, Search, Rankings, Creator, or Library views. - Audio Progress Reporting: When
playback.progressis declared, audio-only playback invokesreportPlaybackwithdata.seconds = 0right after start (without writing a local resume position), followed by actual elapseddata.seconds(anddata.finished = truewhen completed) on finish or track change.
Source plugins may declare an optional top-level presentation object in plugin.json — with per-language overrides under locales.<tag>.presentation — so audio, podcast, or cloud-drive sources use natural domain copy instead of generic video labels:
- Customizable groups include
home(picks, continue, ranking copy),sections(library,history,favorites,folderUnit,watchLater,tracking,courses, guest copy),search,creator,detail,series, pluscreatorGroupTitle,membership, andmobileApp. - For the exact field schema, see
SourcePresentationininternal/provider/catalog.go.
Every capability declared in capabilities MUST have its matching named export(s) in main. Undeclared capabilities are not invoked; missing exports fail package open.
| Capability | Required Export(s) | Dependency Constraint |
|---|---|---|
catalog.browse |
browse |
— |
catalog.item |
getItem |
— |
catalog.search |
search |
— |
catalog.searchSuggest |
searchSuggest |
Requires catalog.search |
catalog.series |
readSeries |
— |
catalog.live |
readLive |
— |
catalog.creator |
readCreator |
— |
catalog.videoComments |
videoComments |
— |
catalog.following |
readFollowing |
Requires account.signIn |
catalog.library |
readAccount |
Requires account.signIn |
playback.resolve |
resolvePlayback |
— |
playback.progress |
reportPlayback |
Requires account.signIn |
playback.danmaku |
readDanmaku |
— |
playback.subtitles |
readSubtitles |
— |
playback.modes |
— | — |
live.chat |
connectLiveChat |
— |
live.chatWrite |
sendLiveChat |
Requires live.chat + account.signIn |
account.signIn |
restoreAccount, signOut, plus beginSignIn & pollSignIn (for "qrCode") and/or signInWithCredentials (for "credentials") |
Requires authentication.methods ("qrCode" and/or "credentials") |
account.videoInteraction |
editVideo |
Requires account.signIn |
account.videoFavorites |
videoFavoriteFolders, editVideoFavoriteFolders |
Requires account.signIn |
account.danmaku |
postDanmaku |
Requires account.signIn |
account.danmakuRules |
readDanmakuRules, addDanmakuRule, removeDanmakuRule |
Requires account.signIn |
account.followCreator |
followCreator |
Requires account.signIn |
account.trackSeries |
trackSeries |
— |
account.history / watchLater / favorites / tracking / courses / notifications |
readAccount |
Requires account.signIn |
account.editFavoriteFolders |
editFavoriteFolder |
Requires account.favorites |
account.editHistory / editWatchLater / editTracking |
removeAccountItems |
Requires matching read capability |
account.editNotifications |
markNotificationsRead |
Requires account.notifications |
account.privateMessages |
readPrivateConversations, readPrivateMessages |
Requires account.signIn |
account.writePrivateMessages |
sendPrivateMessage, markPrivateMessagesRead |
Requires account.privateMessages + account.signIn |
For exact request and response JSON schemas of each export, inspect the Go types in internal/provider/ and the invocation adapters in internal/plugin/.
Theme plugins are pure declarative JSON (theme.json, max 64 KiB) loaded directly in Go without starting JavaScript.
{
"id": "my-theme",
"name": "My Theme",
"description": "Custom palette for MikuTV.",
"kind": "theme",
"version": "1.0.0",
"apiVersion": 1,
"minAppVersion": "0.1.0",
"license": "Apache-2.0",
"theme": "theme.json"
}schemaVersion:1base:"mikutv-dark"or"mikutv-light"(unmodified tokens inherit cleanly from the base)appearance:"dark"or"light"colors: overrides any of the 46 semantic tokens (surface,text,accent,border,focus,selected,hover,pressed,disabled,status,overlay,playback,decoration) using#RRGGBBor#RRGGBBAA.- Automatic WCAG Contrast Gate: MikuTV validates contrast ratios for primary text, focus rings, selected states, and accent foregrounds when opening the package; failing palettes are rejected with
ErrContrastFailed. - Reference implementations: any of the 10 official
yuchanns/mikutv-theme-*repositories.
MikuTV includes built-in Simplified Chinese (zh-Hans) and English (en) UI strings and follows the tvOS system language by default. Community and official language packs are pure declarative JSON (locale.json, max 256 KiB) loaded directly in Go without starting JavaScript.
{
"id": "mikutv-locale-ja",
"name": "Japanese (日本語)",
"description": "Japanese UI localization for MikuTV.",
"kind": "locale",
"version": "1.0.0",
"apiVersion": 1,
"minAppVersion": "0.1.0",
"license": "Apache-2.0",
"language": "ja",
"nativeName": "日本語",
"locale": "locale.json"
}language(inplugin.json): canonical BCP-47 tag (e.g."ja","ko","zh-Hant","fr","es").nativeName(inplugin.json): native endonym shown in Settings → Appearance & Motion → Language (e.g."日本語","한국어","繁體中文").locale.json: sparse or complete JSON object directly mirroringinternal/ui/assets/labels.en.json. Any omitted key falls back cleanly to built-in English, and canonical settings section order/icons are preserved automatically.- Zero-restart hot-swap & Follow System: Once installed, a locale pack can be selected immediately in Settings, or activated automatically in Follow System mode when tvOS
NSLocale.preferredLanguagesmatches itslanguagetag. - Reference implementation:
yuchanns/mikutv-locale-ja.
Put the plugin in a public GitHub repository with plugin.json and LICENSE at the root, and add the topic mikutv-plugin (plus mikutv-theme for themes or mikutv-locale for language packs). MikuTV reads the latest non-draft GitHub Release whose tag matches v<version> in plugin.json and installs its plugin.zip asset.
Add .github/workflows/release.yml using yuchanns/release-mikutv-plugin. Pushing a v* tag validates plugin.json, builds a deterministic plugin.zip and SHA256SUMS.txt, and publishes the GitHub Release (automatically marking SemVer prerelease tags as prereleases):
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: yuchanns/release-mikutv-plugin@v1- Read authoritative Go contracts first:
- Manifest & archive validation:
internal/plugin/manifest.go,internal/plugin/package.go,internal/plugin/theme.go,internal/plugin/locale.go - Provider request/response structs:
internal/provider/*.go - Theme schema & contrast rules:
internal/theme/theme.go,internal/theme/parse.go - UI locale baseline keys:
internal/ui/assets/labels.en.json
- Manifest & archive validation:
- Scaffold the repository: keep
plugin.json,LICENSE, and.js/.jsonfiles at the root (only pure JS,fetch, andhost.*are available insidemoejs), and addplugin.zipandSHA256SUMS.txtto.gitignore. - Validate with MikuTV's Go loader: run a Go test against
github.com/yuchanns/MikuTV/internal/plugincallingplugin.InspectPackagealong withplugin.Open(source),plugin.OpenTheme(theme), orplugin.OpenLocale(locale) to confirm zero unknown fields, valid host allowlist, contrast/locale rules, and declared exports; cover JS exports with mocked HTTP fixtures. - Tag and publish: bump
versioninplugin.json, push tomain, and push the matching tag:Once the workflow finishes,git tag -a v1.0.0 -m "Release v1.0.0" git push origin v1.0.0GET https://api.github.com/repos/<owner>/<repo>/releases/latestservesplugin.zipundertag_name == "v" + version.