@ikenxuan/amagi 4.2.3 → 4.2.4
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.
|
@@ -8,7 +8,7 @@ class DouyinAPI {
|
|
|
8
8
|
return `https://www.douyin.com/aweme/v1/web/comment/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id=${data.aweme_id}&cursor=${data.cursor ?? 0}&count=${data.number ?? 50}&item_type=0&insert_ids=&whale_cut_token=&cut_version=1&rcFT=&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=125.0.0.0&browser_online=true&engine_name=Blink&engine_version=125.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&msToken=${douyinSign.Mstoken(116)}&verifyFp=${fp}&fp=${fp}`;
|
|
9
9
|
}
|
|
10
10
|
二级评论(data) {
|
|
11
|
-
return `https://www.douyin.com/aweme/v1/web/comment/list/reply/?device_platform=webapp&aid=6383&channel=channel_pc_web&item_id=${data.aweme_id}&comment_id=${data.comment_id}&cut_version=1&cursor
|
|
11
|
+
return `https://www.douyin.com/aweme/v1/web/comment/list/reply/?device_platform=webapp&aid=6383&channel=channel_pc_web&item_id=${data.aweme_id}&comment_id=${data.comment_id}&cut_version=1&cursor=${data.cursor}&count=${data.number}&item_type=0&update_version_code=170400&pc_client_type=1&pc_libra_divert=Windows&support_h265=1&support_dash=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1552&screen_height=970&browser_language=zh-CN&browser_platform=Win32&browser_name=Edge&browser_version=132.0.0.0&browser_online=true&engine_name=Blink&engine_version=132.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7386217876267796006&verifyFp=${fp}&fp=${fp}`;
|
|
12
12
|
}
|
|
13
13
|
动图(data) {
|
|
14
14
|
return `https://www.iesdouyin.com/web/api/v2/aweme/slidesinfo/?reflow_source=reflow_page&web_id=7326472315356857893&device_id=7326472315356857893&aweme_ids=[${data.aweme_id}]&request_source=200&msToken=${douyinSign.Mstoken(116)}&verifyFp=${fp}&fp=${fp}`;
|
|
@@ -5,8 +5,10 @@ const defheaders = {
|
|
|
5
5
|
priority: 'u=0, i',
|
|
6
6
|
'content-type': 'application/json',
|
|
7
7
|
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
|
8
|
-
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
9
|
-
referer: 'https://www.douyin.com/'
|
|
8
|
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0',
|
|
9
|
+
referer: 'https://www.douyin.com/',
|
|
10
|
+
'accept-encoding': 'gzip, deflate, br',
|
|
11
|
+
connection: 'keep-alive'
|
|
10
12
|
};
|
|
11
13
|
export const DouyinData = async (data, cookie) => {
|
|
12
14
|
const headers = {
|
|
@@ -27,57 +29,18 @@ export const DouyinData = async (data, cookie) => {
|
|
|
27
29
|
}
|
|
28
30
|
case '评论数据': {
|
|
29
31
|
validateData(data, ['aweme_id']);
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
let tmpresp = {};
|
|
34
|
-
// 循环直到获取到足够数量的评论
|
|
35
|
-
while (fetchedComments.length < Number(data.number ?? 50)) {
|
|
36
|
-
// 计算本次请求需要获取的评论数量,确保不超过剩余需要获取的数量
|
|
37
|
-
const requestCount = Math.min(Number(data.number ?? 50) - fetchedComments.length, maxPageSize);
|
|
38
|
-
// 构建请求URL
|
|
39
|
-
const url = douyinAPI.评论({
|
|
40
|
-
aweme_id: data.aweme_id,
|
|
41
|
-
number: requestCount,
|
|
42
|
-
cursor
|
|
43
|
-
});
|
|
44
|
-
// 发起请求获取评论数据
|
|
45
|
-
const response = await GlobalGetData({
|
|
46
|
-
url: `${url}&a_bogus=${douyinSign.AB(url)}`,
|
|
47
|
-
headers,
|
|
48
|
-
...data
|
|
49
|
-
});
|
|
50
|
-
if (!response.comments) {
|
|
51
|
-
response.comments = [];
|
|
52
|
-
}
|
|
53
|
-
// 将获取到的评论数据添加到数组中
|
|
54
|
-
fetchedComments.push(...response.comments);
|
|
55
|
-
// 更新tmpresp为最后一次请求的响应
|
|
56
|
-
tmpresp = response;
|
|
57
|
-
// 如果本次请求的评论数量小于请求的数量,说明已经没有更多评论了
|
|
58
|
-
if (response.comments.length < requestCount) {
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
// 更新游标值,准备下一次请求
|
|
62
|
-
cursor = response.cursor;
|
|
63
|
-
}
|
|
64
|
-
// 使用最后一次请求的接口响应格式,替换其中的评论数据
|
|
65
|
-
const finalResponse = {
|
|
66
|
-
...tmpresp,
|
|
67
|
-
comments: data.number === 0 ? [] : fetchedComments.slice(0, Number(data.number ?? 50)),
|
|
68
|
-
cursor: data.number === 0 ? 0 : fetchedComments.length
|
|
69
|
-
};
|
|
70
|
-
return finalResponse;
|
|
32
|
+
const urlGenerator = (params) => douyinAPI.评论(params);
|
|
33
|
+
const response = await fetchPaginatedData(urlGenerator, data, 50, headers);
|
|
34
|
+
return response;
|
|
71
35
|
}
|
|
72
|
-
case '
|
|
36
|
+
case '指定评论回复数据': {
|
|
73
37
|
validateData(data, ['aweme_id', 'comment_id']);
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
...data
|
|
38
|
+
const urlGenerator = (params) => douyinAPI.二级评论(params);
|
|
39
|
+
const response = await fetchPaginatedData(urlGenerator, data, 3, {
|
|
40
|
+
...headers,
|
|
41
|
+
referer: `https://www.douyin.com/note/${data.aweme_id}`
|
|
79
42
|
});
|
|
80
|
-
return
|
|
43
|
+
return response;
|
|
81
44
|
}
|
|
82
45
|
case '用户主页数据': {
|
|
83
46
|
validateData(data, ['sec_uid']);
|
|
@@ -248,6 +211,53 @@ export const DouyinData = async (data, cookie) => {
|
|
|
248
211
|
break;
|
|
249
212
|
}
|
|
250
213
|
};
|
|
214
|
+
/**
|
|
215
|
+
* 通用的分页请求函数
|
|
216
|
+
* @param apiUrlGenerator - 接口URL生成器
|
|
217
|
+
* @param params - 请求参数
|
|
218
|
+
* @param maxPageSize - 单次请求的最大数据量
|
|
219
|
+
* @param headers - 请求头
|
|
220
|
+
* @returns
|
|
221
|
+
*/
|
|
222
|
+
async function fetchPaginatedData(apiUrlGenerator, params, maxPageSize, headers) {
|
|
223
|
+
let cursor = params.cursor ?? 0; // 初始游标值
|
|
224
|
+
let fetchedData = []; // 用于存储实际获取的所有数据
|
|
225
|
+
let tmpresp = {};
|
|
226
|
+
// 循环直到获取到足够数量的数据
|
|
227
|
+
while (fetchedData.length < Number(params.number ?? maxPageSize)) {
|
|
228
|
+
// 计算本次请求需要获取的数据数量,确保不超过剩余需要获取的数量
|
|
229
|
+
const requestCount = Math.min(Number(params.number ?? maxPageSize) - fetchedData.length, maxPageSize);
|
|
230
|
+
// 构建请求URL
|
|
231
|
+
const url = apiUrlGenerator({
|
|
232
|
+
...params,
|
|
233
|
+
number: requestCount,
|
|
234
|
+
cursor
|
|
235
|
+
});
|
|
236
|
+
// 发起请求获取数据
|
|
237
|
+
const response = await GlobalGetData({
|
|
238
|
+
url: `${url}&a_bogus=${douyinSign.AB(url)}`,
|
|
239
|
+
headers,
|
|
240
|
+
...params
|
|
241
|
+
});
|
|
242
|
+
// 将获取到的数据添加到数组中
|
|
243
|
+
fetchedData.push(...response.comments || response.data || []);
|
|
244
|
+
// 更新tmpresp为最后一次请求的响应
|
|
245
|
+
tmpresp = response;
|
|
246
|
+
// 如果本次请求的数据数量小于请求的数量,说明已经没有更多数据了
|
|
247
|
+
if ((response.comments || response.data || []).length < requestCount) {
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
// 更新游标值,准备下一次请求
|
|
251
|
+
cursor = response.cursor;
|
|
252
|
+
}
|
|
253
|
+
// 使用最后一次请求的接口响应格式,替换其中的数据
|
|
254
|
+
const finalResponse = {
|
|
255
|
+
...tmpresp,
|
|
256
|
+
comments: params.number === 0 ? [] : fetchedData.slice(0, Number(params.number ?? maxPageSize)),
|
|
257
|
+
cursor: params.number === 0 ? 0 : fetchedData.length
|
|
258
|
+
};
|
|
259
|
+
return finalResponse;
|
|
260
|
+
}
|
|
251
261
|
async function GlobalGetData(options) {
|
|
252
262
|
const ResponseData = await new Networks(options).getData();
|
|
253
263
|
if (ResponseData === '' || !ResponseData) {
|
|
@@ -21,7 +21,7 @@ export const registerDouyinRoutes = (fastify, cookie) => {
|
|
|
21
21
|
});
|
|
22
22
|
fastify.get('/fetch_video_comment_replies', async (request, reply) => {
|
|
23
23
|
reply.type('application/json').send(await DouyinData({
|
|
24
|
-
methodType: '
|
|
24
|
+
methodType: '指定评论回复数据',
|
|
25
25
|
aweme_id: request.query.aweme_id,
|
|
26
26
|
comment_id: request.query.comment_id
|
|
27
27
|
}, request.headers.cookie ?? cookie));
|
package/lib/server/client.d.ts
CHANGED
package/lib/server/client.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
export interface DouyinMethodOptionsMap {
|
|
2
2
|
CommentReplyParams: {
|
|
3
|
-
methodType: '
|
|
3
|
+
methodType: '指定评论回复数据';
|
|
4
4
|
/** 视频ID */
|
|
5
5
|
aweme_id: string;
|
|
6
6
|
/** 评论ID */
|
|
7
7
|
comment_id: string;
|
|
8
|
+
/**
|
|
9
|
+
* 获取的评论数量
|
|
10
|
+
* 默认情况下,如果指定的数量不足,则获取实际的评论数量。
|
|
11
|
+
* @defaultValue 5
|
|
12
|
+
*/
|
|
13
|
+
number?: number;
|
|
14
|
+
/**
|
|
15
|
+
* 游标,作用类似于翻页,根据上一次评论数量递增
|
|
16
|
+
* @defaultValue 0
|
|
17
|
+
*/
|
|
18
|
+
cursor?: number;
|
|
8
19
|
};
|
|
9
20
|
UserParams: {
|
|
10
21
|
methodType: '用户主页数据' | '用户主页视频列表数据' | '直播间信息数据';
|
|
@@ -70,7 +81,7 @@ export interface DouyinMethodOptionsMap {
|
|
|
70
81
|
}
|
|
71
82
|
/** 抖音API接口参数类型 */
|
|
72
83
|
export interface DouyinDataOptionsMap {
|
|
73
|
-
|
|
84
|
+
指定评论回复数据: DouyinMethodOptionsMap['CommentReplyParams'];
|
|
74
85
|
用户主页数据: DouyinMethodOptionsMap['UserParams'];
|
|
75
86
|
单个视频作品数据: DouyinMethodOptionsMap['WorkParams'];
|
|
76
87
|
评论数据: DouyinMethodOptionsMap['CommentParams'];
|