yz-yuki-plugin 1.0.1 → 1.0.2

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.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @type {import("puppeteer").Configuration}
3
+ */
4
+ module.exports = require('react-puppeteer/.puppeteerrc')
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.2
2
+ * 新增支持获取完整文章动态内容
3
+ * 修复宫格样式
4
+
1
5
  # 1.0.1
2
6
  * 修复了一些bug
3
7
  * 优化了一些功能
@@ -34,8 +34,8 @@ banWords:
34
34
  # 设置B站动态消息模式 0 文字模式 1 图片模式
35
35
  pushMsgMode: 1
36
36
 
37
- # 是否启用九宫格样式,1 启用,0 不启用。此为最高优先级,若启用九宫格样式,则分片截图模式设置推送每条动态的全部完整内容将无效
37
+ # 是否启用九宫格样式:默认 1 启用,0 不启用。此为最高优先级,九宫格为动态模式,特定大小/长宽比的图片资源将会动态启用九宫格/四宫格/无宫格样式。
38
38
  boxGrid: 1
39
39
 
40
- # B站图片动态推送是否启用分页截图模式: 0 不启用,动态内容过长时候将只推送最前部分 1 启用,将会推送每条动态的全部内容
40
+ # B站动态卡片分页截图模式:默认 1 启用 0 不启用。启用,将会推送每条动态的全部内容;不启用,动态内容过长时候将只推送7500px长度的动态卡片,需关闭宫格模式。
41
41
  isSplit: 1
@@ -31,11 +31,11 @@ banWords:
31
31
  - 关键词1
32
32
  - 关键词2
33
33
 
34
- # 设置B站动态消息模式 0 文字模式 1 图片模式
34
+ # 设置微博动态消息模式 0 文字模式 1 图片模式
35
35
  pushMsgMode: 1
36
36
 
37
- # 是否启用九宫格样式,1 启用,0 不启用。此为最高优先级,若启用九宫格样式,则分片截图模式设置推送每条动态的全部完整内容将无效
37
+ # 是否启用九宫格样式:默认 1 启用,0 不启用。此为最高优先级,九宫格为动态模式,特定大小/长宽比的图片资源将会动态启用九宫格/四宫格/无宫格样式。
38
38
  boxGrid: 1
39
39
 
40
- # 微博图片动态推送是否启用分页截图模式: 0 不启用,动态内容过长时候将只推送最前部分 1 启用,将会推送每条动态的全部内容
40
+ # 微博动态卡片分页截图模式:默认 1 启用 0 不启用。启用,将会推送每条动态的全部内容;不启用,动态内容过长时候将只推送7500px长度的动态卡片,需关闭宫格模式。
41
41
  isSplit: 1
@@ -10,6 +10,8 @@ const Content = ({ data }) => {
10
10
  }
11
11
  return null;
12
12
  })));
