yz-yuki-plugin 2.0.5-8 → 2.0.5-9

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.
@@ -6,7 +6,7 @@ class BiliApi {
6
6
  biliUpFollowFans: `https://api.bilibili.com/x/relation/stat`,
7
7
  //通过uid获取up详情 parama = { mid: uid, jsonp: jsonp }
8
8
  biliSpaceUserInfo: `https://api.bilibili.com/x/space/acc/info`,
9
- //parama = { mid: uid, jsonp: jsonp }
9
+ //parama = { mid: uid, token: '',platform: 'web', web_location: 1550101, w_webid, w_rid, wts }
10
10
  biliSpaceUserInfoWbi: `https://api.bilibili.com/x/space/wbi/acc/info`,
11
11
  //通过关键词${upKeyword}搜索up主 parama = { keyword: 'upKeyword', page: 1, search_type: 'bili_user', order: 'totalrank', pagesize: 5 }
12
12
  biliSearchUp: `https://api.bilibili.com/x/web-interface/search/type`,
@@ -18,10 +18,12 @@ class BiliApi {
18
18
  biliLiveUserInfo: 'https://api.live.bilibili.com/live_user/v1/Master/info',
19
19
  biliOpusDetail: 'https://api.bilibili.com/x/polymer/web-dynamic/v1/opus/detail'
20
20
  };
21
+ static BILIBILI_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36';
21
22
  /**header */
22
23
  static BILIBILI_HEADERS = {
23
24
  'Accept': '*/*',
24
25
  'Accept-Language': 'zh-CN,en-US;q=0.5',
26
+ 'Connection': 'keep-alive',
25
27
  'Accept-Encoding': 'gzip, deflate, br, zstd',
26
28
  'Cookie': '',
27
29
  'pragma': 'no-cache',
@@ -36,7 +38,7 @@ class BiliApi {
36
38
  'Sec-Fetch-User': '?0',
37
39
  'Priority': 'u=4',
38
40
  'TE': 'trailers',
39
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0'
41
+ 'User-Agent': this.BILIBILI_USER_AGENT
40
42
  };
41
43
  /**Login header */
42
44
  static BIlIBILI_LOGIN_HEADERS = {
@@ -70,7 +72,21 @@ class BiliApi {
70
72
  'Sec-Fetch-User': '?1',
71
73
  'TE': 'trailers',
72
74
  'Upgrade-Insecure-Requests': '1',
73
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0'
75
+ 'User-Agent': this.BILIBILI_USER_AGENT
76
+ };
77
+ static BILIBILI_DYNAMIC_SPACE_HEADERS = {
78
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
79
+ 'Accept-Encoding': 'gzip, deflate, br, zstd',
80
+ 'Accept-Language': 'zh-CN,en-US;q=0.5',
81
+ 'Connection': 'keep-alive',
82
+ 'Priority': 'u=0, i',
83
+ 'Sec-Fetch-Dest': 'document',
84
+ 'Sec-Fetch-Mode': 'navigate',
85
+ 'Sec-Fetch-Site': 'none',
86
+ 'Sec-Fetch-User': '?1',
87
+ 'Sec-GPC': '1',
88
+ 'Upgrade-Insecure-Requests': '1',
89
+ 'User-Agent': this.BILIBILI_USER_AGENT
74
90
  };
75
91
  }
76
92
 
@@ -5,10 +5,12 @@ async function getDmImg() {
5
5
  const dm_img_str = 'V2ViR0wgMS';
6
6
  //webgl unmasked renderer的值拼接webgl unmasked vendor的值的base64编码
7
7
  const dm_cover_img_str = 'QU5HTEUgKEludGVsLCBJbnRlbChSKSBIRCBHcmFwaGljcyBEaXJlY3QzRDExIHZzXzVfMCBwc181XzApLCBvciBzaW1pbGFyR29vZ2xlIEluYy4gKEludGVsKQ';
8
+ const dm_img_inter = { ds: [], wh: [0, 0, 0], of: [0, 0, 0] };
8
9
  return {
9
10
  dm_img_list: dm_img_list,
10
11
  dm_img_str: dm_img_str,
11
- dm_cover_img_str: dm_cover_img_str
12
+ dm_cover_img_str: dm_cover_img_str,
13
+ dm_img_inter: dm_img_inter
12
14
  };
13
15
  }
14
16
 
@@ -4,6 +4,7 @@ import { BiliApi } from './bilibili.api.js';
4
4
  import { readSyncCookie, cookieWithBiliTicket, readSavedCookieItems, readSavedCookieOtherItems } from './bilibili.models.js';
5
5
  import { getWbiSign } from './bilibili.wbi.js';
6
6
  import { getDmImg } from './bilibili.dm.img.js';
7
+ import { getWebId } from './bilibili.w_webid.js';
7
8
 
8
9
  class BiliGetWebData {
9
10
  constructor(e) { }
@@ -18,7 +19,7 @@ class BiliGetWebData {
18
19
  'host_mid': uid,
19
20
  'timezone_offset': -480,
20
21
  'platform': 'web',
21
- 'features': 'itemOpusStyle,listOnlyfans,opusBigCover,onlyfansVote',
22
+ 'features': 'itemOpusStyle,listOnlyfans,opusBigCover,onlyfansVote,decorationCard,forwardListHidden,ugcDelete,onlyfansQaCard',
22
23
  'web_location': '333.999',
23
24
  ...dmImg,
24
25
  'x-bili-device-req-json': { platform: 'web', device: 'pc' },
@@ -48,14 +49,20 @@ class BiliGetWebData {
48
49
  const url = BiliApi.BILIBIL_API.biliSpaceUserInfoWbi;
49
50
  let { cookie } = await readSyncCookie();
50
51
  cookie = await cookieWithBiliTicket(cookie);
52
+ const dmImg = await getDmImg();
51
53
  const data = {
52
54
  mid: uid,
53
- jsonp: 'jsonp'
55
+ token: '',
56
+ platform: 'web',
57
+ web_location: 1550101,
58
+ ...dmImg
54
59
  };
55
60
  let signCookie = (await readSavedCookieItems(cookie, ['SESSDATA'], false)) || (await readSavedCookieOtherItems(cookie, ['SESSDATA']));
61
+ const w_webid = await getWebId(uid);
56
62
  const { w_rid, time_stamp } = await getWbiSign(data, BiliApi.BILIBILI_HEADERS, signCookie);
57
63
  const params = {
58
64
  ...data,
65
+ w_webid: w_webid,
59
66
  w_rid: w_rid,
60
67
  wts: time_stamp
61
68
  };
@@ -65,8 +72,8 @@ class BiliGetWebData {
65
72
  headers: lodash.merge(BiliApi.BILIBILI_HEADERS, {
66
73
  Cookie: `${cookie}`,
67
74
  Host: `api.bilibili.com`,
68
- Origin: 'https://www.bilibili.com',
69
- Referer: `https://www.bilibili.com/`
75
+ Origin: 'https://space.bilibili.com',
76
+ Referer: `https://space.bilibili.com/${uid}/dynamic`
70
77
  })
71
78
  });
72
79
  return res;
@@ -22,7 +22,7 @@ class BiliTask {
22
22
  const resjson = await resp.data;
23
23
  if (!resjson || resjson.code !== 0 || resjson.code === -352) {
24
24
  await postGateway(cookie);
25
- if (count < 3) {
25
+ if (count < 2) {
26
26
  await this.randomDelay(2000, 8000); // 随机延时2-8秒
27
27
  await this.hendleEventDynamicData(uid, count + 1);
28
28
  logger.error(`获取 ${uid} 动态,Gateway count:${String(count)}`);
@@ -78,11 +78,11 @@ class BiliTask {
78
78
  dynamicList[subInfoOfup.uid] = dynamicData;
79
79
  }
80
80
  else if (resp.code === -352) {
81
- logger.error(`获取 ${subInfoOfup.uid} 动态失败,resCode:-352`);
82
- continue;
81
+ logger.error(`获取 ${subInfoOfup.uid} 动态失败,resCode:-352,请待下次任务自动重试`);
82
+ return;
83
83
  }
84
84
  else if (resp.code !== 0) {
85
- logger.error(`获取 ${subInfoOfup.uid} 动态失败,resCode:${resp.code}`);
85
+ logger.error(`获取 ${subInfoOfup.uid} 动态失败,resCode:${resp.code},请待下次任务自动重试`);
86
86
  return;
87
87
  }
88
88
  }
@@ -0,0 +1,43 @@
1
+ import axios from 'axios';
2
+ import lodash from 'lodash';
3
+ import { Redis } from 'yunzaijs';
4
+ import { BiliApi } from './bilibili.api.js';
5
+ import { readSyncCookie, cookieWithBiliTicket } from './bilibili.models.js';
6
+
7
+ async function getWebId(uid) {
8
+ const w_webid_key = 'Yz:yuki:bili:w_webid';
9
+ const w_webid = await Redis.get(w_webid_key);
10
+ if (w_webid) {
11
+ return w_webid;
12
+ }
13
+ else {
14
+ const url = `https://space.bilibili.com/${uid ? uid : 401742377}/dynamic`;
15
+ let { cookie } = await readSyncCookie();
16
+ cookie = await cookieWithBiliTicket(cookie);
17
+ const res = await axios.get(url, {
18
+ timeout: 8000,
19
+ headers: lodash.merge(BiliApi.BILIBILI_DYNAMIC_SPACE_HEADERS, {
20
+ Cookie: `${cookie}`,
21
+ Host: `space.bilibili.com`
22
+ })
23
+ });
24
+ const htmlContent = await res.data;
25
+ const htmlContentRegex = /="__RENDER_DATA__"\s*type="application\/json">(.*?)<\/script>/;
26
+ const __RENDER_DATA__ = htmlContent.match(htmlContentRegex);
27
+ if (__RENDER_DATA__ && __RENDER_DATA__[1]) {
28
+ const decoded__RENDER_DATA__JsonString = decodeURIComponent(__RENDER_DATA__[1]);
29
+ const accessIdRegex = /"access_id":"(.*?)"/;
30
+ const access_id = decoded__RENDER_DATA__JsonString.match(accessIdRegex);
31
+ if (access_id && access_id[1]) {
32
+ await Redis.set(w_webid_key, access_id[1], { EX: 43197 * 1000 });
33
+ return access_id[1];
34
+ }
35
+ else {
36
+ console.error('Failed to get access_id from __RENDER_DATA__');
37
+ return null;
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ export { getWebId };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "2.0.5-8",
3
+ "version": "2.0.5-9",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",