From b06ec4ca964ad081b31d416576d0273400a89303 Mon Sep 17 00:00:00 2001 From: wbt5 Date: Sat, 18 Jul 2020 15:04:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=88=98=E6=97=97=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E5=BC=B9=E5=B9=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- danmu/danmaku/zhanqi.py | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 danmu/danmaku/zhanqi.py 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('