@ikenxuan/amagi 1.4.9 → 1.5.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 +3 -1
- package/lib/business/bilibili/API.d.ts +1 -1
- package/lib/business/bilibili/API.js +1 -1
- package/lib/business/bilibili/getdata.js +18 -3
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/server/client.d.ts +14 -6
- package/lib/server/client.js +22 -5
- package/lib/server/listen.d.ts +6 -1
- package/lib/server/listen.js +6 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# amagi(泥干嘛哈哈
|
|
2
4
|
* 热门平台视频解析 API 基于 Node.js 的实现,支持最低node版本为 v16
|
|
3
5
|
* 抖音、B站
|
|
@@ -14,7 +16,7 @@ import amagi, { StartClient } from '@ikenxuan/amagi'
|
|
|
14
16
|
const client = await new amagi({
|
|
15
17
|
douyin: '抖音ck',
|
|
16
18
|
bilibili: 'B站ck'
|
|
17
|
-
}).initServer(true)
|
|
19
|
+
}).initServer(true) // 是否开启调试模式
|
|
18
20
|
|
|
19
21
|
// 启动监听
|
|
20
22
|
await StartClient(client, { port: 4567 })
|
|
@@ -13,7 +13,7 @@ declare class BiLiBiLiAPI {
|
|
|
13
13
|
动态卡片信息(data: BilibiliAPIParams['DynamicParams']): string;
|
|
14
14
|
用户名片信息(data: BilibiliAPIParams['UserParams']): string;
|
|
15
15
|
直播间信息(data: BilibiliAPIParams['LiveRoomParams']): string;
|
|
16
|
-
|
|
16
|
+
直播间初始化信息(data: BilibiliAPIParams['LiveRoomParams']): string;
|
|
17
17
|
申请二维码(): string;
|
|
18
18
|
二维码状态(data: BilibiliAPIParams['QrcodeParams']): string;
|
|
19
19
|
}
|
|
@@ -36,7 +36,7 @@ class BiLiBiLiAPI {
|
|
|
36
36
|
直播间信息(data) {
|
|
37
37
|
return `https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${data.room_id}`;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
直播间初始化信息(data) {
|
|
40
40
|
return `https://api.live.bilibili.com/room/v1/Room/room_init?id=${data.room_id}`;
|
|
41
41
|
}
|
|
42
42
|
申请二维码() {
|
|
@@ -17,7 +17,7 @@ export default class BilibiliData {
|
|
|
17
17
|
case 'VideoData': {
|
|
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
|
-
const SIGN = await qtparam(BASEURL, this.headers.
|
|
20
|
+
const SIGN = await qtparam(BASEURL, this.headers.Cookie);
|
|
21
21
|
const DATA = await this.GlobalGetData({
|
|
22
22
|
url: BiLiBiLiAPI.视频流信息({ avid: INFODATA.data.aid, cid: INFODATA.data.cid }) + SIGN.QUERY,
|
|
23
23
|
headers: this.headers
|
|
@@ -26,7 +26,7 @@ export default class BilibiliData {
|
|
|
26
26
|
}
|
|
27
27
|
case 'CommentData': {
|
|
28
28
|
const INFODATA = await this.GlobalGetData({ url: BiLiBiLiAPI.视频详细信息({ id_type: 'bvid', id: data.bvid }) });
|
|
29
|
-
const PARAM = await wbi_sign(BiLiBiLiAPI.评论区明细({ type: 1, oid: INFODATA.data.aid }), this.headers.
|
|
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
|
}
|
|
@@ -73,12 +73,27 @@ export default class BilibiliData {
|
|
|
73
73
|
});
|
|
74
74
|
return dynamicINFO_CARD;
|
|
75
75
|
}
|
|
76
|
-
case 'UserInfoData':
|
|
76
|
+
case 'UserInfoData': {
|
|
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
|
+
}
|
|
83
|
+
case 'LiveRoomInfoData': {
|
|
84
|
+
result = await this.GlobalGetData({
|
|
85
|
+
url: BiLiBiLiAPI.直播间信息({ room_id: data.room_id }),
|
|
86
|
+
headers: this.headers
|
|
87
|
+
});
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
case 'LiveRoomInitData': {
|
|
91
|
+
result = await this.GlobalGetData({
|
|
92
|
+
url: BiLiBiLiAPI.直播间初始化信息({ room_id: data.room_id }),
|
|
93
|
+
headers: this.headers
|
|
94
|
+
});
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
99
|
async GlobalGetData(options) {
|
package/lib/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export * from './business/index.js';
|
|
|
3
3
|
export * from './types/index.js';
|
|
4
4
|
export * from './server/index.js';
|
|
5
5
|
import { client } from './server/index.js';
|
|
6
|
-
|
|
6
|
+
declare const amagi: typeof client;
|
|
7
7
|
export { amagi as default };
|
|
8
|
+
export { amagi as Amagi };
|
package/lib/index.js
CHANGED
|
@@ -3,5 +3,6 @@ export * from './business/index.js';
|
|
|
3
3
|
export * from './types/index.js';
|
|
4
4
|
export * from './server/index.js';
|
|
5
5
|
import { client } from './server/index.js';
|
|
6
|
-
|
|
6
|
+
const amagi = client;
|
|
7
7
|
export { amagi as default };
|
|
8
|
+
export { amagi as Amagi };
|
package/lib/server/client.d.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { FastifyInstance } from 'fastify';
|
|
2
|
-
|
|
2
|
+
interface initClientParams {
|
|
3
|
+
/** 抖音ck */
|
|
3
4
|
douyin: string;
|
|
5
|
+
/** B站ck */
|
|
4
6
|
bilibili: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
}
|
|
8
|
+
export declare class client {
|
|
9
|
+
private readonly douyin;
|
|
10
|
+
private readonly bilibili;
|
|
9
11
|
/**
|
|
10
12
|
*
|
|
13
|
+
* @param cookies 包含抖音和B站cookie的参数对象
|
|
14
|
+
*/
|
|
15
|
+
constructor(cookies: initClientParams);
|
|
16
|
+
/**
|
|
17
|
+
* 初始化 fastify 实例
|
|
11
18
|
* @param log 是否启用日志
|
|
12
|
-
* @returns
|
|
19
|
+
* @returns fastify 实例
|
|
13
20
|
*/
|
|
14
21
|
initServer(log?: boolean): Promise<FastifyInstance>;
|
|
15
22
|
}
|
|
23
|
+
export {};
|
package/lib/server/client.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import fastify from 'fastify';
|
|
2
2
|
import { DouyinResult } from '../business/douyin/index.js';
|
|
3
3
|
import { BilibiliResult } from '../business/bilibili/index.js';
|
|
4
|
+
import fastifySwagger from '@fastify/swagger';
|
|
5
|
+
import fastifySwaggerUi from '@fastify/swagger-ui';
|
|
6
|
+
import fs from 'node:fs';
|
|
4
7
|
export class client {
|
|
5
8
|
douyin;
|
|
6
9
|
bilibili;
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param cookies 包含抖音和B站cookie的参数对象
|
|
13
|
+
*/
|
|
7
14
|
constructor(cookies) {
|
|
8
15
|
/** 抖音ck */
|
|
9
16
|
this.douyin = cookies.douyin;
|
|
@@ -11,12 +18,22 @@ export class client {
|
|
|
11
18
|
this.bilibili = cookies.bilibili;
|
|
12
19
|
}
|
|
13
20
|
/**
|
|
14
|
-
*
|
|
21
|
+
* 初始化 fastify 实例
|
|
15
22
|
* @param log 是否启用日志
|
|
16
|
-
* @returns
|
|
23
|
+
* @returns fastify 实例
|
|
17
24
|
*/
|
|
18
25
|
async initServer(log = false) {
|
|
19
26
|
const client = fastify({ logger: log });
|
|
27
|
+
const data = JSON.parse(fs.readFileSync(process.cwd() + '/amagi.openapi.json', 'utf8'));
|
|
28
|
+
await client.register(fastifySwagger, {
|
|
29
|
+
openapi: data
|
|
30
|
+
});
|
|
31
|
+
await client.register(fastifySwaggerUi, {
|
|
32
|
+
routePrefix: '/docs',
|
|
33
|
+
uiConfig: {
|
|
34
|
+
docExpansion: 'full',
|
|
35
|
+
},
|
|
36
|
+
});
|
|
20
37
|
client.get('/api/douyin/aweme', async (request, reply) => {
|
|
21
38
|
const url = request.query.url;
|
|
22
39
|
reply.type('application/json').send(await new DouyinResult("VideoData" /* DouyinDataType['单个视频作品数据'] */, this.douyin).result({ url }));
|
|
@@ -92,14 +109,14 @@ export class client {
|
|
|
92
109
|
reply.type('application/json').send(await new BilibiliResult("UserInfoData" /* BilibiliDataType['用户主页数据'] */, this.bilibili).result({ host_mid }));
|
|
93
110
|
});
|
|
94
111
|
client.get('/api/bilibili/liveroominfo', async (request, reply) => {
|
|
95
|
-
const room_id = request.query.
|
|
112
|
+
const room_id = request.query.room_id;
|
|
96
113
|
reply.type('application/json').send(await new BilibiliResult("LiveRoomInfoData" /* BilibiliDataType['直播间信息'] */, this.bilibili).result({ room_id }));
|
|
97
114
|
});
|
|
98
115
|
client.get('/api/bilibili/liveroominit', async (request, reply) => {
|
|
99
|
-
const room_id = request.query.
|
|
116
|
+
const room_id = request.query.room_id;
|
|
100
117
|
reply.type('application/json').send(await new BilibiliResult("LiveRoomInitData" /* BilibiliDataType['直播间初始化信息'] */, this.bilibili).result({ room_id }));
|
|
101
118
|
});
|
|
102
|
-
// 返回fastify实例
|
|
119
|
+
// 返回 fastify 实例
|
|
103
120
|
return client;
|
|
104
121
|
}
|
|
105
122
|
}
|
package/lib/server/listen.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ interface ServerOptions {
|
|
|
9
9
|
*/
|
|
10
10
|
log?: boolean;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* 启动 fastify 实例
|
|
14
|
+
* @param client fastify 实例
|
|
15
|
+
* @param options 配置项
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
13
18
|
export declare const StartClient: (client: FastifyInstance, options: ServerOptions) => Promise<void>;
|
|
14
19
|
export {};
|
package/lib/server/listen.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { logger } from '../model/index.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* 启动 fastify 实例
|
|
4
|
+
* @param client fastify 实例
|
|
5
|
+
* @param options 配置项
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
3
8
|
export const StartClient = async (client, options) => {
|
|
4
9
|
return client.listen({ port: options.port, host: '::' }, (_err, _address) => {
|
|
5
10
|
if (_err)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikenxuan/amagi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"registry": "https://registry.npmjs.org"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@fastify/
|
|
32
|
+
"@fastify/swagger": "^8.15.0",
|
|
33
|
+
"@fastify/swagger-ui": "^4.0.1",
|
|
33
34
|
"chalk": "^5.3.0",
|
|
34
35
|
"chokidar": "^3.6.0",
|
|
35
36
|
"fastify": "^4.28.1",
|