koishi-plugin-video-parser-all 0.0.6 → 0.0.8

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.
package/lib/index.d.ts CHANGED
@@ -8,8 +8,10 @@ export interface Config {
8
8
  imageParseFormat: string;
9
9
  showVideoUrl: boolean;
10
10
  maxDescLength: number;
11
- api1: string;
12
- api2: string;
11
+ bugpkDouyinMainApi: string;
12
+ bugpkDouyinBackupApi: string;
13
+ bugpkKuaishouApi: string;
14
+ bugpkBilibiliApi: string;
13
15
  timeout: number;
14
16
  }
15
17
  export declare const Config: Schema<Config>;
package/lib/index.js CHANGED
@@ -25,76 +25,126 @@ exports.Config = koishi_1.Schema.object({
25
25
  \${封面}`),
26
26
  showVideoUrl: koishi_1.Schema.boolean().default(false),
27
27
  maxDescLength: koishi_1.Schema.number().default(200),
28
- api1: koishi_1.Schema.string().default('https://api.douyin.wtf/api/hybrid/video_data'),
29
- api2: koishi_1.Schema.string().default('https://www.alapi.cn/api/video/jh'),
28
+ bugpkDouyinMainApi: koishi_1.Schema.string().default('https://api.bugpk.com/api/douyin'),
29
+ bugpkDouyinBackupApi: koishi_1.Schema.string().default('https://api.bugpk.com/api/dyjx'),
30
+ bugpkKuaishouApi: koishi_1.Schema.string().default('https://api.bugpk.com/api/ksjx'),
31
+ bugpkBilibiliApi: koishi_1.Schema.string().default('https://api.bugpk.com/api/bilibili'),
30
32
  timeout: koishi_1.Schema.number().default(15000),
31
33
  });
32
34
  const processed = new Map();
33
35
  function apply(ctx, config) {
34
- const request = axios_1.default.create({ timeout: config.timeout });
35
- async function parse(url) {
36
- try {
37
- const res = await request.get(config.api1, { params: { url } });
38
- const d = res.data.data?.aweme_detail || res.data.data;
39
- if (d?.video?.play_addr?.url_list?.[0])
40
- return pack(d);
36
+ const request = axios_1.default.create({
37
+ timeout: config.timeout,
38
+ headers: {
39
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
41
40
  }
42
- catch { }
43
- try {
44
- const res = await request.get(config.api2, { params: { url } });
45
- const d = res.data.data;
46
- if (d?.video_url) {
47
- return {
48
- title: d.title || '',
49
- author: '未知作者',
50
- desc: d.title || '',
51
- digg: 0, comment: 0, collect: 0, share: 0, play: 0,
52
- cover: d.cover_url || '',
53
- video: d.video_url || ''
54
- };
41
+ });
42
+ // 抖音解析
43
+ function parseDouyin(data) {
44
+ const videoUrl = data.url || (data.live_photo?.[0]?.video || '');
45
+ return {
46
+ title: data.title || '无标题',
47
+ author: data.author?.name || '未知作者',
48
+ desc: data.desc || data.title || '无简介',
49
+ digg: 0, coin: 0, collect: 0, share: 0, play: 0, danmaku: 0,
50
+ cover: data.cover || '',
51
+ video: videoUrl
52
+ };
53
+ }
54
+ // 快手解析
55
+ function parseKuaishou(data) {
56
+ return {
57
+ title: data.title || '无标题',
58
+ author: '未知作者',
59
+ desc: data.title || '无简介',
60
+ digg: 0, coin: 0, collect: 0, share: 0, play: 0, danmaku: 0,
61
+ cover: data.cover || '',
62
+ video: data.url || ''
63
+ };
64
+ }
65
+ // B站解析
66
+ function parseBilibili(data) {
67
+ const videoUrl = data.url || (data.videos?.[0]?.url || '');
68
+ return {
69
+ title: data.title || '无标题',
70
+ author: data.user?.name || '未知UP主',
71
+ desc: data.description || data.title || '无简介',
72
+ digg: 0, coin: 0, collect: 0, share: 0, play: 0, danmaku: 0,
73
+ cover: data.cover || '',
74
+ video: videoUrl
75
+ };
76
+ }
77
+ // 核心:只走你给的四个接口,无任何通用API
78
+ async function parseVideo(url) {
79
+ // 抖音
80
+ if (url.includes('douyin.com') || url.includes('v.douyin.com')) {
81
+ try {
82
+ const res = await request.get(config.bugpkDouyinMainApi, { params: { url } });
83
+ if (res.data.code === 200 && res.data.data)
84
+ return parseDouyin(res.data.data);
55
85
  }
86
+ catch { }
87
+ try {
88
+ const res = await request.get(config.bugpkDouyinBackupApi, { params: { url } });
89
+ if (res.data.code === 200 && res.data.data)
90
+ return parseDouyin(res.data.data);
91
+ }
92
+ catch { }
56
93
  }
57
- catch { }
58
- return { title: '解析失败', author: '', desc: '', digg: 0, comment: 0, collect: 0, share: 0, play: 0, cover: '', video: '' };
59
- }
60
- function pack(d) {
94
+ // 快手
95
+ if (url.includes('kuaishou.com')) {
96
+ try {
97
+ const res = await request.get(config.bugpkKuaishouApi, { params: { url } });
98
+ if (res.data.code === 200 && res.data.data)
99
+ return parseKuaishou(res.data.data);
100
+ }
101
+ catch { }
102
+ }
103
+ // B站
104
+ if (url.includes('bilibili.com') || url.includes('b23.tv')) {
105
+ try {
106
+ const res = await request.get(config.bugpkBilibiliApi, { params: { url } });
107
+ if (res.data.code === 200 && res.data.data)
108
+ return parseBilibili(res.data.data);
109
+ }
110
+ catch { }
111
+ }
112
+ // 所有接口都失败 → 直接返回失败
61
113
  return {
62
- title: d.desc || '',
63
- author: d.author?.nickname || d.author?.unique_id || '',
64
- desc: d.desc || '',
65
- digg: d.statistics?.digg_count || 0,
66
- comment: d.statistics?.comment_count || 0,
67
- collect: d.statistics?.collect_count || 0,
68
- share: d.statistics?.share_count || 0,
69
- play: d.statistics?.play_count || 0,
70
- cover: d.video?.cover || d.video?.dynamic_cover || '',
71
- video: d.video?.play_addr?.url_list?.[0] || ''
114
+ title: '解析失败', author: '', desc: '不支持该链接或接口异常',
115
+ digg: 0, coin: 0, collect: 0, share: 0, play: 0, danmaku: 0,
116
+ cover: '', video: ''
72
117
  };
73
118
  }
74
- async function send(session, data) {
75
- let t = config.imageParseFormat;
76
- t = t.replace(/\${标题}/g, data.title);
77
- t = t.replace(/\${UP主}/g, data.author);
78
- t = t.replace(/\${简介}/g, data.desc.slice(0, config.maxDescLength));
79
- t = t.replace(/\${点赞}/g, data.digg.toString());
80
- t = t.replace(/\${投币}/g, '0');
81
- t = t.replace(/\${收藏}/g, data.collect.toString());
82
- t = t.replace(/\${转发}/g, data.share.toString());
83
- t = t.replace(/\${观看}/g, data.play.toString());
84
- t = t.replace(/\${弹幕}/g, data.comment.toString());
85
- t = t.replace(/\${tab}/g, '\t');
86
- t = t.replace(/\${~~~}/g, '——————————————');
87
- const [a, b] = t.split('\${封面}');
88
- if (a)
89
- await session.send(a);
119
+ async function sendResult(session, data) {
120
+ let text = config.imageParseFormat
121
+ .replace(/\${标题}/g, data.title)
122
+ .replace(/\${UP主}/g, data.author)
123
+ .replace(/\${简介}/g, data.desc.slice(0, config.maxDescLength))
124
+ .replace(/\${点赞}/g, data.digg.toString())
125
+ .replace(/\${投币}/g, data.coin.toString())
126
+ .replace(/\${收藏}/g, data.collect.toString())
127
+ .replace(/\${转发}/g, data.share.toString())
128
+ .replace(/\${观看}/g, data.play.toString())
129
+ .replace(/\${弹幕}/g, data.danmaku.toString())
130
+ .replace(/\${tab}/g, '\t')
131
+ .replace(/\${~~~}/g, '——————————————');
132
+ const [beforeCover, afterCover] = text.split('\${封面}');
133
+ if (beforeCover)
134
+ await session.send(beforeCover.trim());
90
135
  if (data.cover)
91
136
  await session.send(koishi_1.h.image(data.cover));
92
- if (b)
93
- await session.send(b);
137
+ if (afterCover)
138
+ await session.send(afterCover.trim());
94
139
  if (data.video) {
95
- await session.send(koishi_1.h.video(data.video));
96
- if (config.showVideoUrl)
97
- await session.send(data.video);
140
+ try {
141
+ await session.send(koishi_1.h.video(data.video));
142
+ if (config.showVideoUrl)
143
+ await session.send(`🔗 ${data.video}`);
144
+ }
145
+ catch {
146
+ await session.send(`📥 ${data.video}`);
147
+ }
98
148
  }
99
149
  }
100
150
  ctx.on('message', async (session) => {
@@ -110,8 +160,12 @@ function apply(ctx, config) {
110
160
  processed.set(hash, now);
111
161
  if (config.showWaitingTip)
112
162
  await session.send(config.waitingTipText);
113
- const data = await parse(url);
114
- await send(session, data);
163
+ const data = await parseVideo(url);
164
+ await sendResult(session, data);
115
165
  });
116
- ctx.logger.info('✅ 双API备用抖音解析加载完成');
166
+ setInterval(() => {
167
+ const now = Date.now();
168
+ processed.forEach((t, k) => now - t > 86400000 && processed.delete(k));
169
+ }, 3600000);
170
+ ctx.logger.info('✅ 抖音+快手+B站 纯专属接口解析(无通用API)加载完成');
117
171
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-video-parser-all",
3
3
  "description": "Koishi 视频解析插件,支持抖音/快手/B站链接解析,可自定义API和解析规则",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [