jackwener/OpenCLI · error · CommandExecutionError
获取视频信息失败: ${view?.message ?? 'unknown'} (${view?.code})
Error message
获取视频信息失败: ${view?.message ?? 'unknown'} (${view?.code}) What it means
The Bilibili view API responded successfully but with a non-zero code field, meaning the API itself rejected the request (e.g. -400 request error, -404 not found, -412 risk control). The error surfaces the API's own message and numeric code. This is the library's way of turning Bilibili business-level failures into a thrown CommandExecutionError.
Source
Thrown at clis/bilibili/subtitle.js:34
columns: ['index', 'from', 'to', 'content'],
func: async (page, kwargs) => {
if (!page)
throw new CommandExecutionError('Browser session required for bilibili subtitle');
const bvid = await resolveBvid(kwargs.bvid);
const selectedPage = parsePageArg(kwargs.page);
// 1. 通过 view API 拿 cid。
// 以前的实现走 page.goto(/video/<bvid>) + window.__INITIAL_STATE__.videoData.cid,
// bangumi 绑定的 bvid(番剧/纪录片/电影/综艺)页面 state 不在 videoData 而在 epList,
// 导致 SELECTOR 错。view API 接受任何 bvid(UGC + PGC 都通),且不依赖 DOM 结构。
let view;
try {
view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });
}
catch (err) {
throw new CommandExecutionError(`获取视频信息失败: ${err?.message || err}`);
}
if (view?.code !== 0) {
throw new CommandExecutionError(`获取视频信息失败: ${view?.message ?? 'unknown'} (${view?.code})`);
}
// --page 给定时用该集 cid(selectVideoPart 越界抛错);缺省取整集默认 cid(P1,旧行为)。
const cid = selectedPage != null ? selectVideoPart(view?.data, selectedPage).cid : view?.data?.cid;
if (!cid) {
throw new CommandExecutionError(`无法从 view API 拿到 cid (bvid=${bvid})`);
}
// 2. 用带 Wbi 签名的 player/v2 拿字幕列表(之前 evaluate 里 fetch 因为没签名会 403)
let payload;
try {
payload = await apiGet(page, '/x/player/wbi/v2', {
params: { bvid, cid },
signed: true,
});
}
catch (err) {
throw new CommandExecutionError(`获取视频播放信息失败: ${err?.message || err}`);
}
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {View on GitHub (pinned to 49907e53dc)
Solutions
- Decode the code in the message: -400 bad request → check bvid format; -404 → video doesn't exist/was deleted; -412 → risk control, slow down or log in
- Verify the bvid exists by opening https://www.bilibili.com/video/<bvid> in a browser
- Retry later or from a logged-in session if you got -412 (anti-bot/risk control)
- If using a URL/short link, confirm it resolves to the intended UGC video bvid
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check the bvid exists
const res = await fetch(`https://api.bilibili.com/x/web-interface/view?bvid=${bvid}`);
const j = await res.json();
if (j.code !== 0) throw new Error(`bvid ${bvid} rejected by view API: ${j.message} (${j.code})`); Try / catch
try {
await run(['bilibili', 'subtitle', bvid]);
} catch (e) {
const m = /获取视频信息失败: (.+) \((-?\d+)\)/.exec(String(e.message));
if (m) {
const [, msg, code] = m;
if (code === '-412' || code === '-352') { /* back off, use logged-in session */ }
else if (code === '-404' || code === '-400') { /* fix/validate bvid */ }
} else throw e;
} Prevention
- Validate BV ids before use (regex /^BV[0-9A-Za-z]{10}$/)
- Don't hammer the API — add delays to avoid -412 risk control
- Check video availability manually before batch processing
When it happens
Trigger: view?.code !== 0 after apiGet('/x/web-interface/view') — typically a malformed/nonexistent bvid, deleted/private video, or Bilibili risk-control (-412) rejection of the request.
Common situations: Typo in the BV id; video removed or set to private; b23.tv short link resolving to a bangumi page with odd handling; too many requests triggering -412 anti-crawler; unlogged/risk-controlled account.
Related errors
- Bilibili view API returned a malformed payload during paid-c
- 获取视频播放信息失败: ${payload.message} (${payload.code})
- Cannot resolve aid for bvid: ${bvid}
- 获取视频分P信息失败: ${error?.message || error}
- 获取视频信息失败: ${err?.message || err}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/836ded671f5a2455.
Report an issue: GitHub.