From 624941054efd902eeac017254f9201eca905b1bd Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Sun, 12 Feb 2023 01:05:22 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=93=94=E5=93=A9=E5=93=94=E5=93=A9=E8=A7=A3=E6=9E=90=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 3492d8f..3ff82e0 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -182,15 +182,21 @@ export class tools extends plugin { mkdirsSync(path); } // 视频信息获取例子:http://api.bilibili.com/x/web-interface/view?bvid=BV1hY411m7cB - const baseVideoInfo = "http://api.bilibili.com/x/web-interface/view"; - console.log(url); - const videoId = /video\/(.*?)(\/|\?)/g.exec(url)[1]; - // 获取视频信息,然后发送 - fetch(videoId.startsWith("BV") ? `${baseVideoInfo}?bvid=${videoId}` : `${baseVideoInfo}?aid=${videoId}`) - .then(resp => resp.json()) - .then(resp => { - e.reply(`识别:哔哩哔哩, ${resp.data.title}`) + // 请求视频信息 + (function() { + const baseVideoInfo = "http://api.bilibili.com/x/web-interface/view"; + const videoId = /video\/[^\?\/ ]+/.exec(url)[0].split("/")[1]; + // 获取视频信息,然后发送 + fetch(videoId.startsWith("BV") ? `${baseVideoInfo}?bvid=${videoId}` : `${baseVideoInfo}?aid=${videoId}`) + .then(resp => resp.json()) + .then(resp => { + e.reply(`识别:哔哩哔哩, ${resp.data.title}`) + .catch(err => { + e.reply("解析失败,重试一下"); + console.log(err); + }) }) + }()) await getDownloadUrl(url) .then(data => {