dsh-shlr-bilitoolkit 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,16 @@ import { Dynamic } from "../models.js";
12
12
  import { guessImageType } from "../util.js";
13
13
  const FEATURES = "itemOpusStyle";
14
14
  const REFERER = "https://t.bilibili.com/";
15
+ // 动态详情里的 type 是字符串枚举,删除接口要的是数字码
16
+ const DYN_TYPE_CODE = {
17
+ DYNAMIC_TYPE_NONE: 0,
18
+ DYNAMIC_TYPE_FORWARD: 1,
19
+ DYNAMIC_TYPE_DRAW: 2,
20
+ DYNAMIC_TYPE_WORD: 4,
21
+ DYNAMIC_TYPE_AV: 8,
22
+ DYNAMIC_TYPE_ARTICLE: 64,
23
+ DYNAMIC_TYPE_MUSIC: 256,
24
+ };
15
25
  export class DynamicAPI {
16
26
  client;
17
27
  constructor(client) {
@@ -191,12 +201,25 @@ export class DynamicAPI {
191
201
  }, false, { csrf: this.client.csrf }, true);
192
202
  }
193
203
  async delete(dynamicId) {
194
- const form = {
195
- dynamic_id: String(Math.floor(Number(dynamicId))),
196
- csrf: this.client.csrf,
197
- csrf_token: this.client.csrf,
198
- };
199
- await this.client.post(endpoints.DYNAMIC_DELETE, form, { Referer: REFERER });
204
+ // 动态 id 常超出 JS 安全整数范围(>2^53),必须全程按字符串传递,不能过 Number
205
+ const id = String(dynamicId);
206
+ // 删除接口需要 dyn_type(数字码)+ rid_str,都要先从动态详情取
207
+ let rawType;
208
+ let ridStr = "0";
209
+ try {
210
+ const resp = await this.client.http.get(`${endpoints.DYNAMIC_DETAIL}?id=${encodeURIComponent(id)}`, { headers: { Referer: REFERER } });
211
+ const item = resp?.data?.data?.item ?? {};
212
+ rawType = item?.type;
213
+ ridStr = String(item?.basic?.rid_str ?? item?.basic?.rid ?? "0");
214
+ }
215
+ catch {
216
+ // 详情取不到:rid_str 用默认值,类型仍必须能确定
217
+ }
218
+ const dynType = typeof rawType === "number" ? rawType : DYN_TYPE_CODE[String(rawType)];
219
+ if (dynType == null) {
220
+ throw new BiliApiError(`无法确定该动态的类型码(原始 type=${JSON.stringify(rawType)}),暂不支持删除`);
221
+ }
222
+ await this.client.post(endpoints.DYNAMIC_DELETE_V2, { dyn_id_str: id, dyn_type: dynType, rid_str: ridStr }, { Referer: REFERER }, false, { platform: "web", csrf: this.client.csrf }, true);
200
223
  }
201
224
  static dynamicId(payload) {
202
225
  const data = payload?.data ?? {};
@@ -12,21 +12,30 @@ export class VideoAPI {
12
12
  }
13
13
  async *iterRecommend(pages = 1, pageSize = 10) {
14
14
  const seen = new Set();
15
+ // 推荐流里混有广告(goto=ad)、直播、OGV 等非普通视频项,会被过滤掉,
16
+ // 所以按上限多抓一些做补偿,尽量让「要几条给几条」。
17
+ // 注意:B 站对 ps 有上限(约 30),给大了会 -400。
18
+ const ps = 30;
15
19
  for (let page = 1; page <= pages; page++) {
16
20
  const payload = await this.client.get(endpoints.RCMD_FEED, {
17
21
  fresh_idx: page,
18
22
  fresh_idx_1h: page,
19
23
  feed_version: 1,
20
- ps: pageSize,
24
+ ps,
21
25
  });
22
26
  const items = payload?.data?.item ?? [];
23
27
  let added = 0;
24
28
  for (const item of items) {
29
+ // 只保留普通视频(goto=av):排除广告 / 直播 / OGV / 推广等
30
+ if (item?.goto && item.goto !== "av")
31
+ continue;
25
32
  const video = Video.fromFeedItem(item);
26
33
  if (video && !seen.has(video.bvid)) {
27
34
  seen.add(video.bvid);
28
35
  added += 1;
29
36
  yield video;
37
+ if (seen.size >= pageSize * pages)
38
+ return;
30
39
  }
31
40
  }
32
41
  if (!added)
@@ -45,6 +45,7 @@ export declare const DYNAMIC_FEED_SPACE = "https://api.bilibili.com/x/polymer/we
45
45
  export declare const DYNAMIC_DETAIL = "https://api.bilibili.com/x/polymer/web-dynamic/v1/detail";
46
46
  export declare const DYNAMIC_CREATE = "https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create";
47
47
  export declare const DYNAMIC_CREATE_V2 = "https://api.bilibili.com/x/dynamic/feed/create/dyn";
48
+ export declare const DYNAMIC_DELETE_V2 = "https://api.bilibili.com/x/dynamic/feed/operate/remove";
48
49
  export declare const DYNAMIC_REPUBLISH = "https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/republish";
49
50
  export declare const DYNAMIC_DELETE = "https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/rm_dynamic";
50
51
  export declare const DYNAMIC_THUMB = "https://api.bilibili.com/x/dynamic/feed/dyn/thumb";
package/dist/endpoints.js CHANGED
@@ -57,6 +57,7 @@ export const DYNAMIC_FEED_SPACE = `${API_BASE}/x/polymer/web-dynamic/v1/feed/spa
57
57
  export const DYNAMIC_DETAIL = `${API_BASE}/x/polymer/web-dynamic/v1/detail`;
58
58
  export const DYNAMIC_CREATE = `${VC_BASE}/dynamic_svr/v1/dynamic_svr/create`;
59
59
  export const DYNAMIC_CREATE_V2 = `${API_BASE}/x/dynamic/feed/create/dyn`;
60
+ export const DYNAMIC_DELETE_V2 = `${API_BASE}/x/dynamic/feed/operate/remove`;
60
61
  export const DYNAMIC_REPUBLISH = `${VC_BASE}/dynamic_svr/v1/dynamic_svr/republish`;
61
62
  export const DYNAMIC_DELETE = `${VC_BASE}/dynamic_svr/v1/dynamic_svr/rm_dynamic`;
62
63
  export const DYNAMIC_THUMB = `${API_BASE}/x/dynamic/feed/dyn/thumb`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-shlr-bilitoolkit",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "深海猎人专用B站接口工具箱 dsh 插件。",
5
5
  "type": "module",
6
6
  "main": "dist/dsh.js",