koishi-plugin-video-parser-all 1.1.8 → 1.2.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/lib/index.d.ts ADDED
@@ -0,0 +1,122 @@
1
+ import { Context, Schema } from 'koishi';
2
+ export declare const name = "video-parser-all";
3
+ export declare const Config: Schema<{
4
+ enable?: boolean | null | undefined;
5
+ botName?: string | null | undefined;
6
+ showWaitingTip?: boolean | null | undefined;
7
+ debug?: boolean | null | undefined;
8
+ } & import("cosmokit").Dict & {
9
+ unifiedMessageFormat?: string | null | undefined;
10
+ } & {
11
+ showImageText?: boolean | null | undefined;
12
+ showVideoFile?: boolean | null | undefined;
13
+ maxDescLength?: number | null | undefined;
14
+ videoDownloadTimeout?: number | null | undefined;
15
+ tempDir?: string | null | undefined;
16
+ maxVideoSize?: number | null | undefined;
17
+ forceDownloadVideo?: boolean | null | undefined;
18
+ } & {
19
+ timeout?: number | null | undefined;
20
+ videoSendTimeout?: number | null | undefined;
21
+ userAgent?: string | null | undefined;
22
+ } & {
23
+ ignoreSendError?: boolean | null | undefined;
24
+ retryTimes?: number | null | undefined;
25
+ retryInterval?: number | null | undefined;
26
+ } & {
27
+ enableForward?: boolean | null | undefined;
28
+ } & {
29
+ deduplicationInterval?: number | null | undefined;
30
+ } & {
31
+ primaryApiUrl?: string | null | undefined;
32
+ backupApiUrl?: string | null | undefined;
33
+ platformDedicatedFirst?: ({
34
+ bilibili?: boolean | null | undefined;
35
+ douyin?: boolean | null | undefined;
36
+ kuaishou?: boolean | null | undefined;
37
+ xiaohongshu?: boolean | null | undefined;
38
+ weibo?: boolean | null | undefined;
39
+ xigua?: boolean | null | undefined;
40
+ youtube?: boolean | null | undefined;
41
+ tiktok?: boolean | null | undefined;
42
+ acfun?: boolean | null | undefined;
43
+ zhihu?: boolean | null | undefined;
44
+ weishi?: boolean | null | undefined;
45
+ huya?: boolean | null | undefined;
46
+ haokan?: boolean | null | undefined;
47
+ meipai?: boolean | null | undefined;
48
+ twitter?: boolean | null | undefined;
49
+ instagram?: boolean | null | undefined;
50
+ doubao?: boolean | null | undefined;
51
+ } & import("cosmokit").Dict) | null | undefined;
52
+ customApis?: ({
53
+ platform?: "bilibili" | "douyin" | "kuaishou" | "xiaohongshu" | "weibo" | "xigua" | "youtube" | "tiktok" | "acfun" | "zhihu" | "weishi" | "huya" | "haokan" | "meipai" | "twitter" | "instagram" | "doubao" | null | undefined;
54
+ apiUrl?: string | null | undefined;
55
+ } & import("cosmokit").Dict)[] | null | undefined;
56
+ } & {
57
+ waitingTipText?: string | null | undefined;
58
+ unsupportedPlatformText?: string | null | undefined;
59
+ invalidLinkText?: string | null | undefined;
60
+ parseErrorPrefix?: string | null | undefined;
61
+ parseErrorItemFormat?: string | null | undefined;
62
+ }, {
63
+ enable: boolean;
64
+ botName: string;
65
+ showWaitingTip: boolean;
66
+ debug: boolean;
67
+ } & import("cosmokit").Dict & {
68
+ unifiedMessageFormat: string;
69
+ } & {
70
+ showImageText: boolean;
71
+ showVideoFile: boolean;
72
+ maxDescLength: number;
73
+ videoDownloadTimeout: number;
74
+ tempDir: string;
75
+ maxVideoSize: number;
76
+ forceDownloadVideo: boolean;
77
+ } & {
78
+ timeout: number;
79
+ videoSendTimeout: number;
80
+ userAgent: string;
81
+ } & {
82
+ ignoreSendError: boolean;
83
+ retryTimes: number;
84
+ retryInterval: number;
85
+ } & {
86
+ enableForward: boolean;
87
+ } & {
88
+ deduplicationInterval: number;
89
+ } & {
90
+ primaryApiUrl: string;
91
+ backupApiUrl: string;
92
+ platformDedicatedFirst: Schemastery.ObjectT<{
93
+ bilibili: Schema<boolean, boolean>;
94
+ douyin: Schema<boolean, boolean>;
95
+ kuaishou: Schema<boolean, boolean>;
96
+ xiaohongshu: Schema<boolean, boolean>;
97
+ weibo: Schema<boolean, boolean>;
98
+ xigua: Schema<boolean, boolean>;
99
+ youtube: Schema<boolean, boolean>;
100
+ tiktok: Schema<boolean, boolean>;
101
+ acfun: Schema<boolean, boolean>;
102
+ zhihu: Schema<boolean, boolean>;
103
+ weishi: Schema<boolean, boolean>;
104
+ huya: Schema<boolean, boolean>;
105
+ haokan: Schema<boolean, boolean>;
106
+ meipai: Schema<boolean, boolean>;
107
+ twitter: Schema<boolean, boolean>;
108
+ instagram: Schema<boolean, boolean>;
109
+ doubao: Schema<boolean, boolean>;
110
+ }>;
111
+ customApis: Schemastery.ObjectT<{
112
+ platform: Schema<"bilibili" | "douyin" | "kuaishou" | "xiaohongshu" | "weibo" | "xigua" | "youtube" | "tiktok" | "acfun" | "zhihu" | "weishi" | "huya" | "haokan" | "meipai" | "twitter" | "instagram" | "doubao", "bilibili" | "douyin" | "kuaishou" | "xiaohongshu" | "weibo" | "xigua" | "youtube" | "tiktok" | "acfun" | "zhihu" | "weishi" | "huya" | "haokan" | "meipai" | "twitter" | "instagram" | "doubao">;
113
+ apiUrl: Schema<string, string>;
114
+ }>[];
115
+ } & {
116
+ waitingTipText: string;
117
+ unsupportedPlatformText: string;
118
+ invalidLinkText: string;
119
+ parseErrorPrefix: string;
120
+ parseErrorItemFormat: string;
121
+ }>;
122
+ export declare function apply(ctx: Context, config: any): void;
package/lib/index.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Config = exports.name = void 0;
7
7
  exports.apply = apply;
