forked from muqiuhan/blivedm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (32 loc) · 1.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
import asyncio
import random
import blivedm
from sys import argv
class handler(blivedm.BaseHandler):
"弹幕消息的handler, 这里只捕获弹幕消息和醒目的弹幕, 因为我们不需要多余的信息"
# 普通弹幕
async def _on_danmaku(
self, client: blivedm.BLiveClient, message: blivedm.DanmakuMessage
):
print(f"{message.timestamp} | {message.uname} : {message.msg}")
# 醒目弹幕
async def _on_super_chat(
self, client: blivedm.BLiveClient, message: blivedm.SuperChatMessage
):
print(f"[{message.start_time}] | {message.uname} : {message.message}")
async def run():
room_id = argv[1]
# 如果SSL验证失败就把ssl设为False,B站真的有过忘续证书的情况
client = blivedm.BLiveClient(room_id, ssl=False)
client.add_handler(handler())
try:
print(f"-> 目标直播间 {room_id}")
client.start()
await client.join()
finally:
await client.stop_and_close()
async def main():
await run()
if __name__ == "__main__":
asyncio.run(main())