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 +4 -2
- package/lib/index.js +114 -60
- package/package.json +1 -1
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
|
-
|
|
12
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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:
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const [
|
|
88
|
-
if (
|
|
89
|
-
await session.send(
|
|
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 (
|
|
93
|
-
await session.send(
|
|
137
|
+
if (afterCover)
|
|
138
|
+
await session.send(afterCover.trim());
|
|
94
139
|
if (data.video) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
114
|
-
await
|
|
163
|
+
const data = await parseVideo(url);
|
|
164
|
+
await sendResult(session, data);
|
|
115
165
|
});
|
|
116
|
-
|
|
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
|
}
|