@ikenxuan/amagi 1.5.8 → 2.0.0
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/README.md +25 -11
- package/lib/business/bilibili/API.d.ts +1 -0
- package/lib/business/bilibili/API.js +1 -0
- package/lib/business/bilibili/getdata.js +13 -13
- package/lib/business/bilibili/getid.js +3 -3
- package/lib/business/bilibili/result.d.ts +2 -1
- package/lib/business/bilibili/result.js +17 -13
- package/lib/business/douyin/API.d.ts +1 -0
- package/lib/business/douyin/API.js +1 -0
- package/lib/business/douyin/getdata.js +18 -11
- package/lib/business/douyin/getid.js +3 -3
- package/lib/business/douyin/result.d.ts +2 -1
- package/lib/business/douyin/result.js +18 -13
- package/lib/model/index.d.ts +1 -2
- package/lib/model/index.js +1 -2
- package/lib/model/networks.js +10 -11
- package/lib/server/client.d.ts +26 -3
- package/lib/server/client.js +58 -26
- package/lib/server/listen.d.ts +4 -15
- package/lib/server/listen.js +7 -8
- package/lib/types/DataType.d.ts +23 -24
- package/package.json +3 -4
- package/lib/model/logger.d.ts +0 -3
- package/lib/model/logger.js +0 -28
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
1
|
# amagi(泥干嘛哈哈
|
|
2
|
+
|
|
4
3
|
* 热门平台视频解析 API 基于 Node.js 的实现,支持最低node版本为 v16
|
|
5
4
|
* 抖音、B站
|
|
6
5
|
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
7
10
|
## 使用
|
|
8
11
|
```
|
|
9
12
|
pnpm add @ikenxuan/amagi
|
|
@@ -12,22 +15,33 @@ pnpm add @ikenxuan/amagi
|
|
|
12
15
|
```js
|
|
13
16
|
import amagi, { StartClient } from '@ikenxuan/amagi'
|
|
14
17
|
|
|
15
|
-
// 初始化
|
|
16
|
-
const
|
|
18
|
+
// 初始化 amagi 实例,传入 ck
|
|
19
|
+
const Client = await new amagi({
|
|
17
20
|
douyin: '抖音ck',
|
|
18
21
|
bilibili: 'B站ck'
|
|
19
22
|
}).initServer(true) // 是否开启调试模式
|
|
20
23
|
|
|
21
|
-
//
|
|
22
|
-
await StartClient(
|
|
24
|
+
// 调用 StartClient 方法,可在本地部署一个 api 接口的 http 服务
|
|
25
|
+
await StartClient(Client.Instance, 4567)
|
|
23
26
|
```
|
|
24
|
-
## 开发构建
|
|
25
|
-
> Node.js版本 <= v18.20.4
|
|
26
27
|
|
|
27
|
-
*
|
|
28
|
-
```
|
|
29
|
-
|
|
28
|
+
* 如果你想直接获取数据
|
|
29
|
+
```js
|
|
30
|
+
import amagi from '@ikenxuan/amagi'
|
|
31
|
+
|
|
32
|
+
// 同样先初始化 amagi 实例
|
|
33
|
+
const Client = await new amagi({
|
|
34
|
+
douyin: '抖音ck',
|
|
35
|
+
bilibili: 'B站ck'
|
|
36
|
+
}).initServer()
|
|
37
|
+
|
|
38
|
+
const Data = await (Client.GetBilibiliData({ type: '单个视频作品数据' }))
|
|
39
|
+
.result({ url: 'https://b23.tv/9JvEHhJ' })
|
|
30
40
|
```
|
|
41
|
+
|
|
42
|
+
## 开发构建
|
|
43
|
+
> **开发环境下,支持最低node版本为 v18**
|
|
44
|
+
|
|
31
45
|
* 安装依赖
|
|
32
46
|
```
|
|
33
47
|
pnpm install
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BiLiBiLiAPI, qtparam, wbi_sign } from '../../business/bilibili/index.js';
|
|
2
|
-
import { Networks
|
|
2
|
+
import { Networks } from '../../model/index.js';
|
|
3
3
|
export default class BilibiliData {
|
|
4
4
|
type;
|
|
5
5
|
headers;
|
|
@@ -14,7 +14,7 @@ export default class BilibiliData {
|
|
|
14
14
|
async GetData(data = {}) {
|
|
15
15
|
let result;
|
|
16
16
|
switch (this.type) {
|
|
17
|
-
case
|
|
17
|
+
case "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* BilibiliDataType.单个视频作品数据 */: {
|
|
18
18
|
const INFODATA = await this.GlobalGetData({ url: BiLiBiLiAPI.视频详细信息({ id_type: 'bvid', id: data.id }) });
|
|
19
19
|
const BASEURL = BiLiBiLiAPI.视频流信息({ avid: INFODATA.data.aid, cid: INFODATA.data.cid });
|
|
20
20
|
const SIGN = await qtparam(BASEURL, this.headers.Cookie);
|
|
@@ -24,15 +24,15 @@ export default class BilibiliData {
|
|
|
24
24
|
});
|
|
25
25
|
return { INFODATA, DATA };
|
|
26
26
|
}
|
|
27
|
-
case
|
|
27
|
+
case "\u8BC4\u8BBA\u6570\u636E" /* BilibiliDataType.评论数据 */: {
|
|
28
28
|
const INFODATA = await this.GlobalGetData({ url: BiLiBiLiAPI.视频详细信息({ id_type: 'bvid', id: data.bvid }) });
|
|
29
29
|
const PARAM = await wbi_sign(BiLiBiLiAPI.评论区明细({ type: 1, oid: INFODATA.data.aid }), this.headers.Cookie);
|
|
30
30
|
const COMMENTSDATA = await this.GlobalGetData({ url: BiLiBiLiAPI.评论区明细({ type: 1, oid: INFODATA.data.aid }) + PARAM, headers: this.headers });
|
|
31
31
|
return COMMENTSDATA;
|
|
32
32
|
}
|
|
33
|
-
case
|
|
33
|
+
case "emoji\u6570\u636E" /* BilibiliDataType.emoji数据 */:
|
|
34
34
|
return await this.GlobalGetData({ url: BiLiBiLiAPI.表情列表() });
|
|
35
|
-
case
|
|
35
|
+
case "\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E" /* BilibiliDataType.番剧基本信息数据 */: {
|
|
36
36
|
let isep;
|
|
37
37
|
if (data?.id?.startsWith('ss')) {
|
|
38
38
|
data.id = data.id.replace('ss', '');
|
|
@@ -48,16 +48,16 @@ export default class BilibiliData {
|
|
|
48
48
|
});
|
|
49
49
|
return INFO;
|
|
50
50
|
}
|
|
51
|
-
case
|
|
51
|
+
case "\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E" /* BilibiliDataType.番剧下载信息数据 */:
|
|
52
52
|
return await this.GlobalGetData({ url: BiLiBiLiAPI.番剧视频流信息({ cid: data.cid, ep_id: data.ep_id }) });
|
|
53
|
-
case
|
|
53
|
+
case "\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E" /* BilibiliDataType.用户主页动态列表数据 */:
|
|
54
54
|
delete this.headers.Referer;
|
|
55
55
|
result = await this.GlobalGetData({
|
|
56
56
|
url: BiLiBiLiAPI.用户空间动态({ host_mid: data.host_mid }),
|
|
57
57
|
headers: this.headers
|
|
58
58
|
});
|
|
59
59
|
return result;
|
|
60
|
-
case
|
|
60
|
+
case "\u52A8\u6001\u8BE6\u60C5\u6570\u636E" /* BilibiliDataType.动态详情数据 */: {
|
|
61
61
|
delete this.headers.Referer;
|
|
62
62
|
const dynamicINFO = await this.GlobalGetData({
|
|
63
63
|
url: BiLiBiLiAPI.动态详情({ dynamic_id: data.dynamic_id }),
|
|
@@ -65,7 +65,7 @@ export default class BilibiliData {
|
|
|
65
65
|
});
|
|
66
66
|
return dynamicINFO;
|
|
67
67
|
}
|
|
68
|
-
case
|
|
68
|
+
case "\u52A8\u6001\u5361\u7247\u6570\u636E" /* BilibiliDataType.动态卡片数据 */: {
|
|
69
69
|
delete this.headers.Referer;
|
|
70
70
|
const dynamicINFO_CARD = await this.GlobalGetData({
|
|
71
71
|
url: BiLiBiLiAPI.动态卡片信息({ dynamic_id: data.dynamic_id }),
|
|
@@ -73,21 +73,21 @@ export default class BilibiliData {
|
|
|
73
73
|
});
|
|
74
74
|
return dynamicINFO_CARD;
|
|
75
75
|
}
|
|
76
|
-
case
|
|
76
|
+
case "\u7528\u6237\u4E3B\u9875\u6570\u636E" /* BilibiliDataType.用户主页数据 */: {
|
|
77
77
|
result = await this.GlobalGetData({
|
|
78
78
|
url: BiLiBiLiAPI.用户名片信息({ host_mid: data.host_mid }),
|
|
79
79
|
headers: this.headers
|
|
80
80
|
});
|
|
81
81
|
return result;
|
|
82
82
|
}
|
|
83
|
-
case
|
|
83
|
+
case "\u76F4\u64AD\u95F4\u4FE1\u606F" /* BilibiliDataType.直播间信息 */: {
|
|
84
84
|
result = await this.GlobalGetData({
|
|
85
85
|
url: BiLiBiLiAPI.直播间信息({ room_id: data.room_id }),
|
|
86
86
|
headers: this.headers
|
|
87
87
|
});
|
|
88
88
|
return result;
|
|
89
89
|
}
|
|
90
|
-
case
|
|
90
|
+
case "\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F" /* BilibiliDataType.直播间初始化信息 */: {
|
|
91
91
|
result = await this.GlobalGetData({
|
|
92
92
|
url: BiLiBiLiAPI.直播间初始化信息({ room_id: data.room_id }),
|
|
93
93
|
headers: this.headers
|
|
@@ -102,7 +102,7 @@ export default class BilibiliData {
|
|
|
102
102
|
const result = await new Networks(options).getData();
|
|
103
103
|
if (result && result.code !== 0) {
|
|
104
104
|
const errorMessage = errorMap[result.code] || '未知错误';
|
|
105
|
-
|
|
105
|
+
console.error(`响应数据失败!\n请求接口类型:${this.type}\n请求URL:${options.url}\n错误代码:${result.code},\n含义:${errorMessage}`);
|
|
106
106
|
return null;
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
@@ -11,7 +11,7 @@ export default async function GetBilibiliID(url) {
|
|
|
11
11
|
case /video\/([A-Za-z0-9]+)/.test(longLink): {
|
|
12
12
|
const bvideoMatch = longLink.match(/video\/([A-Za-z0-9]+)/);
|
|
13
13
|
result = {
|
|
14
|
-
type: "
|
|
14
|
+
type: "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* BilibiliDataType['单个视频作品数据'] */,
|
|
15
15
|
id: bvideoMatch ? bvideoMatch[1] : ''
|
|
16
16
|
};
|
|
17
17
|
break;
|
|
@@ -19,7 +19,7 @@ export default async function GetBilibiliID(url) {
|
|
|
19
19
|
case /play\/(\S+?)\??/.test(longLink): {
|
|
20
20
|
const playMatch = longLink.match(/play\/(\w+)/);
|
|
21
21
|
result = {
|
|
22
|
-
type: "
|
|
22
|
+
type: "\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E" /* BilibiliDataType['番剧基本信息数据'] */,
|
|
23
23
|
id: playMatch ? playMatch[1] : ''
|
|
24
24
|
};
|
|
25
25
|
break;
|
|
@@ -29,7 +29,7 @@ export default async function GetBilibiliID(url) {
|
|
|
29
29
|
const opusMatch = longLink.match(/^https:\/\/www\.bilibili\.com\/opus\/(\d+)/);
|
|
30
30
|
const dynamic_id = tMatch || opusMatch;
|
|
31
31
|
result = {
|
|
32
|
-
type: "
|
|
32
|
+
type: "\u52A8\u6001\u8BE6\u60C5\u6570\u636E" /* BilibiliDataType['动态详情数据'] */,
|
|
33
33
|
dynamic_id: dynamic_id ? dynamic_id[1] : ''
|
|
34
34
|
};
|
|
35
35
|
break;
|
|
@@ -2,6 +2,7 @@ import { BilibiliDataType, BilibiliOptionsType, GetDataResponseType } from '../.
|
|
|
2
2
|
export default class BilibiliResult {
|
|
3
3
|
type: BilibiliDataType;
|
|
4
4
|
cookie: string;
|
|
5
|
-
|
|
5
|
+
returndata: boolean;
|
|
6
|
+
constructor(type: BilibiliDataType, cookie: string, returndata?: boolean);
|
|
6
7
|
result(options?: BilibiliOptionsType): Promise<GetDataResponseType>;
|
|
7
8
|
}
|
|
@@ -2,27 +2,29 @@ import { BilibiliData, GetBilibiliID } from '../../business/bilibili/index.js';
|
|
|
2
2
|
export default class BilibiliResult {
|
|
3
3
|
type;
|
|
4
4
|
cookie;
|
|
5
|
-
|
|
5
|
+
returndata;
|
|
6
|
+
constructor(type, cookie, returndata = false) {
|
|
6
7
|
this.type = type;
|
|
7
8
|
this.cookie = cookie;
|
|
9
|
+
/** 直接返回数据,不做响应封装 */
|
|
10
|
+
this.returndata = returndata;
|
|
8
11
|
}
|
|
9
12
|
async result(options = {}) {
|
|
10
13
|
let result;
|
|
11
14
|
switch (this.type) {
|
|
12
|
-
case
|
|
13
|
-
case
|
|
14
|
-
case
|
|
15
|
-
case
|
|
16
|
-
case
|
|
17
|
-
case
|
|
18
|
-
case
|
|
19
|
-
case
|
|
20
|
-
case
|
|
21
|
-
case 'LiveRoomInitData':
|
|
15
|
+
case "\u7528\u6237\u4E3B\u9875\u6570\u636E" /* BilibiliDataType.用户主页数据 */:
|
|
16
|
+
case "emoji\u6570\u636E" /* BilibiliDataType.emoji数据 */:
|
|
17
|
+
case "\u8BC4\u8BBA\u6570\u636E" /* BilibiliDataType.评论数据 */:
|
|
18
|
+
case "\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E" /* BilibiliDataType.番剧下载信息数据 */:
|
|
19
|
+
case "\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E" /* BilibiliDataType.用户主页动态列表数据 */:
|
|
20
|
+
case "\u52A8\u6001\u8BE6\u60C5\u6570\u636E" /* BilibiliDataType.动态详情数据 */:
|
|
21
|
+
case "\u52A8\u6001\u5361\u7247\u6570\u636E" /* BilibiliDataType.动态卡片数据 */:
|
|
22
|
+
case "\u76F4\u64AD\u95F4\u4FE1\u606F" /* BilibiliDataType.直播间信息 */:
|
|
23
|
+
case "\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F" /* BilibiliDataType.直播间初始化信息 */:
|
|
22
24
|
result = await new BilibiliData(this.type, this.cookie).GetData(options);
|
|
23
25
|
break;
|
|
24
|
-
case
|
|
25
|
-
case
|
|
26
|
+
case "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* BilibiliDataType.单个视频作品数据 */:
|
|
27
|
+
case "\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E" /* BilibiliDataType.番剧基本信息数据 */: {
|
|
26
28
|
const iddata = await GetBilibiliID(options.url);
|
|
27
29
|
result = await new BilibiliData(this.type, this.cookie).GetData(iddata);
|
|
28
30
|
break;
|
|
@@ -31,6 +33,8 @@ export default class BilibiliResult {
|
|
|
31
33
|
result = '';
|
|
32
34
|
break;
|
|
33
35
|
}
|
|
36
|
+
if (this.returndata)
|
|
37
|
+
return result;
|
|
34
38
|
return {
|
|
35
39
|
code: result !== false && result !== '' ? 200 : 503,
|
|
36
40
|
message: result !== !false && result !== '' ? 'success' : 'error',
|
|
@@ -38,4 +38,5 @@ class DouyinAPI {
|
|
|
38
38
|
return `https://live.douyin.com/webcast/room/info_by_scene/?aid=6383&app_name=douyin_web&live_id=1&device_platform=web&language=zh-CN&cookie_enabled=true&screen_width=2328&screen_height=1310&browser_language=zh-CN&browser_platform=Win32&browser_name=Edge&browser_version=125.0.0.0&room_id=${data.room_id}&scene=aweme_video_feed_pc&channel=channel_pc_web®ion=cn&device_id=7355205920467306010&device_type=web_device&os_version=web&version_code=170400&webcast_sdk_version=2450&msToken=${Sign.Mstoken(116)}&verifyFp=${fp}&fp=${fp}`;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
/** 该类下的所有方法只会返回拼接好参数后的 Url 地址,需要手动请求该地址以获取数据 */
|
|
41
42
|
export default new DouyinAPI();
|
|
@@ -17,8 +17,8 @@ export default class DouyinData {
|
|
|
17
17
|
}
|
|
18
18
|
async GetData(data = {}) {
|
|
19
19
|
switch (this.type) {
|
|
20
|
-
case
|
|
21
|
-
case
|
|
20
|
+
case "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* DouyinDataType.单个视频作品数据 */:
|
|
21
|
+
case "\u56FE\u96C6\u4F5C\u54C1\u6570\u636E" /* DouyinDataType.图集作品数据 */:
|
|
22
22
|
this.URL = DouyinAPI.视频或图集({ aweme_id: data.aweme_id });
|
|
23
23
|
const VideoData = await this.GlobalGetData({
|
|
24
24
|
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
@@ -26,21 +26,21 @@ export default class DouyinData {
|
|
|
26
26
|
headers: this.headers
|
|
27
27
|
});
|
|
28
28
|
return VideoData;
|
|
29
|
-
case
|
|
29
|
+
case "\u8BC4\u8BBA\u6570\u636E" /* DouyinDataType.评论数据 */:
|
|
30
30
|
this.URL = DouyinAPI.评论({ aweme_id: data.aweme_id });
|
|
31
31
|
const CommentsData = await this.GlobalGetData({
|
|
32
32
|
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
33
33
|
headers: this.headers
|
|
34
34
|
});
|
|
35
35
|
return CommentsData;
|
|
36
|
-
case
|
|
36
|
+
case "\u4E8C\u7EA7\u8BC4\u8BBA\u6570\u636E" /* DouyinDataType.二级评论数据 */:
|
|
37
37
|
this.URL = DouyinAPI.二级评论({ aweme_id: data.aweme_id, comment_id: data.comment_id });
|
|
38
38
|
const CommentReplyData = await this.GlobalGetData({
|
|
39
39
|
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
40
40
|
headers: this.headers
|
|
41
41
|
});
|
|
42
42
|
return CommentReplyData;
|
|
43
|
-
case
|
|
43
|
+
case "\u7528\u6237\u4E3B\u9875\u6570\u636E" /* DouyinDataType.用户主页数据 */:
|
|
44
44
|
this.URL = DouyinAPI.用户主页信息({ sec_uid: data.sec_uid });
|
|
45
45
|
const UserInfoData = await this.GlobalGetData({
|
|
46
46
|
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
@@ -50,14 +50,14 @@ export default class DouyinData {
|
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
return UserInfoData;
|
|
53
|
-
case
|
|
53
|
+
case "\u5B98\u65B9emoji\u6570\u636E" /* DouyinDataType.官方emoji数据 */:
|
|
54
54
|
this.URL = DouyinAPI.表情();
|
|
55
55
|
const EmojiData = await this.GlobalGetData({
|
|
56
56
|
url: this.URL,
|
|
57
57
|
headers: this.headers
|
|
58
58
|
});
|
|
59
59
|
return EmojiData;
|
|
60
|
-
case
|
|
60
|
+
case "\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E" /* DouyinDataType.用户主页视频列表数据 */:
|
|
61
61
|
this.URL = DouyinAPI.用户主页视频({ sec_uid: data.sec_uid });
|
|
62
62
|
const UserVideoListData = await this.GlobalGetData({
|
|
63
63
|
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
@@ -67,7 +67,7 @@ export default class DouyinData {
|
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
return UserVideoListData;
|
|
70
|
-
case
|
|
70
|
+
case "\u70ED\u70B9\u8BCD\u6570\u636E" /* DouyinDataType.热点词数据 */:
|
|
71
71
|
this.URL = DouyinAPI.热点词({ query: data.query });
|
|
72
72
|
const SuggestWordsData = await this.GlobalGetData({
|
|
73
73
|
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
@@ -77,7 +77,7 @@ export default class DouyinData {
|
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
return SuggestWordsData;
|
|
80
|
-
case
|
|
80
|
+
case "\u641C\u7D22\u6570\u636E" /* DouyinDataType.搜索数据 */:
|
|
81
81
|
this.URL = DouyinAPI.搜索({ query: data.query });
|
|
82
82
|
const SearchData = await this.GlobalGetData({
|
|
83
83
|
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
@@ -87,20 +87,27 @@ export default class DouyinData {
|
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
89
|
return SearchData;
|
|
90
|
-
case
|
|
90
|
+
case "\u52A8\u6001\u8868\u60C5\u6570\u636E" /* DouyinDataType.动态表情数据 */:
|
|
91
91
|
this.URL = DouyinAPI.互动表情();
|
|
92
92
|
const ExpressionPlusData = await this.GlobalGetData({
|
|
93
93
|
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
94
94
|
headers: this.headers
|
|
95
95
|
});
|
|
96
96
|
return ExpressionPlusData;
|
|
97
|
-
case
|
|
97
|
+
case "\u97F3\u4E50\u6570\u636E" /* DouyinDataType.音乐数据 */:
|
|
98
98
|
this.URL = DouyinAPI.背景音乐({ music_id: data.music_id });
|
|
99
99
|
const MusicData = await this.GlobalGetData({
|
|
100
100
|
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
101
101
|
headers: this.headers
|
|
102
102
|
});
|
|
103
103
|
return MusicData;
|
|
104
|
+
case "\u5B9E\u51B5\u56FE\u7247\u56FE\u96C6\u6570\u636E" /* DouyinDataType.实况图片图集数据 */:
|
|
105
|
+
this.URL = DouyinAPI.动图({ aweme_id: data.aweme_id });
|
|
106
|
+
const LiveImages = await this.GlobalGetData({
|
|
107
|
+
url: `${this.URL}&a_bogus=${Sign.AB(this.URL)}`,
|
|
108
|
+
headers: this.headers
|
|
109
|
+
});
|
|
110
|
+
return LiveImages;
|
|
104
111
|
default:
|
|
105
112
|
break;
|
|
106
113
|
}
|
|
@@ -11,21 +11,21 @@ export default async function GetDouyinID(url) {
|
|
|
11
11
|
case /video\/(\d+)/.test(longLink):
|
|
12
12
|
const videoMatch = longLink.match(/video\/(\d+)/);
|
|
13
13
|
result = {
|
|
14
|
-
type: "
|
|
14
|
+
type: "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* DouyinDataType['单个视频作品数据'] */,
|
|
15
15
|
aweme_id: videoMatch ? videoMatch[1] : ''
|
|
16
16
|
};
|
|
17
17
|
break;
|
|
18
18
|
case /note\/(\d+)/.test(longLink):
|
|
19
19
|
const noteMatch = longLink.match(/note\/(\d+)/);
|
|
20
20
|
result = {
|
|
21
|
-
type: "
|
|
21
|
+
type: "\u56FE\u96C6\u4F5C\u54C1\u6570\u636E" /* DouyinDataType['图集作品数据'] */,
|
|
22
22
|
aweme_id: noteMatch ? noteMatch[1] : ''
|
|
23
23
|
};
|
|
24
24
|
break;
|
|
25
25
|
case /user\/(\S+?)\?/.test(longLink):
|
|
26
26
|
const userMatch = longLink.match(/user\/(\S+?)\?/);
|
|
27
27
|
result = {
|
|
28
|
-
type: "
|
|
28
|
+
type: "\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E" /* DouyinDataType['用户主页视频列表数据'] */,
|
|
29
29
|
sec_uid: userMatch ? userMatch[1] : ''
|
|
30
30
|
};
|
|
31
31
|
break;
|
|
@@ -2,6 +2,7 @@ import { DouyinDataType, DouyinOptionsType, GetDataResponseType } from '../../ty
|
|
|
2
2
|
export default class DouyinResult {
|
|
3
3
|
type: DouyinDataType;
|
|
4
4
|
cookie: string;
|
|
5
|
-
|
|
5
|
+
returndata: boolean;
|
|
6
|
+
constructor(type: DouyinDataType, cookie: string, returndata?: boolean);
|
|
6
7
|
result(options?: DouyinOptionsType): Promise<GetDataResponseType>;
|
|
7
8
|
}
|
|
@@ -2,27 +2,30 @@ import { DouyinData, GetDouyinID } from '../../business/douyin/index.js';
|
|
|
2
2
|
export default class DouyinResult {
|
|
3
3
|
type;
|
|
4
4
|
cookie;
|
|
5
|
-
|
|
5
|
+
returndata;
|
|
6
|
+
constructor(type, cookie, returndata = true) {
|
|
6
7
|
this.type = type;
|
|
7
8
|
this.cookie = cookie;
|
|
9
|
+
/** 直接返回数据,不做响应封装 */
|
|
10
|
+
this.returndata = returndata;
|
|
8
11
|
}
|
|
9
12
|
async result(options = {}) {
|
|
10
13
|
let result;
|
|
11
14
|
switch (this.type) {
|
|
12
|
-
case
|
|
13
|
-
case
|
|
14
|
-
case
|
|
15
|
-
case
|
|
16
|
-
case
|
|
17
|
-
case
|
|
18
|
-
case
|
|
19
|
-
case
|
|
20
|
-
case
|
|
15
|
+
case "\u4E8C\u7EA7\u8BC4\u8BBA\u6570\u636E" /* DouyinDataType.二级评论数据 */:
|
|
16
|
+
case "\u7528\u6237\u4E3B\u9875\u6570\u636E" /* DouyinDataType.用户主页数据 */:
|
|
17
|
+
case "\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E" /* DouyinDataType.用户主页视频列表数据 */:
|
|
18
|
+
case "\u70ED\u70B9\u8BCD\u6570\u636E" /* DouyinDataType.热点词数据 */:
|
|
19
|
+
case "\u641C\u7D22\u6570\u636E" /* DouyinDataType.搜索数据 */:
|
|
20
|
+
case "\u5B98\u65B9emoji\u6570\u636E" /* DouyinDataType.官方emoji数据 */:
|
|
21
|
+
case "\u52A8\u6001\u8868\u60C5\u6570\u636E" /* DouyinDataType.动态表情数据 */:
|
|
22
|
+
case "\u97F3\u4E50\u6570\u636E" /* DouyinDataType.音乐数据 */:
|
|
23
|
+
case "\u5B9E\u51B5\u56FE\u7247\u56FE\u96C6\u6570\u636E" /* DouyinDataType.实况图片图集数据 */:
|
|
21
24
|
result = await new DouyinData(this.type, this.cookie).GetData(options);
|
|
22
25
|
break;
|
|
23
|
-
case
|
|
24
|
-
case
|
|
25
|
-
case
|
|
26
|
+
case "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* DouyinDataType.单个视频作品数据 */:
|
|
27
|
+
case "\u56FE\u96C6\u4F5C\u54C1\u6570\u636E" /* DouyinDataType.图集作品数据 */:
|
|
28
|
+
case "\u8BC4\u8BBA\u6570\u636E" /* DouyinDataType.评论数据 */: {
|
|
26
29
|
const defurl = options?.url?.toString().match(/(http|https):\/\/.*\.(douyin|iesdouyin)\.com\/[^ ]+/g);
|
|
27
30
|
const iddata = await GetDouyinID(String(defurl));
|
|
28
31
|
result = await new DouyinData(this.type, this.cookie).GetData(iddata);
|
|
@@ -32,6 +35,8 @@ export default class DouyinResult {
|
|
|
32
35
|
result = '';
|
|
33
36
|
break;
|
|
34
37
|
}
|
|
38
|
+
if (this.returndata)
|
|
39
|
+
return result;
|
|
35
40
|
return {
|
|
36
41
|
code: result !== false && result !== '' ? 200 : 503,
|
|
37
42
|
message: result !== false && result !== '' ? 'success' : 'error',
|
package/lib/model/index.d.ts
CHANGED
package/lib/model/index.js
CHANGED
package/lib/model/networks.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { logger } from '../model/index.js';
|
|
2
1
|
import axios from 'axios';
|
|
3
2
|
export default class Networks {
|
|
4
3
|
url;
|
|
@@ -48,7 +47,7 @@ export default class Networks {
|
|
|
48
47
|
return result;
|
|
49
48
|
}
|
|
50
49
|
catch (error) {
|
|
51
|
-
|
|
50
|
+
console.info(error);
|
|
52
51
|
return false;
|
|
53
52
|
}
|
|
54
53
|
}
|
|
@@ -62,7 +61,7 @@ export default class Networks {
|
|
|
62
61
|
return result.request.res.responseUrl; // axios中获取最终的请求URL
|
|
63
62
|
}
|
|
64
63
|
catch (error) {
|
|
65
|
-
|
|
64
|
+
console.error(error);
|
|
66
65
|
return '';
|
|
67
66
|
}
|
|
68
67
|
}
|
|
@@ -78,7 +77,7 @@ export default class Networks {
|
|
|
78
77
|
return response.headers['location'];
|
|
79
78
|
}
|
|
80
79
|
catch (error) {
|
|
81
|
-
|
|
80
|
+
console.error(error);
|
|
82
81
|
return '';
|
|
83
82
|
}
|
|
84
83
|
}
|
|
@@ -91,7 +90,7 @@ export default class Networks {
|
|
|
91
90
|
return result;
|
|
92
91
|
}
|
|
93
92
|
if (result.status === 429) {
|
|
94
|
-
|
|
93
|
+
console.warn('HTTP 响应状态码: 429');
|
|
95
94
|
throw new Error('ratelimit triggered, 触发 https://www.douyin.com/ 的速率限制!!!');
|
|
96
95
|
}
|
|
97
96
|
this.axiosInstance = result;
|
|
@@ -118,7 +117,7 @@ export default class Networks {
|
|
|
118
117
|
return this.axiosInstance;
|
|
119
118
|
}
|
|
120
119
|
catch (error) {
|
|
121
|
-
|
|
120
|
+
console.error(error);
|
|
122
121
|
return false;
|
|
123
122
|
}
|
|
124
123
|
}
|
|
@@ -131,17 +130,17 @@ export default class Networks {
|
|
|
131
130
|
return this.axiosInstance.headers;
|
|
132
131
|
}
|
|
133
132
|
else {
|
|
134
|
-
|
|
133
|
+
console.error('未获取到响应头');
|
|
135
134
|
return null;
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
else {
|
|
139
|
-
|
|
138
|
+
console.error('未获取到响应对象');
|
|
140
139
|
return null;
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
142
|
catch (error) {
|
|
144
|
-
|
|
143
|
+
console.error('获取响应头失败:', error);
|
|
145
144
|
return null;
|
|
146
145
|
}
|
|
147
146
|
}
|
|
@@ -170,12 +169,12 @@ export default class Networks {
|
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
171
|
else {
|
|
173
|
-
|
|
172
|
+
console.error('未获取到响应对象');
|
|
174
173
|
}
|
|
175
174
|
return { headers, data };
|
|
176
175
|
}
|
|
177
176
|
catch (error) {
|
|
178
|
-
|
|
177
|
+
console.error('获取响应头和数据失败:', error);
|
|
179
178
|
return { headers: null, data: null };
|
|
180
179
|
}
|
|
181
180
|
}
|
package/lib/server/client.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { BilibiliResult } from '../business/bilibili/index.js';
|
|
2
|
+
import { DouyinResult } from '../business/douyin/index.js';
|
|
3
|
+
import { BilibiliDataType, DouyinDataType } from '../types/index.js';
|
|
1
4
|
import { FastifyInstance } from 'fastify';
|
|
2
5
|
interface initClientParams {
|
|
3
6
|
/** 抖音ck */
|
|
@@ -5,9 +8,23 @@ interface initClientParams {
|
|
|
5
8
|
/** B站ck */
|
|
6
9
|
bilibili: string;
|
|
7
10
|
}
|
|
11
|
+
interface amagiInstance {
|
|
12
|
+
/** Fastify 实例 */
|
|
13
|
+
Instance: FastifyInstance;
|
|
14
|
+
/** 获取抖音接口数据 */
|
|
15
|
+
GetDouyinData: (data: {
|
|
16
|
+
type: keyof typeof DouyinDataType;
|
|
17
|
+
}) => DouyinResult;
|
|
18
|
+
/** 获取B站接口数据 */
|
|
19
|
+
GetBilibiliData: (data: {
|
|
20
|
+
type: keyof typeof BilibiliDataType;
|
|
21
|
+
}) => BilibiliResult;
|
|
22
|
+
}
|
|
8
23
|
export declare class client {
|
|
9
|
-
|
|
10
|
-
|
|
24
|
+
/** douyin cookies */
|
|
25
|
+
douyin: string;
|
|
26
|
+
/** bilibili cookes */
|
|
27
|
+
bilibili: string;
|
|
11
28
|
/**
|
|
12
29
|
*
|
|
13
30
|
* @param cookies 包含抖音和B站cookie的参数对象
|
|
@@ -18,6 +35,12 @@ export declare class client {
|
|
|
18
35
|
* @param log 是否启用日志
|
|
19
36
|
* @returns fastify 实例
|
|
20
37
|
*/
|
|
21
|
-
initServer(log?: boolean): Promise<
|
|
38
|
+
initServer(log?: boolean): Promise<amagiInstance>;
|
|
39
|
+
GetDouyinData: (data: {
|
|
40
|
+
type: keyof typeof DouyinDataType;
|
|
41
|
+
}) => DouyinResult;
|
|
42
|
+
GetBilibiliData: (data: {
|
|
43
|
+
type: keyof typeof BilibiliDataType;
|
|
44
|
+
}) => BilibiliResult;
|
|
22
45
|
}
|
|
23
46
|
export {};
|
package/lib/server/client.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { BilibiliResult } from '../business/bilibili/index.js';
|
|
2
2
|
import { DouyinResult } from '../business/douyin/index.js';
|
|
3
|
-
import
|
|
3
|
+
import Fastify from 'fastify';
|
|
4
4
|
export class client {
|
|
5
|
+
/** douyin cookies */
|
|
5
6
|
douyin;
|
|
7
|
+
/** bilibili cookes */
|
|
6
8
|
bilibili;
|
|
7
9
|
/**
|
|
8
10
|
*
|
|
@@ -20,90 +22,120 @@ export class client {
|
|
|
20
22
|
* @returns fastify 实例
|
|
21
23
|
*/
|
|
22
24
|
async initServer (log = false) {
|
|
23
|
-
const client =
|
|
25
|
+
const client = Fastify({
|
|
26
|
+
logger: log && {
|
|
27
|
+
transport: {
|
|
28
|
+
target: 'pino-pretty',
|
|
29
|
+
options: {
|
|
30
|
+
colorize: true,
|
|
31
|
+
translateTime: 'yyyy-MM-dd HH:mm:ss',
|
|
32
|
+
ignore: 'pid,hostname,reqId,res,responseTime,req.hostname,req.method,req.remotePort',
|
|
33
|
+
messageFormat: '{msg}'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
client.get('/', async (_request, reply) => {
|
|
39
|
+
reply.redirect('https://amagi.apifox.cn', 301);
|
|
40
|
+
});
|
|
41
|
+
client.get('/docs', async (_request, reply) => {
|
|
42
|
+
reply.redirect('https://amagi.apifox.cn', 301);
|
|
43
|
+
});
|
|
24
44
|
client.get('/api/douyin/aweme', async (request, reply) => {
|
|
25
45
|
const url = request.query.url;
|
|
26
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
46
|
+
reply.type('application/json').send(await new DouyinResult("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* DouyinDataType.单个视频作品数据 */, this.douyin).result({ url }));
|
|
27
47
|
});
|
|
28
48
|
client.get('/api/douyin/comments', async (request, reply) => {
|
|
29
49
|
const url = request.query.url;
|
|
30
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
50
|
+
reply.type('application/json').send(await new DouyinResult("\u8BC4\u8BBA\u6570\u636E" /* DouyinDataType.评论数据 */, this.douyin).result({ url }));
|
|
31
51
|
});
|
|
32
52
|
client.get('/api/douyin/comments/reply', async (request, reply) => {
|
|
33
53
|
const { aweme_id, comment_id } = request.query;
|
|
34
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
54
|
+
reply.type('application/json').send(await new DouyinResult("\u4E8C\u7EA7\u8BC4\u8BBA\u6570\u636E" /* DouyinDataType.二级评论数据 */, this.douyin).result({ aweme_id, comment_id }));
|
|
35
55
|
});
|
|
36
56
|
client.get('/api/douyin/userinfo', async (request, reply) => {
|
|
37
57
|
const sec_uid = request.query.sec_uid;
|
|
38
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
58
|
+
reply.type('application/json').send(await new DouyinResult("\u7528\u6237\u4E3B\u9875\u6570\u636E" /* DouyinDataType.用户主页数据 */, this.douyin).result({ sec_uid }));
|
|
39
59
|
});
|
|
40
60
|
client.get('/api/douyin/uservideoslist', async (request, reply) => {
|
|
41
61
|
const sec_uid = request.query.sec_uid;
|
|
42
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
62
|
+
reply.type('application/json').send(await new DouyinResult("\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E" /* DouyinDataType.用户主页视频列表数据 */, this.douyin).result({ sec_uid }));
|
|
43
63
|
});
|
|
44
64
|
client.get('/api/douyin/suggestwords', async (request, reply) => {
|
|
45
65
|
const query = request.query.query;
|
|
46
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
66
|
+
reply.type('application/json').send(await new DouyinResult("\u70ED\u70B9\u8BCD\u6570\u636E" /* DouyinDataType.热点词数据 */, this.douyin).result({ query }));
|
|
47
67
|
});
|
|
48
68
|
client.get('/api/douyin/search', async (request, reply) => {
|
|
49
69
|
const query = request.query.query;
|
|
50
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
70
|
+
reply.type('application/json').send(await new DouyinResult("\u641C\u7D22\u6570\u636E" /* DouyinDataType.搜索数据 */, this.douyin).result({ query }));
|
|
51
71
|
});
|
|
52
72
|
client.get('/api/douyin/emoji', async (_request, reply) => {
|
|
53
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
73
|
+
reply.type('application/json').send(await new DouyinResult("\u5B98\u65B9emoji\u6570\u636E" /* DouyinDataType.官方emoji数据 */, this.douyin).result());
|
|
54
74
|
});
|
|
55
75
|
client.get('/api/douyin/expressionplus', async (_request, reply) => {
|
|
56
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
76
|
+
reply.type('application/json').send(await new DouyinResult("\u52A8\u6001\u8868\u60C5\u6570\u636E" /* DouyinDataType.动态表情数据 */, this.douyin).result());
|
|
57
77
|
});
|
|
58
78
|
client.get('/api/douyin/music', async (request, reply) => {
|
|
59
79
|
const music_id = request.query.music_id;
|
|
60
|
-
reply.type('application/json').send(await new DouyinResult("
|
|
80
|
+
reply.type('application/json').send(await new DouyinResult("\u97F3\u4E50\u6570\u636E" /* DouyinDataType.音乐数据 */, this.douyin).result({ music_id }));
|
|
81
|
+
});
|
|
82
|
+
client.get('/api/douyin/liveimages', async (request, reply) => {
|
|
83
|
+
const music_id = request.query.music_id;
|
|
84
|
+
reply.type('application/json').send(await new DouyinResult("\u5B9E\u51B5\u56FE\u7247\u56FE\u96C6\u6570\u636E" /* DouyinDataType.实况图片图集数据 */, this.douyin).result({ music_id }));
|
|
61
85
|
});
|
|
62
|
-
// bilibili
|
|
63
86
|
client.get('/api/bilibili/work', async (request, reply) => {
|
|
64
87
|
const url = request.query.url;
|
|
65
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
88
|
+
reply.type('application/json').send(await new BilibiliResult("\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E" /* BilibiliDataType.单个视频作品数据 */, this.bilibili).result({ url }));
|
|
66
89
|
});
|
|
67
90
|
client.get('/api/bilibili/comment', async (request, reply) => {
|
|
68
91
|
const bvid = request.query.bvid;
|
|
69
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
92
|
+
reply.type('application/json').send(await new BilibiliResult("\u8BC4\u8BBA\u6570\u636E" /* BilibiliDataType.评论数据 */, this.bilibili).result({ bvid }));
|
|
70
93
|
});
|
|
71
94
|
client.get('/api/bilibili/emoji', async (_request, reply) => {
|
|
72
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
95
|
+
reply.type('application/json').send(await new BilibiliResult("emoji\u6570\u636E" /* BilibiliDataType.emoji数据 */, this.bilibili).result());
|
|
73
96
|
});
|
|
74
97
|
client.get('/api/bilibili/bangumivideoinfo', async (request, reply) => {
|
|
75
98
|
const url = request.query.url;
|
|
76
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
99
|
+
reply.type('application/json').send(await new BilibiliResult("\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E" /* BilibiliDataType.番剧基本信息数据 */, this.bilibili).result({ url }));
|
|
77
100
|
});
|
|
78
101
|
client.get('/api/bilibili/bangumivideodownloadlink', async (request, reply) => {
|
|
79
102
|
const { cid, ep_id } = request.query;
|
|
80
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
103
|
+
reply.type('application/json').send(await new BilibiliResult("\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E" /* BilibiliDataType.番剧下载信息数据 */, this.bilibili).result({ cid, ep_id }));
|
|
81
104
|
});
|
|
82
105
|
client.get('/api/bilibili/dynamiclist', async (request, reply) => {
|
|
83
106
|
const host_mid = request.query.host_mid;
|
|
84
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
107
|
+
reply.type('application/json').send(await new BilibiliResult("\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E" /* BilibiliDataType.用户主页动态列表数据 */, this.bilibili).result({ host_mid }));
|
|
85
108
|
});
|
|
86
109
|
client.get('/api/bilibili/dynamicinfo', async (request, reply) => {
|
|
87
110
|
const dynamic_id = request.query.dynamic_id;
|
|
88
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
111
|
+
reply.type('application/json').send(await new BilibiliResult("\u52A8\u6001\u8BE6\u60C5\u6570\u636E" /* BilibiliDataType.动态详情数据 */, this.bilibili).result({ dynamic_id }));
|
|
89
112
|
});
|
|
90
113
|
client.get('/api/bilibili/dynamicdard', async (request, reply) => {
|
|
91
114
|
const dynamic_id = request.query.dynamic_id;
|
|
92
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
115
|
+
reply.type('application/json').send(await new BilibiliResult("\u52A8\u6001\u5361\u7247\u6570\u636E" /* BilibiliDataType.动态卡片数据 */, this.bilibili).result({ dynamic_id }));
|
|
93
116
|
});
|
|
94
117
|
client.get('/api/bilibili/userinfo', async (request, reply) => {
|
|
95
118
|
const host_mid = request.query.host_mid;
|
|
96
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
119
|
+
reply.type('application/json').send(await new BilibiliResult("\u7528\u6237\u4E3B\u9875\u6570\u636E" /* BilibiliDataType.用户主页数据 */, this.bilibili).result({ host_mid }));
|
|
97
120
|
});
|
|
98
121
|
client.get('/api/bilibili/liveroominfo', async (request, reply) => {
|
|
99
122
|
const room_id = request.query.room_id;
|
|
100
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
123
|
+
reply.type('application/json').send(await new BilibiliResult("\u76F4\u64AD\u95F4\u4FE1\u606F" /* BilibiliDataType.直播间信息 */, this.bilibili).result({ room_id }));
|
|
101
124
|
});
|
|
102
125
|
client.get('/api/bilibili/liveroominit', async (request, reply) => {
|
|
103
126
|
const room_id = request.query.room_id;
|
|
104
|
-
reply.type('application/json').send(await new BilibiliResult("
|
|
127
|
+
reply.type('application/json').send(await new BilibiliResult("\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F" /* BilibiliDataType.直播间初始化信息 */, this.bilibili).result({ room_id }));
|
|
105
128
|
});
|
|
106
|
-
|
|
107
|
-
|
|
129
|
+
return {
|
|
130
|
+
Instance: client,
|
|
131
|
+
GetDouyinData: this.GetDouyinData,
|
|
132
|
+
GetBilibiliData: this.GetBilibiliData
|
|
133
|
+
};
|
|
108
134
|
}
|
|
135
|
+
GetDouyinData = (data) => {
|
|
136
|
+
return new DouyinResult(data.type, this.douyin, true);
|
|
137
|
+
};
|
|
138
|
+
GetBilibiliData = (data) => {
|
|
139
|
+
return new BilibiliResult(data.type, this.bilibili, true);
|
|
140
|
+
};
|
|
109
141
|
}
|
package/lib/server/listen.d.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import { FastifyInstance } from 'fastify';
|
|
2
|
-
interface ServerOptions {
|
|
3
|
-
/**
|
|
4
|
-
* 端口
|
|
5
|
-
*/
|
|
6
|
-
port?: number;
|
|
7
|
-
/**
|
|
8
|
-
* 是否启用日志
|
|
9
|
-
*/
|
|
10
|
-
log?: boolean;
|
|
11
|
-
}
|
|
12
2
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param client
|
|
15
|
-
* @param
|
|
3
|
+
* 启动本地 http 服务
|
|
4
|
+
* @param client Fastify 实例
|
|
5
|
+
* @param port 监听端口
|
|
16
6
|
* @returns
|
|
17
7
|
*/
|
|
18
|
-
export declare const StartClient: (client: FastifyInstance,
|
|
19
|
-
export {};
|
|
8
|
+
export declare const StartClient: (client: FastifyInstance, port: 4567) => Promise<void>;
|
package/lib/server/listen.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { logger } from '../model/index.js';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param client
|
|
5
|
-
* @param
|
|
2
|
+
* 启动本地 http 服务
|
|
3
|
+
* @param client Fastify 实例
|
|
4
|
+
* @param port 监听端口
|
|
6
5
|
* @returns
|
|
7
6
|
*/
|
|
8
|
-
export const StartClient = async (client,
|
|
9
|
-
return client.listen({ port:
|
|
7
|
+
export const StartClient = async (client, port) => {
|
|
8
|
+
return client.listen({ port: port, host: '::' }, (_err, _address) => {
|
|
10
9
|
if (_err)
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
client.log.error(_err);
|
|
11
|
+
console.log(`amagi server listening on ${port} port. API docs: https://amagi.apifox.cn`);
|
|
13
12
|
});
|
|
14
13
|
};
|
package/lib/types/DataType.d.ts
CHANGED
|
@@ -2,33 +2,32 @@
|
|
|
2
2
|
* 抖音接口类型
|
|
3
3
|
*/
|
|
4
4
|
export declare const enum DouyinDataType {
|
|
5
|
-
二级评论数据 = "
|
|
6
|
-
用户主页数据 = "
|
|
7
|
-
单个视频作品数据 = "
|
|
8
|
-
评论数据 = "
|
|
9
|
-
用户主页视频列表数据 = "
|
|
10
|
-
热点词数据 = "
|
|
11
|
-
搜索数据 = "
|
|
12
|
-
官方emoji数据 = "
|
|
13
|
-
动态表情数据 = "
|
|
14
|
-
音乐数据 = "
|
|
15
|
-
图集作品数据 = "
|
|
16
|
-
实况图片图集数据 = "
|
|
5
|
+
二级评论数据 = "\u4E8C\u7EA7\u8BC4\u8BBA\u6570\u636E",
|
|
6
|
+
用户主页数据 = "\u7528\u6237\u4E3B\u9875\u6570\u636E",
|
|
7
|
+
单个视频作品数据 = "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E",
|
|
8
|
+
评论数据 = "\u8BC4\u8BBA\u6570\u636E",
|
|
9
|
+
用户主页视频列表数据 = "\u7528\u6237\u4E3B\u9875\u89C6\u9891\u5217\u8868\u6570\u636E",
|
|
10
|
+
热点词数据 = "\u70ED\u70B9\u8BCD\u6570\u636E",
|
|
11
|
+
搜索数据 = "\u641C\u7D22\u6570\u636E",
|
|
12
|
+
官方emoji数据 = "\u5B98\u65B9emoji\u6570\u636E",
|
|
13
|
+
动态表情数据 = "\u52A8\u6001\u8868\u60C5\u6570\u636E",
|
|
14
|
+
音乐数据 = "\u97F3\u4E50\u6570\u636E",
|
|
15
|
+
图集作品数据 = "\u56FE\u96C6\u4F5C\u54C1\u6570\u636E",
|
|
16
|
+
实况图片图集数据 = "\u5B9E\u51B5\u56FE\u7247\u56FE\u96C6\u6570\u636E"
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* B站接口类型
|
|
20
20
|
*/
|
|
21
21
|
export declare const enum BilibiliDataType {
|
|
22
|
-
单个视频作品数据 = "
|
|
23
|
-
评论数据 = "
|
|
24
|
-
用户主页数据 = "
|
|
25
|
-
用户主页动态列表数据 = "
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
直播间初始化信息 = "LiveRoomInitData"
|
|
22
|
+
单个视频作品数据 = "\u5355\u4E2A\u89C6\u9891\u4F5C\u54C1\u6570\u636E",
|
|
23
|
+
评论数据 = "\u8BC4\u8BBA\u6570\u636E",
|
|
24
|
+
用户主页数据 = "\u7528\u6237\u4E3B\u9875\u6570\u636E",
|
|
25
|
+
用户主页动态列表数据 = "\u7528\u6237\u4E3B\u9875\u52A8\u6001\u5217\u8868\u6570\u636E",
|
|
26
|
+
emoji数据 = "emoji\u6570\u636E",
|
|
27
|
+
番剧基本信息数据 = "\u756A\u5267\u57FA\u672C\u4FE1\u606F\u6570\u636E",
|
|
28
|
+
番剧下载信息数据 = "\u756A\u5267\u4E0B\u8F7D\u4FE1\u606F\u6570\u636E",
|
|
29
|
+
动态详情数据 = "\u52A8\u6001\u8BE6\u60C5\u6570\u636E",
|
|
30
|
+
动态卡片数据 = "\u52A8\u6001\u5361\u7247\u6570\u636E",
|
|
31
|
+
直播间信息 = "\u76F4\u64AD\u95F4\u4FE1\u606F",
|
|
32
|
+
直播间初始化信息 = "\u76F4\u64AD\u95F4\u521D\u59CB\u5316\u4FE1\u606F"
|
|
34
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikenxuan/amagi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -34,9 +34,8 @@
|
|
|
34
34
|
"chokidar": "^3.6.0",
|
|
35
35
|
"fastify": "^4.28.1",
|
|
36
36
|
"lodash": "4.17.21",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"md5": "^2.3.0"
|
|
37
|
+
"md5": "^2.3.0",
|
|
38
|
+
"pino-pretty": "^11.2.2"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@types/lodash": "latest",
|
package/lib/model/logger.d.ts
DELETED
package/lib/model/logger.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import log from 'loglevel';
|
|
3
|
-
import prefix from 'loglevel-plugin-prefix';
|
|
4
|
-
const colors = {
|
|
5
|
-
TRACE: chalk.magenta,
|
|
6
|
-
DEBUG: chalk.cyan,
|
|
7
|
-
INFO: chalk.blue,
|
|
8
|
-
WARN: chalk.yellow,
|
|
9
|
-
ERROR: chalk.red
|
|
10
|
-
};
|
|
11
|
-
prefix.reg(log);
|
|
12
|
-
log.enableAll();
|
|
13
|
-
prefix.apply(log, {
|
|
14
|
-
format (level, name, timestamp) {
|
|
15
|
-
const levelKey = level.toUpperCase();
|
|
16
|
-
if (!(levelKey in colors)) {
|
|
17
|
-
throw new Error(`Invalid log level: ${levelKey}`);
|
|
18
|
-
}
|
|
19
|
-
return `${chalk.gray(`[${timestamp}]`)} ${colors[levelKey](level)} ${chalk.green(`${name}:`)}`;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
prefix.apply(log.getLogger('critical'), {
|
|
23
|
-
format (level, name, timestamp) {
|
|
24
|
-
return chalk.red.bold(`[${timestamp}] ${level} ${name}:`);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
const logger = log;
|
|
28
|
-
export default logger;
|