13
+ const boxGrid_4 = React.createElement("link", { key: "0", rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.box.grid.4.css') });
14
+ const boxGrid_9 = React.createElement("link", { key: "0", rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.box.grid.9.css') });
13
15
  function getBoxGridStyle(pics) {
14
16
  if (!Array.isArray(pics) || pics.length === 0) {
15
17
  return null;
@@ -62,8 +64,6 @@ const Content = ({ data }) => {
62
64
  return null;
63
65
  }
64
66
  const boxGrid = data.boxGrid && (data.pics && getBoxGridStyle(data.pics));
65
- const boxGrid_4 = React.createElement("link", { key: "0", rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.box.grid.4.css') });
66
- const boxGrid_9 = React.createElement("link", { key: "0", rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.box.grid.9.css') });
67
67
  const contentCss = React.createElement("link", { rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.css') });
68
68
  switch (data.type) {
69
69
  case 'DYNAMIC_TYPE_LIVE_RCMD':
@@ -44,6 +44,25 @@ class BiliApi {
44
44
  'Sec-Fetch-User': '?1',
45
45
  'TE': 'trailers',
46
46
  };
47
+ static BILIBILI_ARTICLE_HEADERS = {
48
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8',
49
+ 'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
50
+ 'Accept-Encoding': 'gzip, deflate, br',
51
+ 'Content-type': 'text/html; charset=utf-8',
52
+ Cookie: '',
53
+ 'pragma': "no-cache",
54
+ "Cache-control": "no-cache",
55
+ 'DNT': '1',
56
+ 'Sec-GPC': '1',
57
+ 'sec-ch-ua-mobile': '?0',
58
+ 'Sec-Fetch-Dest': 'document',
59
+ 'Sec-Fetch-Mode': 'navigate',
60
+ 'Sec-Fetch-Site': 'same-site',
61
+ 'Sec-Fetch-User': '?1',
62
+ 'TE': 'trailers',
63
+ "Upgrade-Insecure-Requests": '1',
64
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
65
+ };
47
66
  }
48
67
 
49
68
  export { BiliApi };
@@ -1,8 +1,12 @@
1
1
  import moment from 'moment';
2
2
  import { Bot, Segment } from 'yunzai';
3
+ import { readSyncCookie } from './bilibili.models.js';
4
+ import { BiliApi } from './bilibili.api.js';
5
+ import axios from 'axios';
6
+ import lodash from 'lodash';
3
7
 
4
8
  class BiliQuery {
5
- static formatDynamicData(data) {
9
+ static async formatDynamicData(data) {
6
10
  const BiliDrawDynamicLinkUrl = "https://m.bilibili.com/dynamic/";
7
11
  let desc, pics = [], majorType;
8
12
  let formatData = { data: {} };
@@ -71,8 +75,19 @@ class BiliQuery {
71
75
  pics = desc?.pics;
72
76
  pics = pics.map((item) => { return { url: item?.url, width: item?.width, height: item?.height }; }) || [];
73
77
  formatData.data.title = desc?.title;
74
- formatData.data.pics = pics;
75
- formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || "";
78
+ if ((desc?.summary?.text)?.length >= 480) {
79
+ const readInfo = await this.getFullArticleContent(this.formatUrl(desc?.jump_url));
80
+ formatData.data.content = this.praseFullArticleContent(readInfo?.content);
81
+ formatData.data.pics = [];
82
+ if ((formatData.data.content) === null) {
83
+ formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || "";
84
+ formatData.data.pics = pics;
85
+ }
86
+ }
87
+ else {
88
+ formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || "";
89
+ formatData.data.pics = pics;
90
+ }
76
91
  }
77
92
  else {
78
93
  desc = data?.modules?.module_dynamic?.major?.article || {};
@@ -158,6 +173,35 @@ class BiliQuery {
158
173
  return nodes;
159
174
  }
160
175
  };
176
+ static async getFullArticleContent(postUrl) {
177
+ const Cookie = await readSyncCookie();
178
+ try {
179
+ const response = await axios.get(postUrl, {
180
+ headers: lodash.merge(BiliApi.BILIBILI_ARTICLE_HEADERS, { "Cookie": `${Cookie}`, "Host": "www.bilibili.com" }),
181
+ responseType: 'text'
182
+ });
183
+ const text = response.data;
184
+ const match = text.match(/"readInfo":([\s\S]+?),"readViewInfo":/);
185
+ if (match) {
186
+ const full_json_text = match[1];
187
+ const readInfo = JSON.parse(full_json_text);
188
+ return readInfo;
189
+ }
190
+ }
191
+ catch (err) {
192
+ logger?.error(`优纪插件:获取B站完整文章内容失败 [ ${postUrl} ] : ${err}`);
193
+ return null;
194
+ }
195
+ }
196
+ static praseFullArticleContent(content) {
197
+ content = content.replace(/\n/g, '<br>');
198
+ const imgTagRegex = /<img[^>]*data-src="([^"]*)"[^>]*>/g;
199
+ content = content.replace(imgTagRegex, (match, p1) => {
200
+ const newSrc = this.formatUrl(p1);
201
+ return match.replace('data-src', 'src').replace(p1, newSrc);
202
+ });
203
+ return content;
204
+ }
161
205
  static formatUrl(url) {
162
206
  return 0 == url.indexOf('//') ? `https:${url}` : url;
163
207
  }
@@ -94,7 +94,7 @@ class BiliTask {
94
94
  if (!author?.pub_ts)
95
95
  continue;
96
96
  if (Number(now - author.pub_ts) > interval) {
97
- logger.info(`超过间隔时间,跳过该up [ ${author?.name} : ${author?.mid} ] ${author?.pub_time} 的动态`);
97
+ logger.info(`超过间隔,跳过 [ ${author?.name} : ${author?.mid} ] ${author?.pub_time} 的动态`);
98
98
  continue;
99
99
  }
100
100
  if (dynamicItem.type === "DYNAMIC_TYPE_FORWARD" && !biliConfigData.pushTransmit)
@@ -53,7 +53,7 @@ class WeiboTask {
53
53
  if (!raw_post?.mblog?.created_at)
54
54
  continue;
55
55
  if (Number(now - (WeiboQuery.getDynamicCreatetDate(raw_post) / 1000)) > interval) {
56
- logger.info(`超过间隔时间,跳过该博主 [ ${user?.screen_name} : ${user?.id} ] ${raw_post?.mblog?.created_at} 的动态`);
56
+ logger.info(`超过间隔,跳过 [ ${user?.screen_name} : ${user?.id} ] ${raw_post?.mblog?.created_at} 的动态`);
57
57
  continue;
58
58
  }
59
59
  if (dynamicItem.type === "DYNAMIC_TYPE_FORWARD" && !weiboConfigData.pushTransmit)
@@ -44,4 +44,23 @@ export declare class BiliApi {
44
44
  'Sec-Fetch-User': string;
45
45
  TE: string;
46
46
  };
47
+ static BILIBILI_ARTICLE_HEADERS: {
48
+ Accept: string;
49
+ 'Accept-Language': string;
50
+ 'Accept-Encoding': string;
51
+ 'Content-type': string;
52
+ Cookie: string;
53
+ pragma: string;
54
+ "Cache-control": string;
55
+ DNT: string;
56
+ 'Sec-GPC': string;
57
+ 'sec-ch-ua-mobile': string;
58
+ 'Sec-Fetch-Dest': string;
59
+ 'Sec-Fetch-Mode': string;
60
+ 'Sec-Fetch-Site': string;
61
+ 'Sec-Fetch-User': string;
62
+ TE: string;
63
+ "Upgrade-Insecure-Requests": string;
64
+ 'User-Agent': string;
65
+ };
47
66
  }
@@ -1,11 +1,13 @@
1
1
  export declare class BiliQuery {
2
- static formatDynamicData(data: any): {
2
+ static formatDynamicData(data: any): Promise<{
3
3
  uid: any;
4
4
  data: {
5
5
  [key: string]: any;
6
6
  };
7
- };
7
+ }>;
8
8
  static parseRichTextNodes: (nodes: any[] | string | any) => any;
9
+ static getFullArticleContent(postUrl: string): Promise<any>;
10
+ static praseFullArticleContent(content: string): string;
9
11
  static formatUrl(url: string): string;
10
12
  static formatTextDynamicData(upName: string, data: any, isForward: boolean, setData: any): Promise<any>;
11
13
  static dynamicContentLimit(content: string, setData: any): string;
@@ -22,7 +22,7 @@ class YukiPuppeteerRender extends Puppeteer {
22
22
  if (Options?.header) {
23
23
  await page.setExtraHTTPHeaders(Options.header);
24
24
  }
25
- await page.goto(`file://${htmlPath}`, { timeout: Options?.timeout ?? 120000, waitUntil: 'networkidle2' });
25
+ await page.goto(`file://${htmlPath}`, { timeout: Options?.timeout ?? 120000, waitUntil: ["load", "networkidle2"] });
26
26
  const body = await page.$(Options?.tab ?? 'body');
27
27
  if (!body)
28
28
  return false;
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "main.js",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/snowtafir/yuki-plugin.git"
12
+ },
9
13
  "scripts": {
10
14
  "app": "npm run css && node --no-warnings=ExperimentalWarning --loader ts-node/esm src/main.js",
11
15
  "dev": "npm run css && nodemon",
@@ -70,7 +74,6 @@
70
74
  "rollup-plugin-copy": "^3.5.0",
71
75
  "rollup-plugin-dts": "^6.1.1",
72
76
  "rollup-plugin-ignore": "^1.0.10",
73
- "rollup-plugin-terser": "^7.0.2",
74
77
  "tailwindcss": "^3.4.3",
75
78
  "ts-node": "^10.9.2",
76
79
  "typescript": "^5.4.5",
@@ -85,7 +88,8 @@
85
88
  "CHANGELOG.md",
86
89
  "README.md",
87
90
  "package.json",
88
- "LICENSE"
91
+ "LICENSE",
92
+ ".puppeteerrc.cjs"
89
93
  ],
90
94
  "types": "lib/types",
91
95
  "exports": {
@@ -5,6 +5,10 @@
5
5
  font-style: normal;
6
6
  }
7
7
 
8
+ .content-text-title {
9
+ margin-top: 10px;
10
+ }
11
+
8
12
  .content {
9
13
  font-size: 20px;
10
14
  color: #333;