mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
✨ feat: 更改哔哩哔哩解析逻辑 & 🎈 perf: 提升论文解析速度
1. 增加bv av互转 2. 删除代码中的av逻辑,出现av一律转换为bv 3. 论文解析从race转换为any
This commit is contained in:
parent
4e50f786e6
commit
1cd916d48f
@ -19,6 +19,7 @@ import { getVideoInfo } from "../utils/biliInfo.js";
|
||||
import { getBiliGptInputText } from "../utils/biliSummary.js";
|
||||
import { getBodianAudio, getBodianMv, getBodianMusicInfo } from "../utils/bodian.js";
|
||||
import { ChatGPTClient } from "@waylaidwanderer/chatgpt-api";
|
||||
import { av2BV } from "../utils/bilibili-bv-av-convert.js";
|
||||
|
||||
export class tools extends plugin {
|
||||
constructor() {
|
||||
@ -298,7 +299,11 @@ export class tools extends plugin {
|
||||
} else if (url.includes("www.bilibili.com")) {
|
||||
url = urlRex.exec(url)[0];
|
||||
}
|
||||
|
||||
// av处理
|
||||
const matched = url.match(/(av|AV)(\w+)/);
|
||||
if (matched) {
|
||||
url = url.replace(matched[0], av2BV(Number(matched[2])));
|
||||
}
|
||||
// 动态
|
||||
if (url.includes("t.bilibili.com")) {
|
||||
// 去除多余参数
|
||||
@ -819,7 +824,7 @@ export class tools extends plugin {
|
||||
const newWaitList = waitList.map(item => {
|
||||
return item + flag;
|
||||
});
|
||||
await Promise.race(newWaitList).then(resp => {
|
||||
await Promise.any(newWaitList).then(resp => {
|
||||
e.reply(resp);
|
||||
});
|
||||
}
|
||||
|
@ -4,21 +4,18 @@ async function getVideoInfo(url) {
|
||||
const baseVideoInfo = "http://api.bilibili.com/x/web-interface/view";
|
||||
const videoId = /video\/[^\?\/ ]+/.exec(url)[0].split("/")[1];
|
||||
// 获取视频信息,然后发送
|
||||
return fetch(
|
||||
videoId.startsWith("BV")
|
||||
? `${baseVideoInfo}?bvid=${videoId}`
|
||||
: `${baseVideoInfo}?aid=${videoId}`,
|
||||
).then(async resp => {
|
||||
const respJson = await resp.json();
|
||||
const respData = respJson.data;
|
||||
return {
|
||||
title: respData.title,
|
||||
desc: respData.desc,
|
||||
duration: respData.duration,
|
||||
dynamic: respJson.data.dynamic,
|
||||
stat: respData.stat,
|
||||
aid: respData.aid,
|
||||
cid: respData.pages?.[0].cid,
|
||||
return fetch(`${baseVideoInfo}?bvid=${videoId}`)
|
||||
.then(async resp => {
|
||||
const respJson = await resp.json();
|
||||
const respData = respJson.data;
|
||||
return {
|
||||
title: respData.title,
|
||||
desc: respData.desc,
|
||||
duration: respData.duration,
|
||||
dynamic: respJson.data.dynamic,
|
||||
stat: respData.stat,
|
||||
aid: respData.aid,
|
||||
cid: respData.pages?.[0].cid,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
29
utils/bilibili-bv-av-convert.js
Normal file
29
utils/bilibili-bv-av-convert.js
Normal file
@ -0,0 +1,29 @@
|
||||
const table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'
|
||||
const tr = Array.from(table).reduce((o, c, i) => Object.assign(o, { [c]: i }), {})
|
||||
const s = [11, 10, 3, 8, 4, 6]
|
||||
const xor = 177451812
|
||||
const add = 8728348608
|
||||
/** 算法来源:https://www.zhihu.com/question/381784377/answer/1099438784 **/
|
||||
|
||||
/**
|
||||
* Convert a BV string to AV number
|
||||
* @param {string} bv The BV string to be converted to AV number
|
||||
* @returns {number} The AV number converted from the provided BV string
|
||||
*/
|
||||
function bv2AV(bv) {
|
||||
return (new Uint8Array(6).reduce((r, _, i) => r + tr[bv[s[i]]] * 58 ** i, 0) - add) ^ xor
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a AV number to BV string
|
||||
* @param {number} av The AV number to be converted to BV string
|
||||
* @returns {string} The BV string converted from the provided AV number
|
||||
*/
|
||||
function av2BV(av) {
|
||||
return (new Uint8Array(6).reduce((r, _, i) => { r.splice(s[i], 1, table[Math.floor(((av ^ xor) + add) / 58 ** i % 58)]); return r }, Array.from('BV1 4 1 7 '))).join('')
|
||||
}
|
||||
|
||||
export {
|
||||
bv2AV,
|
||||
av2BV
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user