mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-27 01:21:20 -08:00
修改匹配 XML 弹幕的正则表达式
This commit is contained in:
1 parent
19061122b2
commit
530448c3b4
4 files changed
+49
-42
No files matched your search
@@ -180,7 +180,7 @@ function artplayerPluginDanmuku(option) {
|
||||
exports.default = artplayerPluginDanmuku;
|
||||
artplayerPluginDanmuku.env = "development";
|
||||
artplayerPluginDanmuku.version = "4.4.6";
|
||||
artplayerPluginDanmuku.build = "1654653489776";
|
||||
artplayerPluginDanmuku.build = "1654676426448";
|
||||
if (typeof window !== 'undefined') window['artplayerPluginDanmuku'] = artplayerPluginDanmuku;
|
||||
|
||||
},{"./danmuku":"igPca","./setting":"8npWO","@parcel/transformer-js/src/esmodule-helpers.js":"8MjWm"}],"igPca":[function(require,module,exports) {
|
||||
@@ -635,22 +635,25 @@ function getMode(key) {
|
||||
}
|
||||
function bilibiliDanmuParseFromXml(xmlString) {
|
||||
if (typeof xmlString !== 'string') return [];
|
||||
const srtList = xmlString.match(/<d([\S ]*?>[\S ]*?)<\/d>/gi);
|
||||
return srtList && srtList.length ? srtList.map((item)=>{
|
||||
const [, attrStr, text] = item.match(/<d p="(.+)">(.+)<\/d>/);
|
||||
const attr = attrStr.split(',');
|
||||
return attr.length === 8 && text.trim() ? {
|
||||
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])
|
||||
} : null;
|
||||
}) : [];
|
||||
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('"', '"').replaceAll(''', "'").replaceAll('<', '<').replaceAll('>', '>').replaceAll('&', '&');
|
||||
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;
|
||||
}).filter((d)=>d
|
||||
);
|
||||
}
|
||||
function bilibiliDanmuParseFromUrl(url) {
|
||||
return fetch(url).then((res)=>res.text()
|
||||
|
||||
Reference in new issue
Block a user