diff --git a/danmu/danmaku/zhanqi.py b/danmu/danmaku/zhanqi.py new file mode 100644 index 0000000..6f7487b --- /dev/null +++ b/danmu/danmaku/zhanqi.py @@ -0,0 +1,63 @@ +import json +import struct +import aiohttp + + +class ZhanQi: + heartbeat = b'\xbb\xcc\x00\x00\x00\x00\x15\x00\x00\x00\x10\'{"cmdid": "keeplive"}' + wss_url = 'wss://gw.zhanqi.tv/' + heartbeatInterval = 30 + + @staticmethod + async def get_ws_info(url): + reg_datas = [] + rid = url.split('/')[-1] + async with aiohttp.ClientSession() as session: + async with session.get('https://m.zhanqi.tv/api/static/v2.1/room/domain/{}.json'.format(rid)) as resp: + info = json.loads(await resp.text()) + roomid = info['data']['id'] + async with session.get('https://m.zhanqi.tv/api/public/room.viewer') as resp2: + res = json.loads(await resp2.text()) + gid = res['data']['gid'] + sid = res['data']['sid'] + timestamp = res['data']['timestamp'] + + login = { + 'cmdid': 'loginreq', + 'roomid': int(roomid), + 'chatroomid': 0, + 'gid': gid, + 'sid': sid, + 't': 0, + 'r': 0, + 'device': 1, + 'fhost': 'mzhanqi', + 'uid': 0, + 'timestamp': timestamp + } + body = json.dumps(login, separators=(',', ':')) + head = struct.pack('