bilibili

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

bilibili — read & publish 专栏 via your own cookies

bilibili — 使用自有Cookie读写专栏

Drives the user's real Bilibili 专栏 (article) account through the same
api.bilibili.com
web endpoints the site uses, authenticated by the login cookie they captured with the ACE extension. No browser, no third-party deps —
urllib
+
hashlib
(the article-list read endpoint needs WBI signing, done with stdlib).
The connector injects the cookie jar as an env var:
  • BILIBILI_COOKIES
    — a JSON array of cookies. Secret — never echo or print it. It includes
    SESSDATA
    (auth) and
    bili_jct
    (the CSRF token used for writes).
通过B站官方使用的
api.bilibili.com
接口操作用户的真实B站专栏账号,使用用户通过ACE扩展获取的登录Cookie进行身份验证。无需浏览器,无第三方依赖——仅使用
urllib
+
hashlib
(文章列表读取接口需要WBI签名,通过标准库实现)。
连接器会将Cookie Jar注入为环境变量:
  • BILIBILI_COOKIES
    — Cookie的JSON数组。机密信息——切勿回显或打印。其中包含
    SESSDATA
    (身份验证凭证)和
    bili_jct
    (用于写入操作的CSRF令牌)。

CLI

CLI

The skill ships
scripts/bilibili.py
— self-contained, stdlib only.
sh
BILI=$SKILL_DIR/scripts/bilibili.py
python3 $BILI whoami                       # who is logged in (mid, name)
python3 $BILI articles --limit 20          # my 专栏 articles + stats
python3 $BILI article <cvid>               # one article's stats (cv id)
python3 $BILI drafts --limit 50            # list saved drafts (aid + title)
Stats come straight from Bilibili:
view
(阅读),
like
(点赞),
reply
(评论),
favorite
(收藏),
coin
(投币).
本技能附带了
scripts/bilibili.py
——独立脚本,仅依赖标准库。
sh
BILI=$SKILL_DIR/scripts/bilibili.py
python3 $BILI whoami                       # 查询当前登录用户(mid、昵称)
python3 $BILI articles --limit 20          # 列出我的专栏文章及数据
python3 $BILI article <cvid>               # 查看单篇文章的数据(cv id)
python3 $BILI drafts --limit 50            # 列出已保存的草稿(aid + 标题)
数据直接来自B站:
view
(阅读量)、
like
(点赞数)、
reply
(评论数)、
favorite
(收藏数)、
coin
(投币数)。

Verify the connection first

先验证连接

sh
python3 $BILI whoami
sh
python3 $BILI whoami

→ {"mid": 91207595, "name": "...", "level": 4}

→ {"mid": 91207595, "name": "...", "level": 4}


On a not-logged-in / auth error the cookie is expired — have the user reconnect
at <https://auth.acedata.cloud/user/connections>. Do **not** loop-retry.

若未登录或出现身份验证错误,说明Cookie已过期——请用户前往<https://auth.acedata.cloud/user/connections>重新连接。**请勿循环重试**。

Publishing — GATED (dry-run unless trailing
--confirm
)

发布功能——受保护(除非末尾添加
--confirm
,否则仅为模拟运行)

publish
writes to the user's real account. 专栏 content is HTML. Without a trailing
--confirm
it dry-runs.
--confirm
is honored only as the last argument. Always show the dry-run, get an explicit "yes", then re-run.
sh
python3 $BILI publish --title "标题" --content-file a.html                       # dry-run
python3 $BILI publish --title "标题" --content-file a.html --draft-only --confirm   # save a draft
python3 $BILI publish --title "标题" --content-file a.html --confirm                # save draft + submit (publish)
  • --draft-only
    saves a draft (no submit) — safe; finish/publish in the editor.
  • The submit (go public) step is frequently rate-limited by Bilibili risk-control (HTTP 412). When that happens the CLI reports the saved draft + edit URL so the user can publish from the web editor. Default to
    --draft-only
    .
publish
会写入用户的真实账号。专栏内容为HTML格式。若未在末尾添加
--confirm
,则仅进行模拟运行。
--confirm
仅在作为最后一个参数时生效。应始终先展示模拟运行结果,获取用户明确的“同意”后,再重新运行发布命令。
sh
python3 $BILI publish --title "标题" --content-file a.html                       # 模拟运行
python3 $BILI publish --title "标题" --content-file a.html --draft-only --confirm   # 保存为草稿
python3 $BILI publish --title "标题" --content-file a.html --confirm                # 保存草稿并提交发布
  • --draft-only
    仅保存草稿(不提交)——安全操作,可在编辑器中完成后续编辑/发布。
  • 提交(公开)步骤经常会被B站风控系统限制(HTTP 412错误)。出现此情况时,CLI会返回已保存的草稿及编辑链接,用户可通过网页编辑器完成发布。默认建议使用
    --draft-only

