koishi-plugin-video-parser-all 1.5.6 → 1.5.7

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.
Files changed (2) hide show
  1. package/lib/index.js +24 -23
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -719,14 +719,17 @@ function apply(ctx, config) {
719
719
  const imgSig = p.images?.length ? p.images.slice(0, 3).join('|') : (p.live_photo?.slice(0, 3).map(lp => lp.image).join('|') || '');
720
720
  return [p.type, p.title, p.author, p.uid, p.video, imgSig].map(v => String(v ?? '')).join('::');
721
721
  }
722
- const texts = {
723
- waitingTipText: config.waitingTipText || '正在解析视频,请稍候...',
724
- unsupportedPlatformText: config.unsupportedPlatformText || '不支持该平台链接',
725
- invalidLinkText: config.invalidLinkText || '无效的视频链接',
726
- parseErrorPrefix: config.parseErrorPrefix || '❌ 解析失败:',
727
- parseErrorItemFormat: config.parseErrorItemFormat || '【${url}】: ${msg}',
728
- deduplicationTipText: config.deduplicationTipText || '链接 ${url} 在最近 ${interval} 秒内已解析过,已跳过。',
729
- };
722
+ function getText(key) {
723
+ const defaults = {
724
+ waitingTipText: '正在解析视频,请稍候...',
725
+ unsupportedPlatformText: '不支持该平台链接',
726
+ invalidLinkText: '无效的视频链接',
727
+ parseErrorPrefix: ' 解析失败:',
728
+ parseErrorItemFormat: '【${url}】: ${msg}',
729
+ deduplicationTipText: '链接 ${url} 在最近 ${interval} 秒内已解析过,已跳过。',
730
+ };
731
+ return config[key] || defaults[key] || '';
732
+ }
730
733
  const proxyConfig = config.proxy || {};
