mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-29 19:41:25 -08:00
修改匹配 XML 弹幕的正则表达式
This commit is contained in:
1 parent
edfc95e4c3
commit
19061122b2
1 file changed
+15
-10
@@ -14,13 +14,17 @@ export function getMode(key) {
|
|||||||
|
|
||||||
export function bilibiliDanmuParseFromXml(xmlString) {
|
export function bilibiliDanmuParseFromXml(xmlString) {
|
||||||
if (typeof xmlString !== 'string') return [];
|
if (typeof xmlString !== 'string') return [];
|
||||||
const srtList = xmlString.match(/<d([\S ]*?>[\S ]*?)<\/d>/gi);
|
const matches = xmlString.matchAll(/<d (?:.*? )??p="(?<p>.+?)"(?: .*?)?>(?<text>.+?)<\/d>/gs);
|
||||||
return srtList && srtList.length
|
return Array.from(matches).map(match => {
|
||||||
? srtList.map((item) => {
|
const attr = match.groups.p.split(',');
|
||||||
const [, attrStr, text] = item.match(/<d p="(.+)">(.+)<\/d>/);
|
if (attr.length === 8) {
|
||||||
const attr = attrStr.split(',');
|
const text = match.groups.text.trim()
|
||||||
return attr.length === 8 && text.trim()
|
.replaceAll('"', '\"')
|
||||||
? {
|
.replaceAll(''', '\'')
|
||||||
|
.replaceAll('<', '<')
|
||||||
|
.replaceAll('>', '>')
|
||||||
|
.replaceAll('&', '&');
|
||||||
|
return {
|
||||||
text,
|
text,
|
||||||
time: Number(attr[0]),
|
time: Number(attr[0]),
|
||||||
mode: getMode(Number(attr[1])),
|
mode: getMode(Number(attr[1])),
|
||||||
@@ -31,9 +35,10 @@ export function bilibiliDanmuParseFromXml(xmlString) {
|
|||||||
userID: attr[6],
|
userID: attr[6],
|
||||||
rowID: Number(attr[7]),
|
rowID: Number(attr[7]),
|
||||||
}
|
}
|
||||||
: null;
|
} else {
|
||||||
})
|
return null;
|
||||||
: [];
|
}
|
||||||
|
}).filter(d => d);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bilibiliDanmuParseFromUrl(url) {
|
export function bilibiliDanmuParseFromUrl(url) {
|
||||||
|
|||||||
Reference in new issue
Block a user