{"record":{"id":"d1edc6b0d936dc20","repo":"jackwener/OpenCLI","slug":"bilibili-summary-url-must-contain-a-bv-video-id","errorCode":null,"errorMessage":"Bilibili summary URL must contain a BV video id","messagePattern":"Bilibili summary URL must contain a BV video id","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/summary.js","lineNumber":43,"sourceCode":"        throw new ArgumentError('bilibili summary bvid cannot be empty', 'Pass a BV ID, Bilibili video URL, or b23.tv short link.');\n    }\n    if (BVID_RE.test(input)) {\n        return input;\n    }\n    let parsed = null;\n    try {\n        parsed = new URL(input);\n    } catch {\n        // Bare b23.tv short codes are accepted by the shared resolver.\n    }\n    if (parsed) {\n        if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {\n            throw new ArgumentError('Bilibili summary URL must use http or https');\n        }\n        if (BILIBILI_HOST_RE.test(parsed.hostname)) {\n            const match = parsed.pathname.match(/\\/(?:video|bangumi\\/play)\\/(BV[A-Za-z0-9]+)/i);\n            if (!match) {\n                throw new ArgumentError('Bilibili summary URL must contain a BV video id');\n            }\n            return match[1];\n        }\n        if (!B23_HOST_RE.test(parsed.hostname)) {\n            throw new ArgumentError('Bilibili summary URL must be a bilibili.com or b23.tv URL');\n        }\n    }\n    try {\n        return await resolveBvid(input);\n    } catch (error) {\n        throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${input}`, error instanceof Error ? error.message : String(error));\n    }\n}\n\nfunction requireOkPayload(payload, label) {\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError(`Bilibili ${label} API returned a malformed payload`);\n    }","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/summary.js#L25-L61","documentation":"For URLs on a bilibili.com host, readBvid extracts the BV ID from the path via /\\/(?:video|bangumi\\/play)\\/(BV[A-Za-z0-9]+)/. If the path has no /video/BV... or /bangumi/play/BV... segment, the URL is on the right host but does not point at a video, so this ArgumentError is thrown. The library only scrapes the id from known path shapes rather than fetching the page.","triggerScenarios":"Passing bilibili.com URLs that are not video pages: `https://www.bilibili.com/` (homepage), `https://space.bilibili.com/123456` (user space), `https://www.bilibili.com/video/av170001` (av-number instead of BV id), or a video URL with the id stripped.","commonSituations":"Copying the site homepage or a user/space page instead of the video page; using legacy av-number URLs (BV regex requires the literal 'BV' prefix); URL was truncated by a chat/text editor losing the path.","solutions":["Open the video page and copy the full URL including /video/BVxxxx path.","Convert av-numbers to BV ids, or just pass the BV id directly.","Validate the URL contains /video/BV... or /bangumi/play/BV... before invoking."],"exampleFix":"// before\nawait summaryCommand('https://www.bilibili.com/video/av170001');\n// after\nawait summaryCommand('https://www.bilibili.com/video/BV1xx411c7mD');","handlingStrategy":"validation","validationCode":"const u = new URL(input);\nif (/(^|\\.)bilibili\\.com$/.test(u.hostname) && !/\\/video\\/BV[A-Za-z0-9]+|\\/bangumi\\/play\\/BV[A-Za-z0-9]+/i.test(u.pathname)) {\n  throw new Error('URL must be a bilibili video/bangumi page containing /video/BV... or /bangumi/play/BV...');\n}","typeGuard":"function isBilibiliVideoUrl(u) {\n  try {\n    const url = new URL(u);\n    return /(^|\\.)bilibili\\.com$/i.test(url.hostname) &&\n      /\\/(?:video|bangumi\\/play)\\/BV[A-Za-z0-9]+/i.test(url.pathname);\n  } catch { return false; }\n}","tryCatchPattern":"try {\n  await summaryCommand(url);\n} catch (e) {\n  if (/must contain a BV video id/.test(e.message)) {\n    console.error('Copy the full video page URL, e.g. https://www.bilibili.com/video/BV1xx411c7mD');\n  } else throw e;\n}","preventionTips":["Copy the URL from the video page itself, not the homepage or a user space.","Remember av-numbers are not accepted — the path must contain a BV id.","Check URLs weren't truncated when copied from chat apps or markdown."],"tags":["url-validation","url-path","argument-error"],"backgroundTag":"url-path-missing-required-id","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}