Managing drafts (the 999-draft cap)

草稿管理(999篇草稿上限)

Bilibili caps 专栏 drafts at 999; once full, saving a new draft fails with
code 37106 草稿数已达最大上限
. List drafts and delete the ones you don't need:
sh
python3 $BILI drafts --limit 50                       # list (aid + title)
python3 $BILI delete-draft <aid> <aid2> ...           # dry-run (shows what would delete)
python3 $BILI delete-draft <aid> <aid2> ... --confirm # PERMANENTLY delete those drafts
  • delete-draft
    is GATED (dry-run unless trailing
    --confirm
    ) and deletion is permanent — always show the dry-run + the titles and get an explicit "yes" before
    --confirm
    . Pass multiple aids to batch a few per call.
  • Never bulk-delete blindly: list first, confirm the titles are junk/duplicates.
B站专栏草稿上限为999篇;达到上限后,保存新草稿会失败并返回
code 37106 草稿数已达最大上限
。可列出草稿并删除不需要的草稿:
sh
python3 $BILI drafts --limit 50                       # 列出草稿(aid + 标题)
python3 $BILI delete-draft <aid> <aid2> ...           # 模拟删除(展示将要删除的内容)
python3 $BILI delete-draft <aid> <aid2> ... --confirm # 永久删除指定草稿
  • delete-draft
    功能受保护(除非末尾添加
    --confirm
    ,否则仅为模拟运行),且删除操作不可恢复——始终先展示模拟运行结果及草稿标题,获取用户明确的“同意”后再添加
    --confirm
    。可传入多个aid进行批量删除。
  • 切勿盲目批量删除:先列出草稿,确认要删除的是无用/重复的草稿。

Images

图片处理

publish
automatically re-hosts external images (both
<img src>
and markdown) onto Bilibili's CDN (
i0.hdslb.com
/
article.biliimg.com
) before saving — Bilibili hotlink-blocks external images and rejects the whole article (
37130
) if any external link remains. webp sources (which upcover rejects) are transcoded to png via the CDN when possible; an image that still can't upload is dropped from the article rather than failing the post.
--no-rehost-images
skips this.
publish
会自动将外部图片(包括
<img src>
标签和Markdown中的图片)重新托管到B站CDN(
i0.hdslb.com
/
article.biliimg.com
)后再保存——B站会拦截外部图片链接,若文章中存在外部链接,会直接拒绝发布(错误码
37130
)。对于webp格式的图片(部分场景不支持),会尽可能通过CDN转码为png格式;若仍无法上传的图片,会从文章中移除而非导致发布失败。使用
--no-rehost-images
可跳过此步骤。

Gotchas

注意事项

  • This is the user's real Bilibili account. Confirm before any publish.
  • submit may 412 (anti-bot) even when the draft saved fine — the draft is the reliable result; don't loop-retry submit.
  • A wrong cover layout (
    tid
    ) / category returns
    -17
    ; the CLI auto-retries common
    tid
    values.
  • Never print
    BILIBILI_COOKIES
    — it is full account access.
  • ToS: acts only on the user's own account with their own captured cookie.
  • 操作的是用户的真实B站账号。发布前请确认用户意图。
  • 即使草稿保存成功,提交操作仍可能返回412错误(反机器人机制)——草稿是可靠的结果,请勿循环重试提交。
  • 若封面布局(
    tid
    )/分类错误,会返回
    -17
    ;CLI会自动重试常见的
    tid
    值。
  • 切勿打印
    BILIBILI_COOKIES
    ——它包含完整的账号访问权限。
  • 服务条款:仅在用户自有账号上操作,且使用用户自行获取的Cookie。

Record the output

记录输出结果

After you successfully publish and obtain the live result URL, call the built-in
publish_artifact
tool ONCE so the user can track this deliverable in My Outputs:
publish_artifact(kind="article", channel="bilibili", title="<title>", url="<the REAL returned URL>", status="delivered")
Use the real returned URL — never fabricate one. Call it once per published item, only after delivery is confirmed; skip it (or use
status="failed"
) if publishing failed. See
_shared/artifacts.md
.
成功发布并获取文章在线链接后,调用内置的
publish_artifact
工具一次,以便用户在“我的输出”中跟踪该交付物:
publish_artifact(kind="article", channel="bilibili", title="<title>", url="<the REAL returned URL>", status="delivered")
请使用真实返回的链接——切勿伪造。每个已发布内容仅调用一次,且仅在确认交付成功后调用;若发布失败,请跳过调用(或使用
status="failed"
)。详情请参阅
_shared/artifacts.md