feat: websocket消息
This commit is contained in:
29
liveMan.py
29
liveMan.py
@@ -38,7 +38,7 @@ async def send_message(message):
|
||||
await websocket.send(message) # 发送消息到 WebSocket 服务器
|
||||
print(f"已发送消息: {message}")
|
||||
|
||||
asyncio.run(send_message(f"【进场msg】111 进入了直播间"))
|
||||
# asyncio.run(send_message(f"【进场msg】111 进入了直播间"))
|
||||
|
||||
|
||||
@contextmanager
|
||||
@@ -313,6 +313,8 @@ class DouyinLiveWebFetcher:
|
||||
user_id = message.user.id
|
||||
content = message.content
|
||||
print(f"【聊天msg】[{user_id}]{user_name}: {content}")
|
||||
asyncio.run(send_message(f"【聊天msg】[{user_id}]{user_name}: {content}"))
|
||||
|
||||
|
||||
def _parseGiftMsg(self, payload):
|
||||
"""礼物消息"""
|
||||
@@ -321,6 +323,7 @@ class DouyinLiveWebFetcher:
|
||||
gift_name = message.gift.name
|
||||
gift_cnt = message.combo_count
|
||||
print(f"【礼物msg】{user_name} 送出了 {gift_name}x{gift_cnt}")
|
||||
asyncio.run(send_message(f"【礼物msg】{user_name} 送出了 {gift_name}x{gift_cnt}"))
|
||||
|
||||
def _parseLikeMsg(self, payload):
|
||||
'''点赞消息'''
|
||||
@@ -328,6 +331,8 @@ class DouyinLiveWebFetcher:
|
||||
user_name = message.user.nick_name
|
||||
count = message.count
|
||||
print(f"【点赞msg】{user_name} 点了{count}个赞")
|
||||
asyncio.run(send_message(f"【点赞msg】{user_name} 点了{count}个赞"))
|
||||
|
||||
|
||||
async def _parseMemberMsg(self, payload):
|
||||
'''进入直播间消息'''
|
||||
@@ -336,11 +341,6 @@ class DouyinLiveWebFetcher:
|
||||
user_id = message.user.id
|
||||
gender = ["女", "男"][message.user.gender]
|
||||
print(f"【进场msg】[{user_id}][{gender}]{user_name} 进入了直播间")
|
||||
# asyncio.create_task(broadcast_message(f"【进场msg】[{user_id}][{gender}]{user_name} 进入了直播间"))
|
||||
# asyncio.run(send_message('123'))
|
||||
# 调用函数发送消息
|
||||
# await asyncio.to_thread(connect_and_send_message, 'test')
|
||||
# await broadcast_message(f"【进场msg】[{user_id}][{gender}]{user_name} 进入了直播间")
|
||||
asyncio.run(send_message(f"【进场msg】[{user_id}][{gender}]{user_name} 进入了直播间"))
|
||||
|
||||
def _parseSocialMsg(self, payload):
|
||||
@@ -349,6 +349,8 @@ class DouyinLiveWebFetcher:
|
||||
user_name = message.user.nick_name
|
||||
user_id = message.user.id
|
||||
print(f"【关注msg】[{user_id}]{user_name} 关注了主播")
|
||||
asyncio.run(send_message(f"【关注msg】[{user_id}]{user_name} 关注了主播"))
|
||||
|
||||
|
||||
def _parseRoomUserSeqMsg(self, payload):
|
||||
'''直播间统计'''
|
||||
@@ -356,12 +358,16 @@ class DouyinLiveWebFetcher:
|
||||
current = message.total
|
||||
total = message.total_pv_for_anchor
|
||||
print(f"【统计msg】当前观看人数: {current}, 累计观看人数: {total}")
|
||||
asyncio.run(send_message(f"【统计msg】当前观看人数: {current}, 累计观看人数: {total}"))
|
||||
|
||||
|
||||
def _parseFansclubMsg(self, payload):
|
||||
'''粉丝团消息'''
|
||||
message = FansclubMessage().parse(payload)
|
||||
content = message.content
|
||||
print(f"【粉丝团msg】 {content}")
|
||||
asyncio.run(send_message(f"【粉丝团msg】 {content}"))
|
||||
|
||||
|
||||
def _parseEmojiChatMsg(self, payload):
|
||||
'''聊天表情包消息'''
|
||||
@@ -371,22 +377,30 @@ class DouyinLiveWebFetcher:
|
||||
common = message.common
|
||||
default_content = message.default_content
|
||||
print(f"【聊天表情包id】 {emoji_id},user:{user},common:{common},default_content:{default_content}")
|
||||
asyncio.run(send_message(f"【聊天表情包id】 {emoji_id},user:{user},common:{common},default_content:{default_content}"))
|
||||
|
||||
|
||||
def _parseRoomMsg(self, payload):
|
||||
message = RoomMessage().parse(payload)
|
||||
common = message.common
|
||||
room_id = common.room_id
|
||||
print(f"【直播间msg】直播间id:{room_id}")
|
||||
asyncio.run(send_message(f"【直播间msg】直播间id:{room_id}"))
|
||||
|
||||
|
||||
def _parseRoomStatsMsg(self, payload):
|
||||
message = RoomStatsMessage().parse(payload)
|
||||
display_long = message.display_long
|
||||
print(f"【直播间统计msg】{display_long}")
|
||||
asyncio.run(send_message(f"【直播间统计msg】{display_long}"))
|
||||
|
||||
|
||||
def _parseRankMsg(self, payload):
|
||||
message = RoomRankMessage().parse(payload)
|
||||
ranks_list = message.ranks_list
|
||||
print(f"【直播间排行榜msg】{ranks_list}")
|
||||
asyncio.run(send_message(f"【直播间排行榜msg】{ranks_list}"))
|
||||
|
||||
|
||||
def _parseControlMsg(self, payload):
|
||||
'''直播间状态消息'''
|
||||
@@ -394,9 +408,12 @@ class DouyinLiveWebFetcher:
|
||||
|
||||
if message.status == 3:
|
||||
print("直播间已结束")
|
||||
asyncio.run(send_message(f"直播间已结束"))
|
||||
self.stop()
|
||||
|
||||
def _parseRoomStreamAdaptationMsg(self, payload):
|
||||
message = RoomStreamAdaptationMessage().parse(payload)
|
||||
adaptationType = message.adaptation_type
|
||||
print(f'直播间adaptation: {adaptationType}')
|
||||
asyncio.run(send_message(f'直播间adaptation: {adaptationType}'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user