B 站弹幕解析
By
terrorist
at 2022-06-16 • 0人收藏 • 623人看过
class header{ int packetLen; word headerLen; word version; int opCode; int magicNumber; }
unpack = function(pData){ var ret = ..raw.convert(pData, header()) var packetLen = ..raw.swap(ret.packetLen, "int") var headerLen = ..raw.swap(ret.headerLen, "word") var version = ..raw.swap(ret.version, "word") var opCode = ..raw.swap(ret.opCode, "int") var magicNumber = ..raw.swap(ret.magicNumber, "int") var payloadLen = packetLen - headerLen; if(opCode == 5){ // brotli解压 if(version == 3){ var ptr = ..aaz.libbrotli.decompress3( topointer(pData,16), payloadLen) if(ptr){ unpack(ptr) ..raw.realloc(0, ptr) } } elseif(version == 0){ // 弹幕内容 var str = ..raw.tostring(pData,17,packetLen) ..io.print(str) var tab = ..web.json.parse(str) if(tab.cmd == "DANMU_MSG"){ } } } }
aaz.libbrotli.decompress3 函数
https://github.com/btx638/aaz-aardio/blob/master/aaz/libbrotli/_.aardio
参考:
https://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md
https://github.com/AndrewXiongGe/AndrewXiongGe.github.io/blob/4ae09b21bc7dec7f6c17383fd7cc4d73386273e7/bliveproxy.js
登录后方可回帖