731
734
  const customPlatforms = (config.customPlatforms || []).map((p) => ({
732
735
  name: p.name,
@@ -835,7 +838,7 @@ function apply(ctx, config) {
835
838
  if (lastTime && (Date.now() - lastTime < config.deduplicationInterval * 1000)) {
836
839
  debugLog('INFO', `跳过重复链接: ${match.url}`);
837
840
  const shortUrl = match.url.length > 80 ? match.url.slice(0, 80) + '...' : match.url;
838
- const tip = texts.deduplicationTipText.replace(/\$\{url\}/g, shortUrl).replace(/\$\{interval\}/g, String(config.deduplicationInterval));
841
+ const tip = getText('deduplicationTipText').replace(/\$\{url\}/g, shortUrl).replace(/\$\{interval\}/g, String(config.deduplicationInterval));
839
842
  await sendWithTimeout(session, tip).catch(() => { });
840
843
  return;
841
844
  }
@@ -859,7 +862,7 @@ function apply(ctx, config) {
859
862
  }
860
863
  else {
861
864
  const displayUrl = match.url.length > 80 ? match.url.slice(0, 80) + '...' : match.url;
862
- const item = texts.parseErrorItemFormat.replace(/\$\{url\}/g, displayUrl).replace(/\$\{msg\}/g, result.msg);
865
+ const item = getText('parseErrorItemFormat').replace(/\$\{url\}/g, displayUrl).replace(/\$\{msg\}/g, result.msg);
863
866
  errors.push(item);
864
867
  }
865
868
  }
@@ -869,7 +872,7 @@ function apply(ctx, config) {
869
872
  });
870
873
  await Promise.all(promises);
871
874
  if (errors.length)
872
- await sendWithTimeout(session, `${texts.parseErrorPrefix}\n${errors.join('\n')}`);
875
+ await sendWithTimeout(session, `${getText('parseErrorPrefix')}\n${errors.join('\n')}`);
873
876
  if (!items.length)
874
877
  return;
875
878
  const enableForward = config.enableForward && (session.platform === 'onebot' || session.platform === 'satori');
@@ -900,8 +903,6 @@ function apply(ctx, config) {
900
903
  if (p.type === 'live_photo' && p.live_photo?.length) {
901
904
  for (const lp of p.live_photo) {
902
905
  forwardMessages.push(buildForwardNode(session, koishi_1.h.image(lp.image), botName));
903
- if (lp.video)
904
- forwardMessages.push(buildForwardNode(session, koishi_1.h.video(lp.video), botName));
905
906
  }
906
907
  }
907
908
  else if (p.type === 'image' || (p.type === 'live' && (p.live_photo?.length || p.images?.length))) {
@@ -917,13 +918,15 @@ function apply(ctx, config) {
917
918
  forwardMessages.push(buildForwardNode(session, koishi_1.h.audio(p.music.url), botName));
918
919
  }
919
920
  }
920
- if (forwardMessages.length) {
921
+ const MAX_NODES = 50;
922
+ for (let i = 0; i < forwardMessages.length; i += MAX_NODES) {
923
+ const batch = forwardMessages.slice(i, i + MAX_NODES);
921
924
  try {
922
- await sendWithTimeout(session, (0, koishi_1.h)('message', { forward: true }, forwardMessages.slice(0, 100)), config.retryTimes);
925
+ await sendWithTimeout(session, (0, koishi_1.h)('message', { forward: true }, batch), config.retryTimes);
923
926
  }
924
927
  catch (err) {
925
928
  debugLog('ERROR', '合并转发失败,降级逐条发送:', err);
926
- for (const node of forwardMessages) {
929
+ for (const node of batch) {
927
930
  await sendWithTimeout(session, node.data.content).catch(() => { });
928
931
  await delay(300);
929
932
  }
@@ -958,8 +961,6 @@ function apply(ctx, config) {
958
961
  if (p.type === 'live_photo' && p.live_photo?.length) {
959
962
  for (const lp of p.live_photo) {
960
963
  await sendMedia(session, lp.image, 'image', config.showImageFileNew).catch(() => { });
961
- if (lp.video)
962
- await sendMedia(session, lp.video, 'video', config.showVideoFile).catch(() => { });
963
964
  await delay(500);
964
965
  }
965
966
  }
@@ -1083,7 +1084,7 @@ function apply(ctx, config) {
1083
1084
  debugLog('ERROR', `解析失败: ${cleanedUrl}`, getErrorMessage(error));
1084
1085
  return { success: false, msg: getErrorMessage(error) };
1085
1086
  }
1086
- return { success: false, msg: texts.unsupportedPlatformText };
1087
+ return { success: false, msg: getText('unsupportedPlatformText') };
1087
1088
  }
1088
1089
  async function processSingleUrl(url, type, fieldMapping, platformConf) {
1089
1090
  const result = await parseUrl(url, type, fieldMapping, platformConf);
@@ -1155,7 +1156,7 @@ function apply(ctx, config) {
1155
1156
  debugLog('INFO', `检测到 ${matches.length} 个链接`);
1156
1157
  if (config.showWaitingTip) {
1157
1158
  try {
1158
- await sendWithTimeout(session, texts.waitingTipText);
1159
+ await sendWithTimeout(session, getText('waitingTipText'));
1159
1160
  }
1160
1161
  catch (e) {
1161
1162
  debugLog('WARN', '等待提示发送失败:', e);
@@ -1165,17 +1166,17 @@ function apply(ctx, config) {
1165
1166
  });
1166
1167
  ctx.command('parse <url>', '手动解析视频').action(async ({ session }, url) => {
1167
1168
  if (!url) {
1168
- await sendWithTimeout(session, texts.invalidLinkText);
1169
+ await sendWithTimeout(session, getText('invalidLinkText'));
1169
1170
  return;
1170
1171
  }
1171
1172
  const matches = linkTypeParser(url, customRules);
1172
1173
  if (!matches.length) {
1173
- await sendWithTimeout(session, texts.invalidLinkText);
1174
+ await sendWithTimeout(session, getText('invalidLinkText'));
1174
1175
  return;
1175
1176
  }
1176
1177
  if (config.showWaitingTip) {
1177
1178
  try {
1178
- await sendWithTimeout(session, texts.waitingTipText);
1179
+ await sendWithTimeout(session, getText('waitingTipText'));
1179
1180
  }
1180
1181
  catch { }
1181
1182
  }
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.5.6",
4
+ "version": "1.5.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": ["lib"],