Skip to content

Commit 9bab296

Browse files
committed
fix: 使用jkfujr的群友akagiyui提供的视频正则表达式
1 parent abcd759 commit 9bab296

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/link_parse.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ interface LinkType {
2828
* @returns 替换后的字符串
2929
*/
3030
function parse_little_app(content: string): string {
31-
// 正则匹配完整的 <json> 标签,包括 data 属性和结束符 />
3231
const jsonRegex = /<json\s+data="([^"]+)"\s*\/?>/g;
3332

3433
// 使用 replace 方法直接替换原文
3534
const replacedContent = content.replace(jsonRegex, (match, p1) => {
3635
try {
37-
// 解码 HTML 实体并解析 JSON 数据
3836
const jsonData = JSON.parse(
3937
p1
4038
.replace(/&quot;/g, '"') // 替换 HTML 实体
@@ -43,15 +41,12 @@ function parse_little_app(content: string): string {
4341

4442
// 检查是否包含符合条件的 appid
4543
if (jsonData.meta?.detail_1?.appid === "1109937557") {
46-
// 返回链接替换原来的 <json> 标签
4744
return jsonData.meta.detail_1.qqdocurl || match;
4845
}
4946

50-
// 如果条件不满足,保留原来的 <json> 标签
5147
return match;
5248
} catch (error) {
53-
console.error("Failed to parse JSON:", error);
54-
// 如果解析失败,保留原来的 <json> 标签
49+
logger.error("Failed to parse little app JSON:", error);
5550
return match;
5651
}
5752
});
@@ -68,13 +63,20 @@ function parse_little_app(content: string): string {
6863
function link_type_parser(content: string, config: Config): LinkType[] {
6964
const linkRegex: LinkRegex[] = [];
7065

71-
if (config.bVideoEnable)
66+
if (config.bVideoEnable) {
7267
linkRegex.push({
7368
pattern: config.bVideoFullURL
74-
? /bilibili\.com\/video\/([ab]v[0-9a-zA-Z]+)/gim
75-
: /([ab]v[0-9a-zA-Z]+)/gim,
69+
? /bilibili\.com\/video\/(?<![a-zA-Z0-9])[aA][vV]([0-9]+)/gim
70+
: /((?<![a-zA-Z0-9])[aA][vV]([0-9]+))/gim,
7671
type: "Video",
7772
});
73+
linkRegex.push({
74+
pattern: config.bVideoFullURL
75+
? /bilibili\.com\/video\/(?<![a-zA-Z0-9])[bB][vV](1[0-9A-Za-z]+)/gim
76+
: /((?<![a-zA-Z0-9])[bB][vV](1[0-9A-Za-z]+))/gim,
77+
type: "Video",
78+
});
79+
}
7880

7981
if (config.bLiveEnable)
8082
linkRegex.push({
@@ -164,7 +166,7 @@ function link_type_parser(content: string, config: Config): LinkType[] {
164166
}
165167

166168
let sanitizedContent: string = content;
167-
sanitizedContent = parse_little_app(sanitizedContent)
169+
sanitizedContent = parse_little_app(sanitizedContent);
168170
sanitizedContent = sanitizedContent.replace(/<[^>]+>/g, "");
169171
logger.debug("Sanitized message: ", sanitizedContent);
170172

0 commit comments

Comments
 (0)