krillplayer-plugin 0.1.0 → 0.2.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 +5 -0
- package/dist/cli.js +949 -636
- package/package.json +3 -2
- package/skill/krillplayer-plugin/SKILL.md +2 -1
- package/skill/krillplayer-plugin/assets/samples/file-share/plugin.ts +1 -20
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-connect.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-decode.json +19 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-content-rejected.json +31 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-login-expired.json +31 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-muted.json +31 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-not-logged-in.json +14 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-other.json +31 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-rate-limited.json +31 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-sent.json +28 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/manifest.ts +2 -1
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/plugin.ts +40 -1
- package/skill/krillplayer-plugin/assets/samples/media-server/plugin.ts +1 -35
- package/skill/krillplayer-plugin/assets/samples/network-share/plugin.ts +1 -20
- package/skill/krillplayer-plugin/references/choosing-a-kind.md +2 -2
- package/skill/krillplayer-plugin/references/contract.d.ts +80 -112
- package/skill/krillplayer-plugin/references/errors-and-fixes.md +1 -1
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-empty-folder.json +0 -11
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-gone-not-found.json +0 -12
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-lists-subfolders-and-media.json +0 -28
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-second-page.json +0 -22
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-skips-subtitles.json +0 -21
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-root-first-page.json +0 -25
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-root-second-page.json +0 -22
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-everything-first-page.json +0 -74
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-everything-last-page.json +0 -86
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-nothing-new.json +0 -12
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-since-a-token-with-a-removal.json +0 -88
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-ids-first-page.json +0 -15
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-ids-last-page.json +0 -14
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-empty-folder.json +0 -60
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-folder-gives-size-and-modified-time.json +0 -78
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-folder-gone-not-found.json +0 -60
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-folder-second-page.json +0 -71
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-read-a-range.json +0 -62
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-read-an-info-file.json +0 -62
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-read-file-gone-not-found.json +0 -62
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-root.json +0 -84
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-source-offline-retryable.json +0 -61
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "krillplayer-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"templates",
|
|
26
26
|
"skill",
|
|
27
27
|
"README.md",
|
|
28
|
+
"CHANGELOG.md",
|
|
28
29
|
"LICENSE"
|
|
29
30
|
],
|
|
30
31
|
"dependencies": {
|
|
@@ -32,6 +33,6 @@
|
|
|
32
33
|
"eslint": "9.39.5"
|
|
33
34
|
},
|
|
34
35
|
"optionalDependencies": {
|
|
35
|
-
"@krillplayer/plugin-engine-darwin-arm64": "0.
|
|
36
|
+
"@krillplayer/plugin-engine-darwin-arm64": "0.2.0"
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -40,11 +40,12 @@ 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
|
|
43
|
+
- **槽位**:大多数来源导出 `browse`(`list` 必须有,`search`、`channel`、`collection`、`schedule` 按需)与 `play`(`start`)。插件只交数据,不交版式:有几份列表(推荐、分区、排行)的导出 `browse.lists`,交几份具名列表,`list`、`parameters`、`options` 多收一个列表的 id(`BrowseListsSlot`);只有一份的不导出 `lists`(`BrowseSlot`)。来源页怎么画由 App 定,没有拼页面的槽位。认分享链接导出顶层的 `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"` 的实例参数。
|
|
47
47
|
- **图片地址**:公网的只取 https(给 http 时改成 https 取),局域网与本机的只在它就是用户填的那台主机时才取,按用户填的协议。App 按「来源实例、去掉尺寸参数后的地址、尺寸档」缓存图片;地址里每次都变的令牌或盐(例如 Subsonic 的 `t`、`s`,Emby 的 `api_key`)写进清单的 `imageCacheIgnoredParameters`,换了令牌仍命中同一份缓存。
|
|
48
|
+
- **来源与登录**:用户在 App 的来源页每添加一次就是一个来源实例,没有实例参数也能加多个(多个账号就是多个来源)。导出 `login` 的插件添加时就能登录,登不登由用户选;不登录什么都看不了的来源在清单写 `loginRequired: true`,添加时就必须登录。确实只能有一个来源的才写 `singleSource: true`。设置项(`settings`)默认所有来源共用一份,要每个来源各一份的那一项写 `perSource: true`。
|
|
48
49
|
- **失败**:每种失败应答(不存在、要登录、地区限制、还没开始、已结束、被拒、暂时失败)给哪个 `PluginErrorKind`。
|
|
49
50
|
|
|
50
51
|
完成判据:对每个要导出的函数,说得出它的入参、返回类型名、每种失败抛哪个 kind;id 的写法定下来;`hosts` 列全。
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 目录的应答是一份 WebDAV 的 PROPFIND(207 Multi-Status),用 krillplayer.formats.xml 解,按命名空间与本地名找元素。
|
|
5
5
|
// 资料库槽位把同一份目录给内核扫描进索引:一次一层,带名字、大小与修改时间,目录不在了抛 notFound。
|
|
6
6
|
import type {
|
|
7
|
-
At, BrowseSlot, CollectionRef, Entry, File, Folder,
|
|
7
|
+
At, BrowseSlot, CollectionRef, Entry, File, Folder, Paged, PlaySlot, XMLNode,
|
|
8
8
|
} from "krillplayer-plugin";
|
|
9
9
|
|
|
10
10
|
const SERVER = "https://dav.example/share/";
|
|
@@ -158,25 +158,6 @@ export const browse = {
|
|
|
158
158
|
},
|
|
159
159
|
} satisfies BrowseSlot;
|
|
160
160
|
|
|
161
|
-
// 资料库:一次列一层,内核自己往下走。文件的 itemId 就是 browse 给的那个 File 的 id(路径),不是音视频的文件不列。
|
|
162
|
-
export const library = {
|
|
163
|
-
async list(krillplayer, dir, cursor) {
|
|
164
|
-
const found = listingOf(krillplayer, dir);
|
|
165
|
-
if (found === undefined) throw krillplayer.error("notFound", "这个文件夹已不在了");
|
|
166
|
-
const entries = found.flatMap((resource): LibraryEntry[] => {
|
|
167
|
-
const times = resource.modified === undefined ? {} : { modified: resource.modified };
|
|
168
|
-
if (resource.directory) return [{ type: "directory", path: resource.path, name: resource.name, ...times }];
|
|
169
|
-
const media = mediaOf(resource);
|
|
170
|
-
if (media === undefined) return [];
|
|
171
|
-
return [{
|
|
172
|
-
type: "file", path: resource.path, name: resource.name, itemId: resource.path, media,
|
|
173
|
-
...(resource.size === undefined ? {} : { size: resource.size }), ...times,
|
|
174
|
-
}];
|
|
175
|
-
});
|
|
176
|
-
return page(entries, cursor);
|
|
177
|
-
},
|
|
178
|
-
} satisfies LibrarySlot;
|
|
179
|
-
|
|
180
161
|
// 文件按路径起播:地址是来源根加上逐段编码的路径。文件不连播,也没有别的线路。
|
|
181
162
|
// 文件不在了抛 notFound:内核给出「文件不在了」的说明,并重扫它所在的目录。
|
|
182
163
|
export const play = {
|
package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-connect.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"slot": "danmaku",
|
|
3
|
+
"call": "connect",
|
|
4
|
+
"args": [
|
|
5
|
+
"session-88231",
|
|
6
|
+
null
|
|
7
|
+
],
|
|
8
|
+
"exchanges": [],
|
|
9
|
+
"output": {
|
|
10
|
+
"url": "wss://danmaku.example/room/session-88231",
|
|
11
|
+
"handshake": [
|
|
12
|
+
{
|
|
13
|
+
"text": "{\"room\":\"session-88231\",\"resume\":null}"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"heartbeat": {
|
|
17
|
+
"frame": {
|
|
18
|
+
"text": "ping"
|
|
19
|
+
},
|
|
20
|
+
"interval": 30
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"slot": "danmaku",
|
|
3
|
+
"call": "decode",
|
|
4
|
+
"args": [
|
|
5
|
+
{
|
|
6
|
+
"text": "{\"user\":\"小鲸\",\"text\":\"晚上好\",\"seq\":42}"
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
"exchanges": [],
|
|
10
|
+
"output": {
|
|
11
|
+
"messages": [
|
|
12
|
+
{
|
|
13
|
+
"content": "晚上好",
|
|
14
|
+
"username": "小鲸"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"resume": "42"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"slot": "danmaku",
|
|
3
|
+
"call": "send",
|
|
4
|
+
"args": [
|
|
5
|
+
"session-88231",
|
|
6
|
+
"买粉加我"
|
|
7
|
+
],
|
|
8
|
+
"exchanges": [
|
|
9
|
+
{
|
|
10
|
+
"request": {
|
|
11
|
+
"method": "POST",
|
|
12
|
+
"url": "https://live.example/room/session-88231/danmaku",
|
|
13
|
+
"body": "{\"text\":\"买粉加我\"}"
|
|
14
|
+
},
|
|
15
|
+
"response": {
|
|
16
|
+
"status": 200,
|
|
17
|
+
"headers": {
|
|
18
|
+
"content-type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
"body": "{\"code\":1010,\"message\":\"内容含有屏蔽词\"}"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"credentials": {
|
|
25
|
+
"token": "REDACTED"
|
|
26
|
+
},
|
|
27
|
+
"error": {
|
|
28
|
+
"kind": "contentRejected",
|
|
29
|
+
"message": "内容含有屏蔽词"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"slot": "danmaku",
|
|
3
|
+
"call": "send",
|
|
4
|
+
"args": [
|
|
5
|
+
"session-88231",
|
|
6
|
+
"晚上好"
|
|
7
|
+
],
|
|
8
|
+
"exchanges": [
|
|
9
|
+
{
|
|
10
|
+
"request": {
|
|
11
|
+
"method": "POST",
|
|
12
|
+
"url": "https://live.example/room/session-88231/danmaku",
|
|
13
|
+
"body": "{\"text\":\"晚上好\"}"
|
|
14
|
+
},
|
|
15
|
+
"response": {
|
|
16
|
+
"status": 200,
|
|
17
|
+
"headers": {
|
|
18
|
+
"content-type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
"body": "{\"code\":1001,\"message\":\"登录已过期\"}"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"credentials": {
|
|
25
|
+
"token": "REDACTED"
|
|
26
|
+
},
|
|
27
|
+
"error": {
|
|
28
|
+
"kind": "loginRequired",
|
|
29
|
+
"message": "登录已过期"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-muted.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"slot": "danmaku",
|
|
3
|
+
"call": "send",
|
|
4
|
+
"args": [
|
|
5
|
+
"session-88231",
|
|
6
|
+
"晚上好"
|
|
7
|
+
],
|
|
8
|
+
"exchanges": [
|
|
9
|
+
{
|
|
10
|
+
"request": {
|
|
11
|
+
"method": "POST",
|
|
12
|
+
"url": "https://live.example/room/session-88231/danmaku",
|
|
13
|
+
"body": "{\"text\":\"晚上好\"}"
|
|
14
|
+
},
|
|
15
|
+
"response": {
|
|
16
|
+
"status": 200,
|
|
17
|
+
"headers": {
|
|
18
|
+
"content-type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
"body": "{\"code\":1003,\"message\":\"你已被房管禁言\"}"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"credentials": {
|
|
25
|
+
"token": "REDACTED"
|
|
26
|
+
},
|
|
27
|
+
"error": {
|
|
28
|
+
"kind": "muted",
|
|
29
|
+
"message": "你已被房管禁言"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-other.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"slot": "danmaku",
|
|
3
|
+
"call": "send",
|
|
4
|
+
"args": [
|
|
5
|
+
"session-88231",
|
|
6
|
+
"晚上好"
|
|
7
|
+
],
|
|
8
|
+
"exchanges": [
|
|
9
|
+
{
|
|
10
|
+
"request": {
|
|
11
|
+
"method": "POST",
|
|
12
|
+
"url": "https://live.example/room/session-88231/danmaku",
|
|
13
|
+
"body": "{\"text\":\"晚上好\"}"
|
|
14
|
+
},
|
|
15
|
+
"response": {
|
|
16
|
+
"status": 503,
|
|
17
|
+
"headers": {
|
|
18
|
+
"content-type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
"body": "{}"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"credentials": {
|
|
25
|
+
"token": "REDACTED"
|
|
26
|
+
},
|
|
27
|
+
"error": {
|
|
28
|
+
"kind": "other",
|
|
29
|
+
"message": "发送接口返回 503"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"slot": "danmaku",
|
|
3
|
+
"call": "send",
|
|
4
|
+
"args": [
|
|
5
|
+
"session-88231",
|
|
6
|
+
"晚上好"
|
|
7
|
+
],
|
|
8
|
+
"exchanges": [
|
|
9
|
+
{
|
|
10
|
+
"request": {
|
|
11
|
+
"method": "POST",
|
|
12
|
+
"url": "https://live.example/room/session-88231/danmaku",
|
|
13
|
+
"body": "{\"text\":\"晚上好\"}"
|
|
14
|
+
},
|
|
15
|
+
"response": {
|
|
16
|
+
"status": 200,
|
|
17
|
+
"headers": {
|
|
18
|
+
"content-type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
"body": "{\"code\":1005,\"message\":\"发送太频繁\"}"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"credentials": {
|
|
25
|
+
"token": "REDACTED"
|
|
26
|
+
},
|
|
27
|
+
"error": {
|
|
28
|
+
"kind": "rateLimited",
|
|
29
|
+
"message": "发送太频繁"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-sent.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"slot": "danmaku",
|
|
3
|
+
"call": "send",
|
|
4
|
+
"args": [
|
|
5
|
+
"session-88231",
|
|
6
|
+
"晚上好"
|
|
7
|
+
],
|
|
8
|
+
"exchanges": [
|
|
9
|
+
{
|
|
10
|
+
"request": {
|
|
11
|
+
"method": "POST",
|
|
12
|
+
"url": "https://live.example/room/session-88231/danmaku",
|
|
13
|
+
"body": "{\"text\":\"晚上好\"}"
|
|
14
|
+
},
|
|
15
|
+
"response": {
|
|
16
|
+
"status": 200,
|
|
17
|
+
"headers": {
|
|
18
|
+
"content-type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
"body": "{\"code\":0}"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"credentials": {
|
|
25
|
+
"token": "REDACTED"
|
|
26
|
+
},
|
|
27
|
+
"output": null
|
|
28
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// 样例:既直播又发视频的平台。数据写死在这里,不出网;主机名都是不存在的 .example。
|
|
2
2
|
// 看点:创作者是频道,带可选的 live(正在播才有)与分栏;直播条目的 id 由插件给(这里是场次号,和频道 id 没有关系),
|
|
3
3
|
// 状态槽位用 liveId 报同一个 id;预告开播后变成直播、结束后变成回放(点播);普通视频归进播放列表;顶层的 resolve 认链接。
|
|
4
|
+
// 直播间有弹幕:connect 给连接规格、decode 一次解一帧;登录后能 send 发一条(#704),平台的回答按 code 换成契约的错误种类。
|
|
4
5
|
import type {
|
|
5
|
-
BrowseSlot, ChannelRef, Creator, Entry, Live, OnDemand, Paged, Playlist, PlaySlot, ResolveFunction, StatusSlot, Upcoming,
|
|
6
|
+
BrowseSlot, ChannelRef, Creator, DanmakuSlot, Entry, Live, OnDemand, Paged, PluginError, Playlist, PlaySlot, ResolveFunction, StatusSlot, Upcoming,
|
|
6
7
|
} from "krillplayer-plugin";
|
|
7
8
|
|
|
8
9
|
const CDN = "https://cdn.example";
|
|
@@ -121,3 +122,41 @@ export const play = {
|
|
|
121
122
|
return { timing: "onDemand", duration: video.duration, lines: [{ name: "主线路", streams: [{ quality: "1080P", url: `${CDN}/video/${itemId}.m3u8` }] }] };
|
|
122
123
|
},
|
|
123
124
|
} satisfies PlaySlot;
|
|
125
|
+
|
|
126
|
+
// 弹幕:连接与解码不出网,帧是 JSON。发弹幕经平台的接口(https://live.example,用例里是录好的应答):
|
|
127
|
+
// code 0 是发出去了;别的 code 换成契约的错误种类,message 原样交给内核显示。插件不重发,同一条不连发、发送间隔由内核守。
|
|
128
|
+
const SEND_REFUSALS: Record<number, PluginError["kind"]> = { 1001: "loginRequired", 1003: "muted", 1005: "rateLimited", 1010: "contentRejected" };
|
|
129
|
+
|
|
130
|
+
export const danmaku = {
|
|
131
|
+
async connect(_krillplayer, itemId, resume) {
|
|
132
|
+
return {
|
|
133
|
+
url: `wss://danmaku.example/room/${itemId}`,
|
|
134
|
+
handshake: [{ text: JSON.stringify({ room: itemId, resume }) }],
|
|
135
|
+
heartbeat: { frame: { text: "ping" }, interval: 30 },
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
decode(_krillplayer, frame) {
|
|
139
|
+
if (frame.text === undefined || frame.text === "pong") return { messages: [] };
|
|
140
|
+
const message = JSON.parse(frame.text) as { user: string; text: string; seq: number };
|
|
141
|
+
return { messages: [{ content: message.text, username: message.user }], resume: String(message.seq) };
|
|
142
|
+
},
|
|
143
|
+
async send(krillplayer, itemId, text) {
|
|
144
|
+
const credentials = krillplayer.credentials.get();
|
|
145
|
+
if (credentials === null) throw krillplayer.error("loginRequired", "登录后才能发弹幕");
|
|
146
|
+
const response = await krillplayer.http.request({
|
|
147
|
+
method: "POST",
|
|
148
|
+
url: `https://live.example/room/${itemId}/danmaku`,
|
|
149
|
+
headers: { authorization: `Bearer ${credentials.token}`, "content-type": "application/json" },
|
|
150
|
+
body: JSON.stringify({ text }),
|
|
151
|
+
});
|
|
152
|
+
if (response.status !== 200) throw krillplayer.error("other", `发送接口返回 ${response.status}`);
|
|
153
|
+
const { code, message } = JSON.parse(new TextDecoder().decode(response.body)) as { code: number; message?: string };
|
|
154
|
+
if (code === 0) return;
|
|
155
|
+
throw krillplayer.error(SEND_REFUSALS[code] ?? "other", message ?? `code ${code}`);
|
|
156
|
+
},
|
|
157
|
+
} satisfies DanmakuSlot;
|
|
158
|
+
|
|
159
|
+
// 表单登录:贴平台给的令牌,send 经 krillplayer.credentials.get() 读到。
|
|
160
|
+
export const login = {
|
|
161
|
+
methods: () => [{ kind: "fields" as const, title: "令牌", fields: [{ name: "token", title: "令牌", secret: true }] }],
|
|
162
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// 看点:电影、剧集、季、集、影视合集、文件夹与文件各是一个种类;层级用字段表示,不拼进 id;
|
|
3
3
|
// 同一部电影的几个文件是一个条目的几个版本;集按播放顺序排好,at.around 从那一集开始往后给。
|
|
4
4
|
import type {
|
|
5
|
-
At, BrowseSlot, Collection, CollectionRef, Entry, Episode, File, Item,
|
|
5
|
+
At, BrowseSlot, Collection, CollectionRef, Entry, Episode, File, Item, Movie, Paged, PlaySlot,
|
|
6
6
|
} from "krillplayer-plugin";
|
|
7
7
|
|
|
8
8
|
const MEDIA = "https://media.example/stream";
|
|
@@ -116,40 +116,6 @@ export const browse = {
|
|
|
116
116
|
},
|
|
117
117
|
} satisfies BrowseSlot;
|
|
118
118
|
|
|
119
|
-
// 资料库:媒体服务器不列目录,交回自己已经识别过的电影与集,内核直接用这里的 id 与 ids 进海报墙,
|
|
120
|
-
// 不按文件名搜索。每个条目记着最后一次改动的序号,交回的 since 是最新的序号,since 之后改过的才交回;删掉的条目在 REMOVED 里。
|
|
121
|
-
// 影视合集(boxSet)与文件夹不进资料库:服务器自建的合集只在它自己的浏览里。
|
|
122
|
-
const CHANGED: Record<string, number> = { m1: 1, m2: 2, "e0-1": 3, "e1-1": 3, "e1-2": 4, "e2-1": 5 };
|
|
123
|
-
const REMOVED: Record<string, number> = { m0: 4 };
|
|
124
|
-
const LATEST = "5";
|
|
125
|
-
const SERIES = COLLECTIONS.find((candidate): candidate is Series => candidate.kind === "series")!;
|
|
126
|
-
const identified = (value: Movie | Episode): LibraryEntry =>
|
|
127
|
-
value.kind === "movie" ? { type: "identified", item: value } : { type: "identified", item: value, series: SERIES };
|
|
128
|
-
|
|
129
|
-
export const library = {
|
|
130
|
-
async changes(krillplayer, since, cursor) {
|
|
131
|
-
const after = since === null ? 0 : Number(since);
|
|
132
|
-
if (!Number.isInteger(after)) throw krillplayer.error("other", "认不出的 since");
|
|
133
|
-
const changed = [...MOVIES, ...EPISODES].filter((candidate) => CHANGED[candidate.id]! > after).map(identified);
|
|
134
|
-
const start = Number(cursor ?? "0");
|
|
135
|
-
const end = start + PAGE_SIZE;
|
|
136
|
-
const removed = since === null || start > 0 ? [] : Object.keys(REMOVED).filter((id) => REMOVED[id]! > after);
|
|
137
|
-
return {
|
|
138
|
-
entries: changed.slice(start, end),
|
|
139
|
-
...(removed.length > 0 ? { removed } : {}),
|
|
140
|
-
...(end < changed.length ? { next: String(end) } : {}),
|
|
141
|
-
since: LATEST,
|
|
142
|
-
};
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
async ids(_krillplayer, cursor) {
|
|
146
|
-
const all = [...MOVIES, ...EPISODES].map((candidate) => candidate.id);
|
|
147
|
-
const start = Number(cursor ?? "0");
|
|
148
|
-
const end = start + 4;
|
|
149
|
-
return { ids: all.slice(start, end), ...(end < all.length ? { next: String(end) } : {}) };
|
|
150
|
-
},
|
|
151
|
-
} satisfies LibrarySlot;
|
|
152
|
-
|
|
153
119
|
// 条目与版本都用自己的 id 起播:一个来源实例里它们不重复。
|
|
154
120
|
export const play = {
|
|
155
121
|
async start(krillplayer, itemId) {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 不接住 krillplayer.files 的失败:找不到、没有权限、连不上各带着自己的种类交给内核;
|
|
5
5
|
// 起播时顺手把同目录、同名的字幕文件列进 Playable.subtitles,地址同样用 krillplayer.files.playable 给。
|
|
6
6
|
import type {
|
|
7
|
-
At, BrowseSlot, CollectionRef, Entry, File, FileEntry, Folder, KrillPlayer,
|
|
7
|
+
At, BrowseSlot, CollectionRef, Entry, File, FileEntry, Folder, KrillPlayer, Paged, Playable, PlaySlot,
|
|
8
8
|
} from "krillplayer-plugin";
|
|
9
9
|
|
|
10
10
|
const VIDEO = new Set(["mp4", "m4v", "mov", "mkv", "avi", "ts", "m2ts", "webm", "flv", "wmv"]);
|
|
@@ -66,25 +66,6 @@ export const browse = {
|
|
|
66
66
|
},
|
|
67
67
|
} satisfies BrowseSlot;
|
|
68
68
|
|
|
69
|
-
// 资料库:对 krillplayer.files 的薄包装。一次列一层,内核自己往下走;文件的 itemId 就是 browse 给的那个 File 的 id。
|
|
70
|
-
export const library = {
|
|
71
|
-
async list(krillplayer, dir, cursor) {
|
|
72
|
-
const page = await krillplayer.files.list(dir, cursor);
|
|
73
|
-
const entries = page.entries.filter(shown).flatMap((entry): LibraryEntry[] => {
|
|
74
|
-
if (entry.isDirectory) return [{ type: "directory", path: entry.path, name: entry.name, ...times(entry) }];
|
|
75
|
-
const media = mediaOf(entry.name);
|
|
76
|
-
if (media === undefined) return [];
|
|
77
|
-
return [{ type: "file", path: entry.path, name: entry.name, itemId: entry.path, media, ...sizes(entry), ...times(entry) }];
|
|
78
|
-
});
|
|
79
|
-
return { entries, ...(page.next === undefined ? {} : { next: page.next }) };
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
// 内核读同目录的信息文件(NFO)用。
|
|
83
|
-
async read(krillplayer, path, offset, length) {
|
|
84
|
-
return krillplayer.files.read(path, offset, length);
|
|
85
|
-
},
|
|
86
|
-
} satisfies LibrarySlot;
|
|
87
|
-
|
|
88
69
|
// 同目录里与视频同名的字幕:「片名.srt」或「片名.zh.srt」,中间那一段当语言,没有就是 und。最多翻 SUBTITLE_PAGES 页目录。
|
|
89
70
|
const SUBTITLE_PAGES = 20;
|
|
90
71
|
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
|
|
35
35
|
排期与预告的分界只有一条:**来源给没给它一个能拿去 `play.start` 的 id。** 给了是预告,没给是排期。
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
哪个都不像时不要硬套:用最朴素的 `onDemand` 或 `file`,并在插件的说明里写一句。这是我们该不该加种类的信号。
|
|
38
38
|
|
|
39
39
|
试跑器按本节的类型逐个检查返回的对象,字段不属于这个种类、必填的没给,都直接报错并说明该怎么改。
|
|
40
40
|
|
|
@@ -66,4 +66,4 @@
|
|
|
66
66
|
| `onDemand` 点播 | 频道发布的、随时能播的一段内容,不是影视作品,也不是播客单集。平台上的普通视频、直播的回放、电台的回听都是它 | 记 | 播放页 |
|
|
67
67
|
| `live` 直播 | 此刻正在播出的一路:直播间在播的、电视台与电台正在播的 | 不记 | 播放页 |
|
|
68
68
|
| `upcoming` 预告 | 来源给了独立 id、还没开始的一场直播或首播 | 不能播 | 详情与提醒 |
|
|
69
|
-
| `file` 文件 |
|
|
69
|
+
| `file` 文件 | 文件类来源里的一个媒体文件。App 按文件夹浏览,不把它认成作品,续播记在文件上 | 记 | 播放页 |
|