krillplayer-plugin 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/cli.js +44 -40
- package/dist/crypto.d.ts +8 -0
- package/dist/crypto.js +1589 -0
- package/dist/zip.d.ts +13 -0
- package/dist/zip.js +68 -0
- package/package.json +10 -2
- package/skill/krillplayer-plugin/SKILL.md +1 -1
- package/skill/krillplayer-plugin/references/contract.d.ts +45 -40
package/dist/zip.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// krillplayer-plugin/zip:读写插件包(zip),与 `krillplayer-plugin bundle` 用的是同一份代码,只在 Node 里用。
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 按给的顺序把文件写成插件包:只存不压、时间固定为 1980-01-01、文件名按 UTF-8 写,同样的输入在任何机器上得到同样的字节。
|
|
6
|
+
* 与 bundle 打出的插件包逐字节相同的前提是文件与顺序也相同。
|
|
7
|
+
*/
|
|
8
|
+
export function writeZip(entries: { name: string; data: Uint8Array }[]): Buffer;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 读出插件包里的每个文件(文件名 → 内容)。只认只存不压的 zip;找不到目录、目录坏了、有压缩过的文件或 CRC 对不上时抛错。
|
|
12
|
+
*/
|
|
13
|
+
export function readZip(zip: Buffer): Map<string, Buffer>;
|
package/dist/zip.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// packer/zip.ts
|
|
2
|
+
import { crc32 } from "node:zlib";
|
|
3
|
+
var DOS_DATE = 0 << 9 | 1 << 5 | 1;
|
|
4
|
+
var UTF8_NAMES = 2048;
|
|
5
|
+
function writeZip(entries) {
|
|
6
|
+
const locals = [];
|
|
7
|
+
const centrals = [];
|
|
8
|
+
let offset = 0;
|
|
9
|
+
for (const { name, data } of entries) {
|
|
10
|
+
const nameBytes = Buffer.from(name, "utf8");
|
|
11
|
+
const crc = crc32(data);
|
|
12
|
+
const local = Buffer.alloc(30);
|
|
13
|
+
local.writeUInt32LE(67324752, 0);
|
|
14
|
+
local.writeUInt16LE(20, 4);
|
|
15
|
+
local.writeUInt16LE(UTF8_NAMES, 6);
|
|
16
|
+
local.writeUInt16LE(DOS_DATE, 12);
|
|
17
|
+
local.writeUInt32LE(crc, 14);
|
|
18
|
+
local.writeUInt32LE(data.length, 18);
|
|
19
|
+
local.writeUInt32LE(data.length, 22);
|
|
20
|
+
local.writeUInt16LE(nameBytes.length, 26);
|
|
21
|
+
const central = Buffer.alloc(46);
|
|
22
|
+
central.writeUInt32LE(33639248, 0);
|
|
23
|
+
central.writeUInt16LE(20, 4);
|
|
24
|
+
central.writeUInt16LE(20, 6);
|
|
25
|
+
central.writeUInt16LE(UTF8_NAMES, 8);
|
|
26
|
+
central.writeUInt16LE(DOS_DATE, 14);
|
|
27
|
+
central.writeUInt32LE(crc, 16);
|
|
28
|
+
central.writeUInt32LE(data.length, 20);
|
|
29
|
+
central.writeUInt32LE(data.length, 24);
|
|
30
|
+
central.writeUInt16LE(nameBytes.length, 28);
|
|
31
|
+
central.writeUInt32LE(offset, 42);
|
|
32
|
+
locals.push(local, nameBytes, Buffer.from(data));
|
|
33
|
+
centrals.push(central, nameBytes);
|
|
34
|
+
offset += local.length + nameBytes.length + data.length;
|
|
35
|
+
}
|
|
36
|
+
const directory = Buffer.concat(centrals);
|
|
37
|
+
const end = Buffer.alloc(22);
|
|
38
|
+
end.writeUInt32LE(101010256, 0);
|
|
39
|
+
end.writeUInt16LE(entries.length, 8);
|
|
40
|
+
end.writeUInt16LE(entries.length, 10);
|
|
41
|
+
end.writeUInt32LE(directory.length, 12);
|
|
42
|
+
end.writeUInt32LE(offset, 16);
|
|
43
|
+
return Buffer.concat([...locals, directory, end]);
|
|
44
|
+
}
|
|
45
|
+
function readZip(zip) {
|
|
46
|
+
const end = zip.length - 22;
|
|
47
|
+
if (end < 0 || zip.readUInt32LE(end) !== 101010256) throw new Error("not a plugin zip (end of central directory not found)");
|
|
48
|
+
const files = /* @__PURE__ */ new Map();
|
|
49
|
+
let position = zip.readUInt32LE(end + 16);
|
|
50
|
+
for (let index = 0; index < zip.readUInt16LE(end + 10); index += 1) {
|
|
51
|
+
if (zip.readUInt32LE(position) !== 33639248) throw new Error("corrupt central directory");
|
|
52
|
+
const nameLength = zip.readUInt16LE(position + 28);
|
|
53
|
+
const name = zip.toString("utf8", position + 46, position + 46 + nameLength);
|
|
54
|
+
if (zip.readUInt16LE(position + 10) !== 0) throw new Error(`${name} is compressed; plugin zips are stored only`);
|
|
55
|
+
const size = zip.readUInt32LE(position + 24);
|
|
56
|
+
const local = zip.readUInt32LE(position + 42);
|
|
57
|
+
const start = local + 30 + zip.readUInt16LE(local + 26) + zip.readUInt16LE(local + 28);
|
|
58
|
+
const data = zip.subarray(start, start + size);
|
|
59
|
+
if (crc32(data) !== zip.readUInt32LE(position + 16)) throw new Error(`${name} fails its CRC`);
|
|
60
|
+
files.set(name, data);
|
|
61
|
+
position += 46 + nameLength + zip.readUInt16LE(position + 30) + zip.readUInt16LE(position + 32);
|
|
62
|
+
}
|
|
63
|
+
return files;
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
readZip,
|
|
67
|
+
writeZip
|
|
68
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "krillplayer-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Write, pack, record and test KrillPlayer source plugins on the App's own QuickJS-ng engine, with an AI skill.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://krillplayer.kami.asia",
|
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
".": {
|
|
17
17
|
"types": "./skill/krillplayer-plugin/references/contract.d.ts"
|
|
18
18
|
},
|
|
19
|
+
"./zip": {
|
|
20
|
+
"types": "./dist/zip.d.ts",
|
|
21
|
+
"default": "./dist/zip.js"
|
|
22
|
+
},
|
|
23
|
+
"./crypto": {
|
|
24
|
+
"types": "./dist/crypto.d.ts",
|
|
25
|
+
"default": "./dist/crypto.js"
|
|
26
|
+
},
|
|
19
27
|
"./package.json": "./package.json"
|
|
20
28
|
},
|
|
21
29
|
"files": [
|
|
@@ -33,6 +41,6 @@
|
|
|
33
41
|
"eslint": "9.39.5"
|
|
34
42
|
},
|
|
35
43
|
"optionalDependencies": {
|
|
36
|
-
"@krillplayer/plugin-engine-darwin-arm64": "0.
|
|
44
|
+
"@krillplayer/plugin-engine-darwin-arm64": "0.3.0"
|
|
37
45
|
}
|
|
38
46
|
}
|
|
@@ -40,7 +40,7 @@ cd <目录> && npm install && npx krillplayer-plugin check
|
|
|
40
40
|
先弄清来源有什么,再动代码:
|
|
41
41
|
|
|
42
42
|
- **种类**:照 [choosing-a-kind.md](references/choosing-a-kind.md) 的问题按顺序问,给来源里的每样东西定一个种类(频道、合集、条目各自的哪一种)。哪个都不像时不要硬套。
|
|
43
|
-
- **槽位**:大多数来源导出 `browse`(`list` 必须有,`search`、`channel`、`collection`、`schedule` 按需)与 `play`(`start`)。插件只交数据,不交版式:有几份列表(推荐、分区、排行)的导出 `browse.lists`,交几份具名列表,`list`、`parameters`、`options` 多收一个列表的 id(`BrowseListsSlot`);只有一份的不导出 `lists`(`BrowseSlot`)。来源页怎么画由 App
|
|
43
|
+
- **槽位**:大多数来源导出 `browse`(`list` 必须有,`search`、`channel`、`collection`、`schedule` 按需)与 `play`(`start`)。插件只交数据,不交版式:有几份列表(推荐、分区、排行)的导出 `browse.lists`,交几份具名列表,`list`、`parameters`、`options` 多收一个列表的 id(`BrowseListsSlot`);只有一份的不导出 `lists`(`BrowseSlot`)。来源页怎么画由 App 定,没有拼页面的槽位。播放器的侧栏(相关推荐、评论、选集)与卡片上的操作导出 `views`(`panel`、`action`),在清单的 `contributes.playerPanels`、`cardActions` 里按条目种类声明:`panel` 交一串条目(`{ kind: "entries", entries }`)或一串评论(`{ kind: "comments", comments }`),`action` 交一句话(`{ kind: "message", message }`)或一串条目,长相都由 App 定(`ViewsSlot`)。认分享链接导出顶层的 `resolve`;开播状态导出 `status`;要登录导出 `login`。能按作品回答有没有可播版本的来源导出 `resources`(`find`,返回版本,不是条目)。App 不整库扫描来源,没有列出全部内容的槽位。只给作品清单(榜单)的目录插件只导出 `browse`,电影与剧集带上外部 `ids`,App 就把它们当作品,版本由别的来源给。函数名与参数只照 `contract.d.ts` 里的 `BrowseListsSlot`、`BrowseSlot`、`PlaySlot` 等接口写。
|
|
44
44
|
- **App 尚未使用**:`contract.d.ts` 里行尾注释标着「App 尚未使用」的函数与字段,契约里已经有了,这一版的 App 还没接上:导出了这类函数,打包与试跑照常通过,但会打一条 `WARN`,App 不会调它;这类字段给了也不会被读。先把标注之外的做好,标注的按来源有的给,别为了它们改种类或 id。
|
|
45
45
|
- **id**:每个频道、合集、条目的 id 由你定,要稳定(之后改 id 等于让用户的订阅、收藏、续播全部失效)。同一来源里能起播的 id 不重复;直播条目的 id 也由你给。
|
|
46
46
|
- **主机**:插件自己经 `krillplayer.http.request` 发的请求只能去清单 `hosts` 里的主机,按主机名精确匹配,不分大小写,不看端口,**不含子域名**(`api.example.com` 与 `example.com` 要分别写),重定向的每一跳都查。`hosts` 只管插件自己的请求:`play.start` 交给播放器的流地址、`image` 等图片地址不用写进去,播放器拉流时的重定向也不查。用户自己填的服务器地址:声明 `userProvidedURLs: true`,并在 `parameters` 里声明一个 `kind: "url"` 的实例参数。
|
|
@@ -23,7 +23,7 @@ export interface Paged<T> {
|
|
|
23
23
|
export type Ids = Record<string, string>;
|
|
24
24
|
|
|
25
25
|
// 能力由打包器按导出的函数生成(SLOT_RULES),插件不手写。
|
|
26
|
-
export type Capability = "browse" | "music" | "play" | "resolve" | "resources" | "subtitles" | "subtitleSearch" | "danmaku" | "danmakuMatch" | "status" | "login" | "playbackReport" | "
|
|
26
|
+
export type Capability = "browse" | "music" | "play" | "resolve" | "resources" | "subtitles" | "subtitleSearch" | "danmaku" | "danmakuMatch" | "status" | "login" | "playbackReport" | "danmakuSend" | "browseLists" | "playerPanels" | "cardActions";
|
|
27
27
|
|
|
28
28
|
// 内容对象。通用域三样结构:频道、合集、条目,每个种类一个类型,只带属于它的字段。
|
|
29
29
|
// 种类的取值是内核定死的词表,插件不能自造。比插件旧的 App 遇到不认识的种类时跳过数组里的那一项、把可选字段当作没给;
|
|
@@ -384,7 +384,7 @@ export type MusicKind = "artist" | "album" | "playlist" | "song" | "station";
|
|
|
384
384
|
export interface MusicSection {
|
|
385
385
|
id: string;
|
|
386
386
|
title: string;
|
|
387
|
-
kind: MusicKind;
|
|
387
|
+
kind: MusicKind;
|
|
388
388
|
}
|
|
389
389
|
|
|
390
390
|
export type MusicEntry =
|
|
@@ -504,7 +504,7 @@ export interface ParameterCondition {
|
|
|
504
504
|
values: string[];
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
-
// 贡献点:插件只声明往哪里加、对哪些种类的条目生效,内容在 views
|
|
507
|
+
// 贡献点:插件只声明往哪里加、对哪些种类的条目生效,内容在 views 槽位里给(交数据,App 画)。
|
|
508
508
|
// 播放器面板经 views.panel 取,卡片操作经 views.action 执行;kinds 之外的条目上不出现,
|
|
509
509
|
// 过滤掉内核不认识的种类后一个不剩时这一项不显示。
|
|
510
510
|
// backgroundTasks:插件在后台要做的事与建议周期(秒)。只认 task 为 "status"(查订阅频道的
|
|
@@ -591,7 +591,10 @@ export interface PlayableSubtitle {
|
|
|
591
591
|
headers?: Record<string, string>;
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
-
// container
|
|
594
|
+
// container 知道就给,视频引擎把它当格式提示交给播放引擎,并用它认出 HLS;不认识的取值当作没给,引擎再看地址后缀。
|
|
595
|
+
// audioURL 是这一路单独的音轨,给了它 url 就只有画面。两个地址都是 http 或 https(不收 krillplayer.files.playable 给的地址),
|
|
596
|
+
// 都指向分片 MP4:第一个顶层盒子是 ftyp,moov 之后、第一个 moof 或 mdat 之前有顶层的 sidx,moov 在前 64 MiB 里;服务器认 Range。
|
|
597
|
+
// 缺一样这一路就播不了(separateAudioUnindexed)。两个地址带同一组 headers。
|
|
595
598
|
export interface PlayableStream {
|
|
596
599
|
quality: string;
|
|
597
600
|
url: string;
|
|
@@ -646,48 +649,51 @@ export type PlayableSegmentKind = "intro" | "outro" | "chapter";
|
|
|
646
649
|
|
|
647
650
|
export type PlayableDecryptionMethod = "cencAesCtr";
|
|
648
651
|
|
|
649
|
-
//
|
|
650
|
-
//
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
caption?: string;
|
|
657
|
-
image?: string;
|
|
658
|
-
text?: string;
|
|
652
|
+
// 面板里的一条评论(views.panel 交 comments 时):id 在这个条目的评论里唯一,翻页时内核按它去重;
|
|
653
|
+
// author 是作者名,avatar 是作者头像,time 是发表时刻(Unix 秒),likes 是点赞数。怎么画由 App 定。
|
|
654
|
+
export interface Comment {
|
|
655
|
+
id: string;
|
|
656
|
+
author: string;
|
|
657
|
+
text: string;
|
|
658
|
+
avatar?: string; // App 尚未使用
|
|
659
659
|
time?: number;
|
|
660
|
-
|
|
660
|
+
likes?: number; // 整数
|
|
661
661
|
}
|
|
662
662
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
//
|
|
666
|
-
export interface
|
|
667
|
-
|
|
663
|
+
// 播放器面板的一页(views.panel):一串条目,或一串评论,不交版式,App 用通用样式画。
|
|
664
|
+
// title 是这串条目自己的名字(比如选集所在的合集),没有时 App 用清单里面板的标题。
|
|
665
|
+
// next 有值时内核滚到底再要下一页,把它原样放进下一次请求的 cursor;maxAge 是这一页可以缓存几秒。
|
|
666
|
+
export interface EntriesPanel {
|
|
667
|
+
kind: "entries";
|
|
668
668
|
title?: string;
|
|
669
|
-
|
|
669
|
+
entries: Entry[];
|
|
670
|
+
next?: string;
|
|
671
|
+
maxAge?: number;
|
|
670
672
|
}
|
|
671
673
|
|
|
672
|
-
export
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
// next 有值时内核滚到底再要下一页,把它原样放进下一次请求的 cursor:下一页的第一个分区与上一页最后一个分区布局与标题相同时接在后面。
|
|
676
|
-
// empty 是没有分区时空状态里的说明。Swift 里叫 PageContent:内核校验后的页面类型叫 ComponentPage。
|
|
677
|
-
export interface ComponentPage {
|
|
678
|
-
title?: string;
|
|
679
|
-
filters?: Parameter[];
|
|
680
|
-
sections: Section[];
|
|
674
|
+
export interface CommentsPanel {
|
|
675
|
+
kind: "comments";
|
|
676
|
+
comments: Comment[];
|
|
681
677
|
next?: string;
|
|
682
678
|
maxAge?: number;
|
|
683
|
-
empty?: string;
|
|
684
679
|
}
|
|
685
680
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
681
|
+
export type PanelPage = EntriesPanel | CommentsPanel;
|
|
682
|
+
|
|
683
|
+
// 卡片操作的结果(views.action):一句给用户看的话,或一串条目(App 画成列表,title 是这串条目的名字)。
|
|
684
|
+
export interface ActionMessage {
|
|
685
|
+
kind: "message";
|
|
686
|
+
message: string;
|
|
689
687
|
}
|
|
690
688
|
|
|
689
|
+
export interface ActionEntries {
|
|
690
|
+
kind: "entries";
|
|
691
|
+
title?: string;
|
|
692
|
+
entries: Entry[];
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
export type ActionResult = ActionMessage | ActionEntries;
|
|
696
|
+
|
|
691
697
|
// 状态槽位的一项:一批频道 id 进,每个 id 一项出,顺序不限。
|
|
692
698
|
// offline 时 offlineReason 说明为什么不在播:notLive 未开播、rerun 在放轮播或录像、gone 频道已不存在(订阅标成失效)。
|
|
693
699
|
// unknown 时 unknownReason 说明为什么查不出:failed 来源答非所问或出错、rateLimited 被限流(retryAfter 是来源要求等待的秒数)、
|
|
@@ -1424,14 +1430,13 @@ export interface SubtitlesSlot {
|
|
|
1424
1430
|
fetch(krillplayer: KrillPlayer, trackId: string, itemId?: string): Promise<Subtitle>;
|
|
1425
1431
|
}
|
|
1426
1432
|
|
|
1427
|
-
// views
|
|
1428
|
-
//
|
|
1429
|
-
|
|
1430
|
-
export interface
|
|
1431
|
-
export interface ActionRequest { action: string; item?: string; channel?: string }
|
|
1433
|
+
// views 槽位:播放器面板与卡片操作,都只交数据,App 画。cursor 是上一页给的 next,第一页不给;
|
|
1434
|
+
// panel 与 action 的 id 来自清单的贡献点声明,item 是来源内的条目 id。插件拼整页的 page 去掉了,来源页由 App 按具名列表画。
|
|
1435
|
+
export interface PanelRequest { panel: string; item: string; cursor?: string }
|
|
1436
|
+
export interface ActionRequest { action: string; item: string }
|
|
1432
1437
|
|
|
1433
1438
|
export interface ViewsSlot {
|
|
1434
|
-
panel?(krillplayer: KrillPlayer, request: PanelRequest): Promise<
|
|
1439
|
+
panel?(krillplayer: KrillPlayer, request: PanelRequest): Promise<PanelPage>;
|
|
1435
1440
|
action?(krillplayer: KrillPlayer, request: ActionRequest): Promise<ActionResult>;
|
|
1436
1441
|
}
|
|
1437
1442
|
|