开放平台客户端添加主播Open ID、修复一个web端解析弹幕消息时的报错

This commit is contained in:
John Smith 2024-03-17 18:39:28 +08:00
parent 8f6d770e18
commit 60ce01927a
3 changed files with 25 additions and 8 deletions

View File

@ -60,6 +60,8 @@ class OpenLiveClient(ws_base.WebSocketClientBase):
# 在调用init_room后初始化的字段 # 在调用init_room后初始化的字段
self._room_owner_uid: Optional[int] = None self._room_owner_uid: Optional[int] = None
"""主播用户ID""" """主播用户ID"""
self._room_owner_open_id: Optional[str] = None
"""主播Open ID"""
self._host_server_url_list: Optional[List[str]] = [] self._host_server_url_list: Optional[List[str]] = []
"""弹幕服务器URL列表""" """弹幕服务器URL列表"""
self._auth_body: Optional[str] = None self._auth_body: Optional[str] = None
@ -78,6 +80,13 @@ class OpenLiveClient(ws_base.WebSocketClientBase):
""" """
return self._room_owner_uid return self._room_owner_uid
@property
def room_owner_open_id(self) -> Optional[str]:
"""
主播Open ID调用init_room后初始化
"""
return self._room_owner_open_id
@property @property
def room_owner_auth_code(self): def room_owner_auth_code(self):
""" """
@ -181,6 +190,7 @@ class OpenLiveClient(ws_base.WebSocketClientBase):
anchor_info = data['anchor_info'] anchor_info = data['anchor_info']
self._room_id = anchor_info['room_id'] self._room_id = anchor_info['room_id']
self._room_owner_uid = anchor_info['uid'] self._room_owner_uid = anchor_info['uid']
self._room_owner_open_id = anchor_info['open_id']
return True return True
async def _end_game(self): async def _end_game(self):

View File

@ -55,7 +55,7 @@ class DanmakuMessage:
return cls( return cls(
uname=data['uname'], uname=data['uname'],
uid=data['uid'], uid=data['uid'],
open_id=data.get('open_id', ''), # 还没全量上线先用get保险 open_id=data['open_id'],
uface=data['uface'], uface=data['uface'],
timestamp=data['timestamp'], timestamp=data['timestamp'],
room_id=data['room_id'], room_id=data['room_id'],
@ -89,7 +89,7 @@ class AnchorInfo:
def from_dict(cls, data: dict): def from_dict(cls, data: dict):
return cls( return cls(
uid=data['uid'], uid=data['uid'],
open_id=data.get('open_id', ''), # 还没全量上线先用get保险 open_id=data['open_id'],
uname=data['uname'], uname=data['uname'],
uface=data['uface'], uface=data['uface'],
) )
@ -178,7 +178,7 @@ class GiftMessage:
return cls( return cls(
room_id=data['room_id'], room_id=data['room_id'],
uid=data['uid'], uid=data['uid'],
open_id=data.get('open_id', ''), # 还没全量上线先用get保险 open_id=data['open_id'],
uname=data['uname'], uname=data['uname'],
uface=data['uface'], uface=data['uface'],
gift_id=data['gift_id'], gift_id=data['gift_id'],
@ -218,7 +218,7 @@ class UserInfo:
def from_dict(cls, data: dict): def from_dict(cls, data: dict):
return cls( return cls(
uid=data['uid'], uid=data['uid'],
open_id=data.get('open_id', ''), # 还没全量上线先用get保险 open_id=data['open_id'],
uname=data['uname'], uname=data['uname'],
uface=data['uface'], uface=data['uface'],
) )
@ -314,7 +314,7 @@ class SuperChatMessage:
return cls( return cls(
room_id=data['room_id'], room_id=data['room_id'],
uid=data['uid'], uid=data['uid'],
open_id=data.get('open_id', ''), # 还没全量上线先用get保险 open_id=data['open_id'],
uname=data['uname'], uname=data['uname'],
uface=data['uface'], uface=data['uface'],
message_id=data['message_id'], message_id=data['message_id'],
@ -392,7 +392,7 @@ class LikeMessage:
return cls( return cls(
uname=data['uname'], uname=data['uname'],
uid=data['uid'], uid=data['uid'],
open_id=data.get('open_id', ''), # 还没全量上线先用get保险 open_id=data['open_id'],
uface=data['uface'], uface=data['uface'],
timestamp=data['timestamp'], timestamp=data['timestamp'],
room_id=data['room_id'], room_id=data['room_id'],

View File

@ -125,6 +125,13 @@ class DanmakuMessage:
mcolor = 0 mcolor = 0
special_medal = 0 special_medal = 0
if len(info[5]) != 0:
old_title = info[5][0]
title = info[5][1]
else:
old_title = ''
title = ''
return cls( return cls(
mode=info[0][1], mode=info[0][1],
font_size=info[0][2], font_size=info[0][2],
@ -161,8 +168,8 @@ class DanmakuMessage:
ulevel_color=info[4][2], ulevel_color=info[4][2],
ulevel_rank=info[4][3], ulevel_rank=info[4][3],
old_title=info[5][0], old_title=old_title,
title=info[5][1], title=title,
privilege_type=info[7], privilege_type=info[7],
) )