xfgryujk / blivedm Goto Github PK
View Code? Open in Web Editor NEW获取bilibili直播弹幕,使用WebSocket协议,支持web端和B站直播开放平台两种接口
License: MIT License
获取bilibili直播弹幕,使用WebSocket协议,支持web端和B站直播开放平台两种接口
License: MIT License
在使用了重构后的代码后发现,每秒处理新消息时都新建了一个线程,并所有线程都没有关闭。这就导致了并发情况下会使得线程使用量大量上升,运行久了甚至会使服务器线程占满
经过几天的使用,发现通过ws发送过来的消息可能发生了变化。比如,用户进入直播间已经无法捕捉到WELCOME
命令,转而成为了INTERACT_WORD
。
而原先当直播间关注人数发生变化时,会产生ROOM_REAL_TIME_MESSAGE_UPDATE
,现在已经无法接收到该命令(但是在网页端与手机app端,仍然可以观察到xxx关注了直播间这样的消息),所以包数据的解析可能存在遗漏。
这个仓库的代码真的帮助到我了,希望能够持续更新,感谢您的开源
class 'ssl.SSLError'> [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
这个很诡异 因为电脑上的chrome正常使用 但是脚本运行就ssl错误,试了好几个电脑了
看着值好像变长了,阿b又改了
https://github.com/yjqiang/danmu
这份代码是 fork 自本项目,但我最近有计划将其打包至 pypi。
license 显示为你的名字我还没改,但是你可以看到基本上这份代码与你的代码没有什么关系了,如果不修改 license 应该很奇怪吧,pypi 里面作者是我, 许可名字却是你。
所以想问一下,如果我打包的话,可否把版权时间 Copyright (c) 2018 xfgryujk 这里,fork你的时间之前,代码版权归你,之后到现在,版权归我。
配置SESSDATA后报错:
room=4395168 _init_buvid() status error, status=403, reason=Forbidden
room=4395168 _init_buvid() failed
最小复现如下:
self._init_danmaku_session(userdata[9])
self.StartDanmakuMonitorSignal.emit(int(userdata[3])) # userdata[3] 为room_id 的 str
def _init_danmaku_session(self, sessdata):
try:
cookies = http.cookies.SimpleCookie()
cookies["SESSDATA"] = sessdata
cookies["SESSDATA"]["domain"] = "bilibili.com"
self.BliveSession = aiohttp.ClientSession()
self.BliveSession.cookie_jar.update_cookies(cookies)
except Exception as e:
self.Models.TheSeedLogger.error(f'初始化直播弹幕Session失败: {e}')
@qasync.asyncSlot(int)
async def _start_danmaku_monitor(self, room_id):
try:
self.DanmakuClient = blivedm.BLiveClient(room_id, session=self.BliveSession)
self.DanmakuProcessor = BliveDanmakuMsgProcessor()
self.DanmakuClient.set_handler(self.DanmakuProcessor)
self.DanmakuClient.start()
await asyncio.create_task(self.DanmakuClient.join())
except Exception as e:
self.Models.TheSeedLogger.error(f'启动直播弹幕监控失败: {e}')
具体配置:
Python 版本 3.10
Windows10
IDE:Pycharm
BliveDanmakuMsgProcessor为继承了BaseHandler的对象
具体启动流程:
程序启动前用qasync将事件循环绑定到Qt的主线程上
在PySide6中点击按钮后通过qasync的异步信号触发_start_danmaku_monitor
具体表现:
报错后依旧可以打印弹幕和用户名以及uid
动因:
继 #57 错误思路重开
很多要重写
大佬能否推荐一些书籍或者一些项目视频之类的,想写出这种优雅的工程级项目应该往哪个方向学习呢😭😭😭
您好,sample.py获取不到点赞数量呢,{"contribution_info": {"grade": 0}, "dmscore": 32, "fans_medal": {"anchor_roomid": 0, "guard_level": 0, "icon_id": 0, "is_lighted": 0, "medal_color": 0, "medal_color_border": 0, "medal_color_end": 0, "medal_color_start": 0, "medal_level": 0, "medal_name": "", "score": 0, "special": "", "target_id": 0}, "group_medal": null, "identities": [1], "is_mystery": false, "like_icon": "https://i0.hdslb.com/bfs/live/23678e3d90402bea6a65251b3e728044c21b1f0f.png", "like_text": "\u4e3a\u4e3b\u64ad\u70b9\u8d5e\u4e86", "msg_type": 6, "show_area": 0, "uid": 514456342, "uinfo": {"base": {"face": "https://i0.hdslb.com/bfs/face/8c8feab3c2b8ee2a7d298be98d295d36586c84a2.jpg", "is_mystery": false, "name": "bili_181425436453", "name_color": 0, "name_color_str": "", "official_info": {"desc": "", "role": 0, "title": "", "type": -1}, "origin_info": {"face": "https://i0.hdslb.com/bfs/face/8c8feab3c2b8ee2a7d298be98d295d36586c84a2.jpg", "name": "bili_181425436453"}, "risk_ctrl_info": null}, "guard": {"expired_str": "", "level": 0}, "guard_leader": null, "medal": null, "title": null, "uhead_frame": null, "uid": 514456342, "wealth": null}, "uname": "bili_181425436453", "uname_color": ""}
从来没收到过,一直都是USER_TOAST_MSG
最近有一些不兼容的弹幕消息报错,暂时没空研究,先记一下
{'cmd': 'DANMU_MSG:3:7:1:1:1:1', 'info': [
[0, 7, 100, 16777215, 1701789809186, 0, 0, 'f4dbdf21', 0, None, None, None, 0, '{}', '{}', {'mode': 0, 'show_player_type': 0, 'extra': '{"mode":0,"send_from_me":false,"color":16777215,"dm_type":0,"font_size":100,"player_mode":7,"content":"[1.0,0.0,\\"0.8-0.5\\",10.0,\\"辛苦了\\",0.0,0.0,0.0,0.0,10000,0,true,\\"黑体\\",1]"}'}, None, None],
'[1.0,0.0,"0.8-0.5",10.0,"辛苦了",0.0,0.0,0.0,0.0,10000,0,true,"黑体",1]', [0, '***', 1, 0, 0, 10000, 1, ''], None, [], [], 0, 0, None, {'ts': 1701789809, 'ct': '8DB3B1FF'}, 0, 0, None, None, 0, 0, [0]
], 'dm_v2': ''}
{'cmd': 'DANMU_MSG:3:7:1:1:1:1', 'info': [
[0, 7, 100, 16777215, 1701789899411, 0, 0, 'f4dbdf21', 0, None, None, None, 0, '{}', '{}', {'mode': 0, 'show_player_type': 0, 'extra': '{"mode":0,"send_from_me":false,"color":16777215,"dm_type":0,"font_size":100,"player_mode":7,"content":"[1.0,0.0,\\"0.8-0.5\\",10.0,\\"晚安\\",0.0,0.0,0.0,0.0,10000,0,true,\\"黑体\\",1]"}'}, None, None],
'[1.0,0.0,"0.8-0.5",10.0,"晚安",0.0,0.0,0.0,0.0,10000,0,true,"黑体",1]', [0, '***', 1, 0, 0, 10000, 1, ''], None, [], [], 0, 0, None, {'ts': 1701789899, 'ct': '8045F9DF'}, 0, 0, None, None, 0, 0, [0]
], 'dm_v2': ''}
{'cmd': 'DANMU_MSG:3:7:1:1:1:1', 'info': [
[0, 7, 100, 16777215, 1701866650320, 0, 0, 'f4dbdf21', 0, None, None, None, 0, '{}', '{}', {'mode': 0, 'show_player_type': 0, 'extra': '{"mode":0,"send_from_me":false,"color":16777215,"dm_type":0,"font_size":100,"player_mode":7,"content":"[1.0,0.0,\\"0.8-0.5\\",10.0,\\"了不起\\",0.0,0.0,0.0,0.0,10000,0,true,\\"黑体\\",1]"}'}, None, None],
'[1.0,0.0,"0.8-0.5",10.0,"了不起",0.0,0.0,0.0,0.0,10000,0,true,"黑体",1]', [0, '***', 1, 0, 0, 10000, 1, ''], None, [], [], 0, 0, None, {'ts': 1701866650, 'ct': '6AA2F39E'}, 0, 0, None, None, 0, 0, [0]
], 'dm_v2': ''}
我在尝试连接他人直播间的时候有bilibili返回报错白名单限制,请问这个限制的机制是什么样的,blivechat连接其他主播似乎也没有被限制?
python 3.8 ubuntu 20.04 直播间弹幕无肉眼可见异常
await self._ws.send_bytes(packman.pack(heartbeat(), Operation.HEARTBEAT))
File "/usr/local/lib/python3.8/dist-packages/aiohttp/client_ws.py", line 156, in send_bytes
await self._writer.send(data, binary=True, compress=compress)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/http_websocket.py", line 688, in send
await self._send_frame(message, WSMsgType.BINARY, compress)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/http_websocket.py", line 601, in _send_frame
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
Job "BLiver.heartbeat (trigger: interval[0:00:30], next run at: 2022-02-18 00:14:06 CST)" raised an exception
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "/usr/local/lib/python3.8/dist-packages/blive/framework.py", line 147, in heartbeat
await self._ws.send_bytes(packman.pack(heartbeat(), Operation.HEARTBEAT))
File "/usr/local/lib/python3.8/dist-packages/aiohttp/client_ws.py", line 156, in send_bytes
await self._writer.send(data, binary=True, compress=compress)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/http_websocket.py", line 688, in send
await self._send_frame(message, WSMsgType.BINARY, compress)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/http_websocket.py", line 601, in _send_frame
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
Job "BLiver.heartbeat (trigger: interval[0:00:30], next run at: 2022-02-18 00:14:36 CST)" raised an exception
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "/usr/local/lib/python3.8/dist-packages/blive/framework.py", line 147, in heartbeat
await self._ws.send_bytes(packman.pack(heartbeat(), Operation.HEARTBEAT))
File "/usr/local/lib/python3.8/dist-packages/aiohttp/client_ws.py", line 156, in send_bytes
await self._writer.send(data, binary=True, compress=compress)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/http_websocket.py", line 688, in send
await self._send_frame(message, WSMsgType.BINARY, compress)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/http_websocket.py", line 601, in _send_frame
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
Job "BLiver.heartbeat (trigger: interval[0:00:30], next run at: 2022-02-18 00:15:06 CST)" raised an exception
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "/usr/local/lib/python3.8/dist-packages/blive/framework.py", line 147, in heartbeat
await self._ws.send_bytes(packman.pack(heartbeat(), Operation.HEARTBEAT))
File "/usr/local/lib/python3.8/dist-packages/aiohttp/client_ws.py", line 156, in send_bytes
await self._writer.send(data, binary=True, compress=compress)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/http_websocket.py", line 688, in send
await self._send_frame(message, WSMsgType.BINARY, compress)
File "/usr/local/lib/python3.8/dist-packages/aiohttp/http_websocket.py", line 601, in _send_frame
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
^CTraceback (most recent call last):
File "main.py", line 44, in <module>
app.run()
File "/usr/local/lib/python3.8/dist-packages/blive/framework.py", line 176, in run
loop.run_forever()
File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
self._run_once()
File "/usr/lib/python3.8/asyncio/base_events.py", line 1823, in _run_once
event_list = self._selector.select(timeout)
File "/usr/lib/python3.8/selectors.py", line 468, in select
fd_event_list = self._selector.poll(timeout, max_ev)
为什么捕抓不了INTERACT_WORD进入直播间和LIVE_OPEN_PLATFORM_LIKE点赞的事件,直播弹幕、礼物这些都可以获取的,是不是事件名称不对,
进入直播间:
`
_CMD_CALLBACK_DICT = blivedm.BaseHandler._CMD_CALLBACK_DICT.copy()
def __interact_word_callback(self, client: blivedm.BLiveClient, command: dict):
print(f"[{client.room_id}] INTERACT_WORD: self_type={type(self).__name__}, room_id={client.room_id},"
f" uname={command['data']['uname']}")
_CMD_CALLBACK_DICT['INTERACT_WORD'] = __interact_word_callback # noqa`
点赞:
def _on_open_live_like(self, client: blivedm.OpenLiveClient, message: open_models.LikeMessage): print(f'[{message.room_id}] {message.uname} 点赞')
如题,DanmakuMessage没看到到相关的东西
你好,请问一下报这个错误是什么回事啊?win10,python3.10
B站最近更新了隐私政策,直播监听5分钟左右,会提示‘为保护用户隐私,未注册登陆用户将无法查看他人昵称’,所有用户UID都为0了,大佬能解决一下吗?
room_id=24697117 unknown cmd=LOG_IN_NOTICE, command={'cmd': 'LOG_IN_NOTICE', 'data': {'notice_msg': '为保护用户隐私,未注册登陆用户将无法查看他人昵称', 'image_web': 'http://i0.hdslb.com/bfs/dm/75e7c16b99208df259fe0a93354fd3440cbab412.png', 'image_app': ''}}
忽略ssl证书是一种不安全的行为,所以还不如抛弃ssl,使用2244接口
请教一下,获取弹幕的时候无法拿到用户头像,这个有解决方法吗
非常感谢此项目带来的帮助。我在本项目基础上,得以做了很多事情。现在我把websocket封装了起来。但是不太想单独做一个项目了。所以就考虑重新反馈到你这里。所以想问一下你这里还更新么
2024-03-21 10:56:57 - e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\blivedm\clients\open_live.py[line:172] - ERROR: _start_game() failed:
Traceback (most recent call last):
File "e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\blivedm\clients\open_live.py", line 157, in _start_game
async with self._request_open_live(
File "e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\aiohttp\client.py", line 1167, in __aenter__
self._resp = await self._coro
File "e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\aiohttp\client.py", line 493, in _request
with timer:
File "e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\aiohttp\helpers.py", line 725, in __exit__
raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError
2024-03-21 10:56:57 - e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\blivedm\clients\ws_base.py[line:248] - ERROR: room=None _network_coroutine() finished with exception:
Traceback (most recent call last):
File "e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\blivedm\clients\ws_base.py", line 243, in _network_coroutine_wrapper
await self._network_coroutine()
File "e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\blivedm\clients\ws_base.py", line 264, in _network_coroutine
await self._on_before_ws_connect(retry_count)
File "e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\blivedm\clients\open_live.py", line 271, in _on_before_ws_connect
await super()._on_before_ws_connect(retry_count)
File "e:\GitHub_pro\AI-Vtuber\Miniconda3\lib\site-packages\blivedm\clients\ws_base.py", line 306, in _on_before_ws_connect
raise InitError('init_room() failed')
blivedm.clients.ws_base.InitError: init_room() failed
环境:Python 3.11.4
Python 3.12 无法安装 aiohttp
,官方已经发布 3.9.0 版本修复此问题,需要更新 requirements.txt
:
aiohttp==3.8.6
↓
aiohttp==3.9.0
详见:
如题,目前在poetry添加 blivedm 作为依赖,
poetry add git+ssh://[email protected]:xfgryujk/blivedm.git
会报错:
Error output:
Traceback (most recent call last):
File "<string>", line 9, in <module>
File "C:\Users\NEKO_P~1\AppData\Local\Temp\tmpv00wl79a\.venv\Lib\site-packages\build\__init__.py", line 199, in from_isolated_env
return cls(
^^^^
File "C:\Users\NEKO_P~1\AppData\Local\Temp\tmpv00wl79a\.venv\Lib\site-packages\build\__init__.py", line 174, in __init__
_validate_source_directory(source_dir)
File "C:\Users\NEKO_P~1\AppData\Local\Temp\tmpv00wl79a\.venv\Lib\site-packages\build\__init__.py", line 77, in _validate_source_directory
raise BuildException(msg)
build._exceptions.BuildException: Source C:/Users/neko_poly000/AppData/Local/pypoetry/Cache/virtualenvs/blive-qq-forward--M0WCSHV-py3.12/src/blivedm does not appear to be a Python project: no pyproject.toml or setup.py
PC网页直接看直播卡,但是如果获取直播源然后用播放器打开就不卡,问题这样不支持弹幕,blivedm可以显示弹幕,问题是blivedm可以发送弹幕吗?
前几天B站抽风以后,刚开始获取弹幕的时候能正常显示用户名,过一段时间就变成第一个字+***,类似下图。大佬能修复下吗,求求了
!
无标题
https://github.com/lkeme/BiliHelper/pull/49/files
目前听闻b站直播的弹幕协议启用了2.0,我粗略看了一下,在这里讨论了一些。
几乎无法接收到新弹幕,换了多个IP和携带ClientSession登陆态也无法解决。
版本 28645d5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.