From 217768bd3acaa6e146eaffb3825080b46dcfd3fc Mon Sep 17 00:00:00 2001 From: the1812 Date: Mon, 7 Jan 2019 14:11:38 +0800 Subject: [PATCH] Add ass danmaku --- video/danmaku/danmaku.js | 49 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/video/danmaku/danmaku.js b/video/danmaku/danmaku.js index 750002dfa..f3019a0f5 100644 --- a/video/danmaku/danmaku.js +++ b/video/danmaku/danmaku.js @@ -2,13 +2,39 @@ { return (settings, resources) => { - class XmlDanmaku + class Danmaku { - constructor(element) + constructor(content, time, type, fontSize, color) { - this.pData = element.getAttribute("p"); - [this.time, this.type, this.fontSize, this.color] = this.pData.split(","); - this.content = element.innerText; + this.content = content; + this.time = time; + this.type = type; + this.fontSize = fontSize; + this.color = color; + } + } + class XmlDanmaku extends Danmaku + { + constructor({ content, time, type, fontSize, color, timeStamp, pool, userHash, rowId }) + { + super(content, time, type, fontSize, color); + this.timeStamp = timeStamp; + this.pool = pool; + this.userHash = userHash; + this.rowId = rowId; + this.pDataArray = [time, type, fontSize, color, timeStamp, pool, userHash, rowId]; + } + text() + { + const pData = this.pDataArray.join(","); + return `${this.content}`; + } + static parse(element) + { + const pData = element.getAttribute("p"); + [time, type, fontSize, color, timeStamp, pool, userHash, rowId] = pData.split(","); + const content = element.innerText; + return new XmlDanmaku({ content, time, type, fontSize, color, timeStamp, pool, userHash, rowId }); } } class XmlDanmakuDocument @@ -20,5 +46,18 @@ this.danmakus = [...document.querySelectorAll("d[p]")].map(it => new XmlDanmaku(it)); } } + class AssDanmaku extends Danmaku + { + constructor({ content, time, type, fontSize, color, typeTag, endTime }) + { + super(content, time, type, fontSize, color); + this.typeTag = typeTag; + this.endTime = endTime; + } + text(fontStyles) + { + return `Dialogue: ${this.time}, ${this.endTime}, ${fontStyles[this.fontSize]}, {${this.typeTag}\\c&H${this.color}&}${this.content}`; + } + } }; })(); \ No newline at end of file