RayWangQvQ/BiliBiliToolPro · error · BiliBusinessException
re.Message
Error message
re.Message
What it means
Thrown by GetRandomVideoOfUp when the Bilibili search-by-up-id API returns a non-zero code. Any failure listing an UP主's videos (private/banned account, API rejection, risk control) is surfaced directly to the caller as BiliBusinessException(re.Message).
Solutions
- Check re.Message to identify the specific Bilibili error code.
- Verify the UP id (mid) exists and the account still has public videos.
- Recompute the video total (GetVideoCountOfUp) before picking a random page so pn stays in range.
- Refresh the Bilibili cookie if the message indicates authentication failure.
Example fix
// before: random page from possibly stale total pn = new Random().Next(1, total + 1), // after: refresh total and clamp var total = await GetVideoCountOfUp(upId, ck); if (total <= 0) return null; pn = new Random().Next(1, total + 1)
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure the UP has videos and total is fresh before picking a random page
var total = await videoDomainService.GetVideoCountOfUp(upId, ck);
if (total <= 0)
return; // skip this UP, no videos to interact with Type guard
bool CanInteractWithUp(long upId, int total) => upId > 0 && total > 0;
Try / catch
try
{
var video = await videoDomainService.GetRandomVideoOfUp(upId, total, ck);
}
catch (BiliBusinessException ex)
{
logger.LogWarning("获取UP主({upId})视频失败,跳过:{msg}", upId, ex.Message);
} Prevention
- Refresh the UP's video count before generating a random page number.
- Validate the UP id/mid exists and is public.
- Keep the cookie fresh to avoid auth-related non-zero codes.
When it happens
Trigger: apiApi.SearchVideosByUpId responds with re.Code != 0 — the UP id doesn't exist or the account is closed/hidden, the pn page number (random) exceeds available pages and Bilibili rejects it, cookie invalid, or risk-control code returned.
Common situations: Target UP主 deleted/privated all videos so the search API errors; the random page number computed from a stale total exceeds the current page count; cookie expired; Bilibili search API changed behavior.
Related errors
AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12).
Data as JSON: /api/errors/e2f5803eb1c8bb9c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ray.BiliBiliTool.DomainService/VideoDomainService.cs:70
{
if (total <= 0)
return null;
var req = new SearchVideosByUpIdDto()
{
mid = upId,
ps = 1,
pn = new Random().Next(1, total + 1),
};
BiliApiResponse<SearchUpVideosResponse> re = await apiApi.SearchVideosByUpId(
req,
ck.ToString()
);
if (re.Code != 0)
{
throw new BiliBusinessException(re.Message);
}
return re.Data?.List?.Vlist.FirstOrDefault();
}
/// <summary>
/// 获取UP主的视频总数量
/// </summary>
/// <param name="upId"></param>
/// <returns></returns>
public async Task<int> GetVideoCountOfUp(long upId, BiliCookie ck)
{
var req = new SearchVideosByUpIdDto() { mid = upId };
BiliApiResponse<SearchUpVideosResponse> re = await apiApi.SearchVideosByUpId(
req,
ck.ToString()
);View on GitHub (pinned to c599b2c0da)