8
8
  const koishi_1 = require("koishi");
9
+ const axios_1 = __importDefault(require("axios"));
9
10
  const promises_1 = __importDefault(require("fs/promises"));
10
11
  const path_1 = __importDefault(require("path"));
11
12
  const fs_1 = require("fs");
@@ -449,6 +450,14 @@ function apply(ctx, config) {
449
450
  parseErrorPrefix: config.parseErrorPrefix || '❌ 解析失败:',
450
451
  parseErrorItemFormat: config.parseErrorItemFormat || '【${url}】: ${msg}',
451
452
  };
453
+ const http = axios_1.default.create({
454
+ timeout: config.timeout,
455
+ headers: {
456
+ 'User-Agent': config.userAgent,
457
+ 'Referer': 'https://www.baidu.com/',
458
+ 'Content-Type': 'application/x-www-form-urlencoded'
459
+ }
460
+ });
452
461
  const defaultDedicatedApis = {
453
462
  bilibili: 'https://api.bugpk.com/api/bilibili',
454
463
  douyin: 'https://api.bugpk.com/api/douyin',
@@ -475,8 +484,9 @@ function apply(ctx, config) {
475
484
  }
476
485
  async function resolveShortUrl(url) {
477
486
  try {
478
- const res = await ctx.http.get(url, {
487
+ const res = await http.get(url, {
479
488
  timeout: 10000,
489
+ maxRedirects: 10,
480
490
  headers: {
481
491
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
482
492
  'Referer': 'https://www.baidu.com/',
@@ -503,7 +513,9 @@ function apply(ctx, config) {
503
513
  const writer = (0, fs_1.createWriteStream)(filePath);
504
514
  let response;
505
515
  try {
506
- response = await ctx.http.get(videoUrl, {
516
+ response = await http({
517
+ method: 'GET',
518
+ url: videoUrl,
507
519
  responseType: 'stream',
508
520
  timeout: config.videoDownloadTimeout || 120000,
509
521
  headers: {
@@ -519,7 +531,7 @@ function apply(ctx, config) {
519
531
  throw new Error(`下载视频失败: ${getErrorMessage(e)}`);
520
532
  }
521
533
  const maxSizeBytes = (config.maxVideoSize || 0) * 1024 * 1024;
522
- const contentLength = Number(response.headers?.['content-length'] || 0);
534
+ const contentLength = Number(response.headers['content-length'] || 0);
523
535
  if (maxSizeBytes > 0 && contentLength > maxSizeBytes) {
524
536
  writer.destroy();
525
537
  await promises_1.default.unlink(filePath).catch(() => { });
@@ -564,13 +576,9 @@ function apply(ctx, config) {
564
576
  for (const api of apiList) {
565
577
  for (let attempt = 0; attempt <= config.retryTimes; attempt++) {
566
578
  try {
567
- const res = await ctx.http.get(api.url, {
579
+ const res = await http.get(api.url, {
568
580
  params: { url },
569
- timeout: config.timeout,
570
- headers: {
571
- 'User-Agent': config.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
572
- 'Referer': 'https://www.baidu.com/',
573
- },
581
+ timeout: config.timeout
574
582
  });
575
583
  if (res.data && (res.data.code === 200 || res.data.code === 0)) {
576
584
  const parsed = parseApiResponse(res.data, config.maxDescLength);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-video-parser-all",
3
3
  "description": "Koishi 全平台视频解析插件,支持抖音/快手/B站/微博/小红书/剪映/YouTube/TikTok等20+平台",
4
- "version": "1.1.8",
4
+ "version": "1.2.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [