@xzxzzx/bilibili-mcp 1.3.8 → 1.4.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.
Files changed (53) hide show
  1. package/README.md +63 -4
  2. package/README_EN.md +63 -4
  3. package/dist/bilibili/client.d.ts +3 -77
  4. package/dist/bilibili/client.d.ts.map +1 -1
  5. package/dist/bilibili/client.js +4 -600
  6. package/dist/bilibili/client.js.map +1 -1
  7. package/dist/bilibili/comments-api.d.ts +6 -0
  8. package/dist/bilibili/comments-api.d.ts.map +1 -0
  9. package/dist/bilibili/comments-api.js +126 -0
  10. package/dist/bilibili/comments-api.js.map +1 -0
  11. package/dist/bilibili/comments.d.ts +10 -3
  12. package/dist/bilibili/comments.d.ts.map +1 -1
  13. package/dist/bilibili/comments.js +30 -7
  14. package/dist/bilibili/comments.js.map +1 -1
  15. package/dist/bilibili/fingerprint.d.ts +10 -0
  16. package/dist/bilibili/fingerprint.d.ts.map +1 -0
  17. package/dist/bilibili/fingerprint.js +50 -0
  18. package/dist/bilibili/fingerprint.js.map +1 -0
  19. package/dist/bilibili/http.d.ts +24 -0
  20. package/dist/bilibili/http.d.ts.map +1 -0
  21. package/dist/bilibili/http.js +259 -0
  22. package/dist/bilibili/http.js.map +1 -0
  23. package/dist/bilibili/metadata.d.ts +6 -0
  24. package/dist/bilibili/metadata.d.ts.map +1 -0
  25. package/dist/bilibili/metadata.js +36 -0
  26. package/dist/bilibili/metadata.js.map +1 -0
  27. package/dist/bilibili/subtitle.d.ts +9 -0
  28. package/dist/bilibili/subtitle.d.ts.map +1 -1
  29. package/dist/bilibili/subtitle.js +92 -1
  30. package/dist/bilibili/subtitle.js.map +1 -1
  31. package/dist/bilibili/types.d.ts +33 -0
  32. package/dist/bilibili/types.d.ts.map +1 -1
  33. package/dist/bilibili/video-api.d.ts +57 -0
  34. package/dist/bilibili/video-api.d.ts.map +1 -0
  35. package/dist/bilibili/video-api.js +81 -0
  36. package/dist/bilibili/video-api.js.map +1 -0
  37. package/dist/bilibili/wbi.d.ts +13 -0
  38. package/dist/bilibili/wbi.d.ts.map +1 -0
  39. package/dist/bilibili/wbi.js +120 -0
  40. package/dist/bilibili/wbi.js.map +1 -0
  41. package/dist/server.d.ts.map +1 -1
  42. package/dist/server.js +164 -5
  43. package/dist/server.js.map +1 -1
  44. package/dist/utils/validation.d.ts +8 -0
  45. package/dist/utils/validation.d.ts.map +1 -1
  46. package/dist/utils/validation.js +23 -0
  47. package/dist/utils/validation.js.map +1 -1
  48. package/package.json +11 -9
  49. package/dist/smithery-test.d.ts +0 -4
  50. package/dist/smithery-test.d.ts.map +0 -1
  51. package/dist/smithery-test.js +0 -11
  52. package/dist/smithery-test.js.map +0 -1
  53. package/src/index.ts +0 -37
package/README.md CHANGED
@@ -28,7 +28,9 @@
28
28
  - [🌟 功能特性](#-功能特性)
29
29
  - [1. 视频总结 (`get_video_info`)](#1-视频总结-get_video_info)
30
30
  - [2. 评论总结 (`get_video_comments`)](#2-评论总结-get_video_comments)
31
- - [3. 🛡️ 稳健性增强](#3-️-稳健性增强)
31
+ - [3. 视频转录 (`get_video_transcript`)](#3-视频转录-get_video_transcript)
32
+ - [4. 视频元数据 (`get_video_metadata`)](#4-视频元数据-get_video_metadata)
33
+ - [5. 行为说明与错误处理](#5-行为说明与错误处理)
32
34
  - [📋 环境要求](#-环境要求)
33
35
  - [🚀 安装方式](#-安装方式)
34
36
  - [🖱️ Cursor](#️-cursor)
@@ -85,12 +87,51 @@
85
87
  - 优先保留包含时间戳的评论(如 `05:20`),方便定位高能片段
86
88
  - 支持两种详细程度:
87
89
  - `brief`: 10 条热门评论速览
88
- - `detailed`: 50 条热门评论 + 高赞连带回复
90
+ - `detailed`: 20 条热门评论 + 高赞连带回复
91
+ - 可选参数:
92
+ - `limit`: 显式评论数量 `1-50`,覆盖 `detail_level` 的默认数量
93
+ - `sort`: 排序方式 `"hot"`(按热度,默认)或 `"time"`(按时间)
94
+ - `include_replies`: 是否包含高赞回复(默认 `true`)
95
+
96
+ ### 3. 视频转录 (`get_video_transcript`)
97
+ - 返回纯字幕文本,按行合并
98
+ - 支持指定偏好语言(默认按 `zh-Hans` > `ai-zh` > `zh-CN` > `zh-Hant` > `en` 优先级选择)
99
+ - 可选参数:
100
+ - `preferred_lang`: 偏好字幕语言代码
101
+ - `fallback_to_description`: 字幕不可用时是否降级为视频描述(默认 `false`)
102
+ - 默认不降级:无字幕时返回 `SUBTITLE_UNAVAILABLE` 错误
103
+ - Cookie 失效时始终返回 `COOKIE_EXPIRED`,不静默降级
104
+
105
+ ### 4. 视频元数据 (`get_video_metadata`)
106
+ - 返回视频标题、作者、时长、发布时间、描述、标签、播放/点赞/投币等统计信息
107
+ - 不获取字幕或评论
108
+ - 仅需 `bvid_or_url` 参数
109
+
110
+ ### 5. 行为说明与错误处理
89
111
 
90
- ### 3. 🛡️ 稳健性增强
91
112
  - **Cookie 过期智能检测**:当字幕获取为空时自动验证登录状态,区分“无字幕视频”与“凭证失效”,并抛出明确的 `COOKIE_EXPIRED` 错误,避免静默降级。
92
113
 
93
- ---
114
+ #### 无 Cookie 行为
115
+
116
+ - 部分公开视频元数据(`get_video_metadata`)可能在未登录状态下工作。
117
+ - 字幕(`get_video_info`、`get_video_transcript`)在未登录时可能无法获取、不完整或返回空结果。
118
+ - 评论(`get_video_comments`)在未登录时可能不完整、被限流或返回空列表。
119
+ - 不建议依赖无 Cookie 模式获取字幕或评论。
120
+
121
+ #### Cookie 凭据来源
122
+
123
+ - Cookie 凭据应通过 `.env` 文件、环境变量或凭据管理工具提供。
124
+ - 支持的环境变量:`BILIBILI_SESSDATA`、`BILIBILI_BILI_JCT`、`BILIBILI_DEDEUSERID`。
125
+ - **切勿**在源码、脚本、文档、测试、日志或示例中硬编码 Cookie 值。
126
+ - 如果 Cookie 值曾出现在仓库历史中,应尽快到 Bilibili 账号设置中轮换/失效旧 Cookie。
127
+
128
+ #### 预期错误码
129
+
130
+ | 错误码 | 含义 | 调用方建议 |
131
+ |--------|------|-----------|
132
+ | `VALIDATION_ERROR` | 输入参数不合法 | 检查并修正 `bvid_or_url` 或其他参数 |
133
+ | `COOKIE_EXPIRED` | Cookie 已失效或未登录 | 用户应更新/轮换 Bilibili 凭据 |
134
+ | `SUBTITLE_UNAVAILABLE` | 视频无可用的字幕 | 对 `get_video_transcript` 可重试并设置 `fallback_to_description: true` |
94
135
 
95
136
  ## 📋 环境要求
96
137
 
@@ -405,6 +446,24 @@ bilibili-mcp config
405
446
  "name": "get_video_comments",
406
447
  "arguments": { "bvid_or_url": "BV1xx4x1x7xx", "detail_level": "brief" }
407
448
  }
449
+
450
+ // 获取纯字幕文本(无字幕时返回错误)
451
+ {
452
+ "name": "get_video_transcript",
453
+ "arguments": { "bvid_or_url": "BV1xx4x1x7xx" }
454
+ }
455
+
456
+ // 获取视频元数据
457
+ {
458
+ "name": "get_video_metadata",
459
+ "arguments": { "bvid_or_url": "BV1xx4x1x7xx" }
460
+ }
461
+
462
+ // 获取评论(自定义数量+排序)
463
+ {
464
+ "name": "get_video_comments",
465
+ "arguments": { "bvid_or_url": "BV1xx4x1x7xx", "limit": 5, "sort": "time", "include_replies": false }
466
+ }
408
467
  ```
409
468
 
410
469
  ---
package/README_EN.md CHANGED
@@ -23,7 +23,9 @@ View this document in [简体中文](./README.md)
23
23
  - [🌟 Features](#-features)
24
24
  - [1. Video Summarization (`get_video_info`)](#1-video-summarization-get_video_info)
25
25
  - [2. Comment Summarization (`get_video_comments`)](#2-comment-summarization-get_video_comments)
26
- - [3. 🛡️ Robustness Enhancement](#3-️-robustness-enhancement)
26
+ - [3. Video Transcript (`get_video_transcript`)](#3-video-transcript-get_video_transcript)
27
+ - [4. Video Metadata (`get_video_metadata`)](#4-video-metadata-get_video_metadata)
28
+ - [5. Behavior and Error Handling](#5-behavior-and-error-handling)
27
29
  - [📋 Requirements](#-requirements)
28
30
  - [🚀 Installation](#-installation)
29
31
  - [🖱️ Cursor](#️-cursor)
@@ -80,12 +82,51 @@ Before proceeding with installation, please ensure you are familiar with [How to
80
82
  - Prioritizes comments with timestamps (e.g., `05:20`) for quick highlight location.
81
83
  - Supports two levels of detail:
82
84
  - `brief`: 10 popular comments summary.
83
- - `detailed`: 50 popular comments + high-quality replies.
85
+ - `detailed`: 20 popular comments + high-quality replies.
86
+ - Optional parameters:
87
+ - `limit`: Explicit comment count `1-50`, overrides `detail_level` default.
88
+ - `sort`: Sort order `"hot"` (default) or `"time"`.
89
+ - `include_replies`: Whether to include top replies (default `true`).
90
+
91
+ ### 3. Video Transcript (`get_video_transcript`)
92
+ - Returns clean subtitle text, joined by newlines.
93
+ - Supports preferred language selection (defaults to `zh-Hans` > `ai-zh` > `zh-CN` > `zh-Hant` > `en` priority).
94
+ - Optional parameters:
95
+ - `preferred_lang`: Preferred subtitle language code.
96
+ - `fallback_to_description`: Fall back to video description if subtitles unavailable (default `false`).
97
+ - By default, returns `SUBTITLE_UNAVAILABLE` error when no subtitles exist.
98
+ - Cookie expiration always returns `COOKIE_EXPIRED`, never silently falls back.
99
+
100
+ ### 4. Video Metadata (`get_video_metadata`)
101
+ - Returns video title, author, duration, publish date, description, tags, and stats (views, likes, coins, etc.).
102
+ - Does not fetch subtitles or comments.
103
+ - Only requires the `bvid_or_url` parameter.
104
+
105
+ ### 5. Behavior and Error Handling
84
106
 
85
- ### 3. 🛡️ Robustness Enhancement
86
107
  - **Intelligent Cookie Expiration Detection**: Automatically verifies login status when subtitles are empty, distinguishing between "videos without subtitles" and "invalid credentials," and throwing a clear `COOKIE_EXPIRED` error to prevent silent degradation.
87
108
 
88
- ---
109
+ #### Without Cookie
110
+
111
+ - Some public video metadata (`get_video_metadata`) may work without authentication.
112
+ - Subtitles (`get_video_info`, `get_video_transcript`) may be unavailable, incomplete, or fail without authentication.
113
+ - Comments (`get_video_comments`) may be incomplete, empty, or rate-limited without authentication.
114
+ - Do not rely on cookie-less mode for reliable subtitle or comment access.
115
+
116
+ #### Credential Sources
117
+
118
+ - Credentials should be supplied via `.env` file, environment variables, or the credential helper.
119
+ - Supported environment variables: `BILIBILI_SESSDATA`, `BILIBILI_BILI_JCT`, `BILIBILI_DEDEUSERID`.
120
+ - **Never** hard-code Cookie values in source code, scripts, docs, tests, logs, or examples.
121
+ - If Cookie values were previously exposed in repository history, rotate them immediately via Bilibili account settings.
122
+
123
+ #### Expected Error Codes
124
+
125
+ | Code | Meaning | Caller Action |
126
+ |------|---------|---------------|
127
+ | `VALIDATION_ERROR` | Invalid input parameter | Fix the `bvid_or_url` or other parameter |
128
+ | `COOKIE_EXPIRED` | Cookie expired or not logged in | User should refresh/rotate Bilibili credentials |
129
+ | `SUBTITLE_UNAVAILABLE` | No subtitles available for this video | For `get_video_transcript`, retry with `fallback_to_description: true` |
89
130
 
90
131
  ## 📋 Requirements
91
132
 
@@ -389,6 +430,24 @@ AI assistants will call these tools using JSON:
389
430
  "name": "get_video_comments",
390
431
  "arguments": { "bvid_or_url": "BV1xx4x1x7xx", "detail_level": "brief" }
391
432
  }
433
+
434
+ // Transcript-only text (returns error if no subtitles)
435
+ {
436
+ "name": "get_video_transcript",
437
+ "arguments": { "bvid_or_url": "BV1xx4x1x7xx" }
438
+ }
439
+
440
+ // Video metadata
441
+ {
442
+ "name": "get_video_metadata",
443
+ "arguments": { "bvid_or_url": "BV1xx4x1x7xx" }
444
+ }
445
+
446
+ // Comments with custom limit + sort
447
+ {
448
+ "name": "get_video_comments",
449
+ "arguments": { "bvid_or_url": "BV1xx4x1x7xx", "limit": 5, "sort": "time", "include_replies": false }
450
+ }
392
451
  ```
393
452
 
394
453
  ---
@@ -1,78 +1,4 @@
1
- /**
2
- * 检查当前 Cookie 是否处于登录状态。
3
- * 通过调用 /x/web-interface/nav 接口,解析 isLogin 字段来判断。
4
- * 该函数不会在日志或错误信息中输出任何 Cookie 内容。
5
- */
6
- export declare function checkLoginStatus(): Promise<{
7
- isLogin: boolean;
8
- }>;
9
- /**
10
- * 带有 WBI 签名的 GET 请求
11
- */
12
- export declare function fetchWithWBI(path: string, params: Record<string, string | number>, additionalHeaders?: Record<string, string>): Promise<unknown>;
13
- /**
14
- * 普通的 GET 请求(不需要 WBI 签名)
15
- */
16
- export declare function fetchWithoutWBI(path: string, params?: Record<string, string | number>, additionalHeaders?: Record<string, string>): Promise<unknown>;
17
- /**
18
- * 获取视频基本信息
19
- */
20
- export declare function getVideoInfo(bvid: string): Promise<{
21
- title: string;
22
- desc: string;
23
- pic?: string;
24
- owner: {
25
- name: string;
26
- face: string;
27
- };
28
- stat: {
29
- view: number;
30
- danmaku: number;
31
- reply: number;
32
- favorite: number;
33
- coin: number;
34
- share: number;
35
- like: number;
36
- };
37
- cid: number;
38
- aid: number;
39
- duration: number;
40
- pubdate: number;
41
- tag?: {
42
- tag_name: string;
43
- }[];
44
- }>;
45
- /**
46
- * 获取视频字幕信息
47
- *
48
- * 策略:优先使用带 WBI 签名的 /x/player/wbi/v2 接口。
49
- * 若该接口返回空字幕(部分视频的 AI 字幕 subtitle_url 只在非 WBI 版接口中暴露),
50
- * 自动降级到 /x/player/v2 重试一次。
51
- */
52
- export declare function getVideoSubtitle(bvid: string, cid: number): Promise<{
53
- subtitle: {
54
- subtitles: Array<{
55
- id: number;
56
- lan: string;
57
- lan_doc: string;
58
- subtitle_url: string;
59
- }>;
60
- };
61
- }>;
62
- /**
63
- * 获取字幕内容
64
- */
65
- export declare function getSubtitleContent(url: string): Promise<{
66
- body: Array<{
67
- from: number;
68
- to: number;
69
- location: number;
70
- content: string;
71
- }>;
72
- }>;
73
- /**
74
- * 获取视频评论
75
- */
76
- export declare function getVideoComments(videoUrlOrBvid: string, page?: number, pageSize?: number, sort?: number, // 0按时间,1按热度
77
- includeReplies?: boolean): Promise<any>;
1
+ export { checkLoginStatus, fetchWithWBI, fetchWithoutWBI } from "./http.js";
2
+ export { getSubtitleContent, getVideoInfo, getVideoSubtitle, } from "./video-api.js";
3
+ export { getVideoComments } from "./comments-api.js";
78
4
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"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