1
0
mirror of https://github.com/wbt5/real-url.git synced 2025-07-28 03:20:31 +08:00

新增映客直播弹幕

This commit is contained in:
wbt5 2020-07-05 09:58:03 +08:00
parent 2f63951d68
commit 527d296c9d

41
danmu/danmaku/inke.py Normal file
View File

@ -0,0 +1,41 @@
import aiohttp
import re
import time
import json
class Inke:
@staticmethod
async def get_ws_info(url):
uid = re.search(r'uid=(\d+)', url).group(1)
roomid = id = re.search(r'&id=(\d+)', url).group(1)
t = int(time.time() * 1e3)
cr = 'https://chatroom.inke.cn/url?roomid={}&uid={}&id={}&access_from=pc_web&_t={}'.format(roomid, uid, id, t)
async with aiohttp.ClientSession() as session:
async with session.get(cr) as resp:
res = await resp.text()
wss_url = json.loads(res).get('url')
return wss_url
@staticmethod
def decode_msg(data):
msgs = []
name = content = ''
msg_type = 'other'
message = json.loads(data)
ms = message['ms']
c = ms[-1].get('c', 0)
if c:
tp = ms[-1].get('tp', 0)
if tp == 'pub' or tp == 'color':
name = ms[0].get('from').get('nic', '')
elif tp == 'user_join_tip':
name = ms[0].get('u').get('nic', '')
else:
name = 'sys'
content = c
msg_type = 'danmaku'
msg = {'name': name, 'content': content, 'msg_type': msg_type}
msgs.append(msg)
return msgs