@ikenxuan/amagi 1.4.8 → 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 CHANGED
@@ -1,3 +1,5 @@
1
+ ![amagi](https://socialify.git.ci/ikenxuan/amagi/image?font=Source%20Code%20Pro&forks=1&issues=1&language=1&name=1&owner=1&pattern=Floating%20Cogs&pulls=1&stargazers=1&theme=Auto)
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
- 房间页初始化信息(data: BilibiliAPIParams['LiveRoomParams']): string;
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
- 房间页初始化信息(data) {
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.cookie);
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.cookie);
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
- export declare const amagi: typeof client;
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
- export const amagi = client;
6
+ const amagi = client;
7
7
  export { amagi as default };
8
+ export { amagi as Amagi };
@@ -1,3 +1,3 @@
1
- import log4js from 'log4js';
2
- declare const logger: log4js.Logger;
1
+ import log from 'loglevel';
2
+ declare const logger: log.RootLogger;
3
3
  export default logger;
@@ -1,28 +1,28 @@
1
- import log4js from 'log4js';
2
- log4js.configure({
3
- appenders: {
4
- console: {
5
- type: 'stdout',
6
- layout: {
7
- type: 'pattern',
8
- pattern: '%[[amagi][%d{hh:mm:ss.SSS}][%4.4p]%] %m',
9
- },
10
- },
11
- command: {
12
- type: 'dateFile', // 可以是console,dateFile,file,Logstash等
13
- filename: 'logs/command', // 将会按照filename和pattern拼接文件名
14
- pattern: 'yyyy-MM-dd.log',
15
- numBackups: 15,
16
- alwaysIncludePattern: true,
17
- layout: {
18
- type: 'pattern',
19
- pattern: '[%d{hh:mm:ss.SSS}][%4.4p] %m',
20
- },
21
- },
1
+ import log from 'loglevel';
2
+ import prefix from 'loglevel-plugin-prefix';
3
+ import chalk from 'chalk';
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}:`)}`;
22
20
  },
23
- categories: {
24
- default: { appenders: ['console'], level: 'debug' },
21
+ });
22
+ prefix.apply(log.getLogger('critical'), {
23
+ format(level, name, timestamp) {
24
+ return chalk.red.bold(`[${timestamp}] ${level} ${name}:`);
25
25
  },
26
26
  });
27
- const logger = log4js.getLogger();
27
+ const logger = log;
28
28
  export default logger;
@@ -1,15 +1,23 @@
1
1
  import { FastifyInstance } from 'fastify';
2
- export declare class client {
2
+ interface initClientParams {
3
+ /** 抖音ck */
3
4
  douyin: string;
5
+ /** B站ck */
4
6
  bilibili: string;
5
- constructor(cookies: {
6
- douyin: string;
7
- bilibili: string;
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 {};
@@ -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.host_mid;
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.host_mid;
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
  }
@@ -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 {};
@@ -1,7 +1,12 @@
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
- return client.listen({ port: options.port, host: '[::]' }, (_err, _address) => {
9
+ return client.listen({ port: options.port, host: '::' }, (_err, _address) => {
5
10
  if (_err)
6
11
  logger.error(_err);
7
12
  logger.info(`amagi server listening on http://localhost:${options.port}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikenxuan/amagi",
3
- "version": "1.4.8",
3
+ "version": "1.5.0",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -29,12 +29,14 @@
29
29
  "registry": "https://registry.npmjs.org"
30
30
  },
31
31
  "dependencies": {
32
- "@fastify/autoload": "^5.10.0",
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",
36
37
  "lodash": "4.17.21",
37
- "log4js": "^6.9.1",
38
+ "loglevel": "^1.9.1",
39
+ "loglevel-plugin-prefix": "^0.8.4",
38
40
  "md5": "^2.3.0",
39
41
  "node-fetch": "^3.3.2"
40
42
  },