Skip to navigation

How do I use a Bilibili video link, BV ID, AV ID and uploader mid?

To fetch Bilibili video comments, take the BV or AV ID after /video/ in the full video URL and pass the ID to bilibili.app.fetch_video_comments as either bv_id or av_id. The Web comments action bilibili.web.fetch_video_comments takes the BV ID only. The uploader mid from a space.bilibili.com/ profile URL identifies the creator’s account, not a video, so do not use mid for comments. You do not need to retrieve video details to convert between ID types.

What does each identifier target?

InformationObjectUse here
BV…One videoPreserve case and use App comment input bv_id
av… in an old video linkOne videoRemove the explicit av prefix and use the remaining digit string as av_id
mid after space.bilibili.com/Uploader or userAccount research; not a video identifier
A returned comment identifierOne commentKeep separately for a later reply request
A b23.tv short linkA share entry whose destination needs confirmationObtain the short link’s target video URL first; the local helper does not expand short links

AV IDs, mid values and comment identifiers can all look numeric. Store each identifier with the link or response it came from, and never substitute one type for another. Keep long numbers as text, including in spreadsheets.

Can I retrieve comments directly with a BV ID?

Yes. Pass the BV ID as bv_id to data:bilibili.app.fetch_video_comments; do not retrieve video details just to convert identifiers. data:bilibili.app.fetch_video_comments also accepts a confirmed av_id; send one of the two. The current data:bilibili.web.fetch_video_comments input declares BV only.

The helper prepare_bilibili_comments.py below converts an explicit BV ID, AV ID or long video URL into request.json for the first page of time-ordered comments. To choose recent or popular feedback, see comment ordering.

Prepare one newest-comment request from an explicit ID or long URL

Save the script below as prepare_bilibili_comments.py. The script takes one of three modes: bv, av or url. The script’s regular expressions check syntax only and do not prove that a video exists. In url mode the script accepts only HTTPS /video/ URLs on bilibili.com or www.bilibili.com, and rejects space, live-room and short links, URLs with user information and URLs with conflicting identity query parameters. Ordinary tracking parameters and fragments are left out of the API request.

import json
import pathlib
import re
import sys
from urllib.parse import urlsplit, parse_qs
kind, value, destination = sys.argv[1:4]
bv = r"BV[0-9A-Za-z]{10}"
av = r"[1-9][0-9]*"
source_kind = kind
ignored_query = False
if kind == "url":
if any(c.isspace() or ord(c) < 32 or ord(c) == 127 for c in value):
raise ValueError("Use an intact public URL")
u = urlsplit(value)
if u.scheme != "https" or u.hostname not in {"bilibili.com", "www.bilibili.com"} or u.username is not None or u.password is not None or u.port not in (None, 443):
raise ValueError("Use a public HTTPS bilibili.com video URL; resolve short links separately")
match = re.fullmatch(r"/video/(" + bv + r"|av" + av + r")/?", u.path)
if not match:
raise ValueError("Expected a video URL, not an account, live room or short link")
if any(k.lower() in {"bvid", "bv_id", "aid", "av_id", "mid", "oid"} for k in parse_qs(u.query, keep_blank_values=True)):
raise ValueError("Ambiguous identity query; copy an unambiguous public video URL")
value = match[1]
kind = "bv" if value.startswith("BV") else "av"
if kind == "av":
value = value[2:]
ignored_query = bool(u.query or u.fragment)
if kind not in {"bv", "av"} or not re.fullmatch(bv if kind == "bv" else av, value):
raise ValueError("Use explicit bv or av text; do not pass mid, a whole URL as an ID or a numeric conversion")
request = {"action": "bilibili.app.fetch_video_comments", "params": {kind + "_id": value, "mode": 2, "next_offset": 1}}
audit = {"input_kind": source_kind, "id_type": kind, "id_text": value, "query_or_fragment_discarded": ignored_query, "executed": False, "identity_scope": "syntax and URL shape only; existence and target not independently verified"}
target = pathlib.Path(destination)
target.mkdir(parents=False, exist_ok=False)
(target / "request.json").write_text(json.dumps(request, ensure_ascii=False, indent=2), encoding="utf-8")
(target / "input-audit.json").write_text(json.dumps(audit, ensure_ascii=False, indent=2), encoding="utf-8")
print(json.dumps({"prepared": True, "executed": False, "id_type": kind}))

Run one of the three commands for a given video, not all three:

python3 prepare_bilibili_comments.py bv BV18SCrBGE9E comments-bv
python3 prepare_bilibili_comments.py av 115568241811221 comments-av
python3 prepare_bilibili_comments.py url 'https://www.bilibili.com/video/BV18SCrBGE9E/?p=2' comments-link

The script writes only request.json and input-audit.json and makes no network call. In request.json, mode=2 requests time order and next_offset=1 selects the first page; the prepared request does not paginate automatically or guarantee complete historical order. The script discards a URL’s p part selector because bilibili.app.fetch_video_comments has no part input, so do not label the result as comments for that part only.

Check the target and budget before sending

  1. Open request.json and confirm that the request contains exactly one bv_id or av_id and that the value matches the original target text. A numeric AV ID is not a creator mid.
  2. If all you have is an unexplained number, stop instead of paying for requests to guess the number’s type.
  3. Choose a new output directory for each run; the script rejects an existing directory.
  4. For hot comments, inspect the mode contract, then change mode to 3 on purpose. Do not describe one result as both the newest and the hot ranking.

See the current pricing page. With a known BV or AV ID, send the comment request directly, and retrieve video details, more pages or replies only when the task needs them.

curl --fail-with-body -sS https://api.beatapi.io/v1/social-data/call \
-H "Authorization: Bearer $BEATAPI_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary @comments-bv/request.json \
-D comments-bv/response.headers -o comments-bv/response.json

If you chose another directory, change the paths to match, and do not rerun the command over a previous response. Before the next step, check the HTTP status, the public error and request_id; HTTP 200 alone does not mean the response contains usable comments. bilibili.app.fetch_video_comments has no published, verifiable output paths for the comment list, replies or cursor yet, so request.json is a request, not a comment CSV. Keep a failed response as a failure instead of counting it as zero comments.

Sources: the App and Web comment input contracts. Offline tests of prepare_bilibili_comments.py cover BV case, long AV text, BV and AV long URLs, rejection of mid, short links, lookalike hosts and identity query parameters, existing-directory protection and zero network calls.

Only an AV ID · App pagination · Bilibili questions