修改匹配 XML 弹幕的正则表达式

This commit is contained in:
Harvey committed 2022-06-08 16:22:27 +08:00
1 parent 19061122b2
commit 530448c3b4
4 files changed
+49 -42

No files matched your search

@@ -15,30 +15,34 @@ export function getMode(key) {
export function bilibiliDanmuParseFromXml(xmlString) {
if (typeof xmlString !== 'string') return [];
const matches = xmlString.matchAll(/<d (?:.*? )??p="(?<p>.+?)"(?: .*?)?>(?<text>.+?)<\/d>/gs);
return Array.from(matches).map(match => {
const attr = match.groups.p.split(',');
if (attr.length === 8) {
const text = match.groups.text.trim()
.replaceAll('&quot;', '\"')
.replaceAll('&apos;', '\'')
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&amp;', '&');
return {
text,
time: Number(attr[0]),
mode: getMode(Number(attr[1])),
fontSize: Number(attr[2]),
color: `#${Number(attr[3]).toString(16)}`,
timestamp: Number(attr[4]),
pool: Number(attr[5]),
userID: attr[6],
rowID: Number(attr[7]),
return Array.from(matches)
.map((match) => {
const attr = match.groups.p.split(',');
if (attr.length === 8) {
const text = match.groups.text
.trim()
.replaceAll('&quot;', '"')
.replaceAll('&apos;', "'")
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&amp;', '&');
return {
text,
time: Number(attr[0]),
mode: getMode(Number(attr[1])),
fontSize: Number(attr[2]),
color: `#${Number(attr[3]).toString(16)}`,
timestamp: Number(attr[4]),
pool: Number(attr[5]),
userID: attr[6],
rowID: Number(attr[7]),
};
} else {
return null;
}
} else {
return null;
}
}).filter(d => d);
})
.filter((d) => d);
}
export function bilibiliDanmuParseFromUrl(url) {