mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 23:51:20 -08:00
add bilibiliDanmuParseFromAv
This commit is contained in:
1 parent
d735bb4de7
commit
9bd1452030
4 files changed
+121
-87
No files matched your search
@@ -1,4 +1,4 @@
|
||||
export default function bilibiliDanmuParse(xmlString) {
|
||||
export function bilibiliDanmuParseFromXml(xmlString) {
|
||||
if (typeof xmlString !== 'string') return [];
|
||||
const regSrt = '<d p="(.+)">(.+)</d>';
|
||||
const listReg = new RegExp(regSrt, 'gi');
|
||||
@@ -7,20 +7,36 @@ export default function bilibiliDanmuParse(xmlString) {
|
||||
return srtList.length
|
||||
? srtList.map(item => {
|
||||
const [, attrStr, text] = item.match(itemReg);
|
||||
const attr = attrStr.split(',');
|
||||
const attr = attrStr.split(',').map(Number);
|
||||
return attr.length === 8 && text.trim()
|
||||
? {
|
||||
text,
|
||||
time: Number(attr[0]),
|
||||
mode: Number(attr[1]),
|
||||
size: Number(attr[2]),
|
||||
color: `#${Number(attr[3]).toString(16)}`,
|
||||
timestamp: Number(attr[4]),
|
||||
pool: Number(attr[5]),
|
||||
userID: Number(attr[6]),
|
||||
rowID: Number(attr[7]),
|
||||
time: attr[0],
|
||||
mode: attr[1],
|
||||
size: attr[2],
|
||||
color: `#${attr[3].toString(16)}`,
|
||||
timestamp: attr[4],
|
||||
pool: attr[5],
|
||||
userID: attr[6],
|
||||
rowID: attr[7],
|
||||
}
|
||||
: null;
|
||||
})
|
||||
: [];
|
||||
}
|
||||
|
||||
export function bilibiliDanmuParseFromAv(av) {
|
||||
const corsUrl = 'https://cors-anywhere.herokuapp.com/';
|
||||
return fetch(`${corsUrl}https://api.bilibili.com/x/web-interface/view?aid=${av}`)
|
||||
.then(res => res.json())
|
||||
.then(res => {
|
||||
if (res.code === 0 && res.data && res.data.cid) {
|
||||
return fetch(`${corsUrl}https://api.bilibili.com/x/v1/dm/list.so?oid=${res.data.cid}`)
|
||||
.then(res => res.text())
|
||||
.then(xmlString => {
|
||||
return bilibiliDanmuParseFromXml(xmlString);
|
||||
});
|
||||
}
|
||||
throw new Error(`Unable to get data: ${JSON.stringify(res)}`);
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { bilibiliDanmuParseFromXml, bilibiliDanmuParseFromAv } from './bilibiliDanmuParse';
|
||||
import Danmuku from './danmuku';
|
||||
import bilibiliDanmuParse from './bilibiliDanmuParse';
|
||||
|
||||
function artplayerPluginDanmu(option) {
|
||||
return art => {
|
||||
@@ -15,6 +15,7 @@ function artplayerPluginDanmu(option) {
|
||||
};
|
||||
}
|
||||
|
||||
artplayerPluginDanmu.bilibiliDanmuParse = bilibiliDanmuParse;
|
||||
artplayerPluginDanmu.bilibiliDanmuParseFromXml = bilibiliDanmuParseFromXml;
|
||||
artplayerPluginDanmu.bilibiliDanmuParseFromAv = bilibiliDanmuParseFromAv;
|
||||
window.artplayerPluginDanmu = artplayerPluginDanmu;
|
||||
export default artplayerPluginDanmu;
|
||||
Reference in new issue
Block a user