Giter VIP home page Giter VIP logo

nonebot_plugin_blive_danmaku's Introduction

NoneBotPluginLogo

NoneBotPluginText

nonebot_plugin_blive_danmaku

💫 B站直播间路灯插件 💫

pypi python license

简介

  • 基于nonebot2开发的B站直播间弹幕监听插件,参考了Haruka和blivechat的部分代码。
  • 起源于哈鹿hallu的一条动态,苦于做视频时没有人做路灯,翻录播的时候头都大了,说要花钱请个全职路灯,我寻思与其把钱送给别人,不如交给Bot去做路灯。
  • 路灯:指把直播过程中有趣的点记录下来,给剪辑根据记录的时间点和内容做出对应的视频。

功能

  • 用弹幕的形式记录直播高能点
  • 弹幕指令为#路灯加上记录的内容
  • 仅在开播时弹幕指令才会生效

依赖

  • Python >= 3.10
  • OneBot V11

安装

  • 方式一:使用nb-cli安装插件
nb plugin install nonebot-plugin-blive-danmaku
  • 方式二:使用pip安装
python -m pip install nonebot-plugin-blive-danmaku

配置

名称 类型 默认值 描述
danmaku_group_notice bool False 全局群开播提醒
danmaku_host str 外部访问地址,若配置了公网访问地址请填写此项,以便bot能够发送正确的面板地址,例如:“http://www.your_domain.com”“http://192.168.0.2"
非80,443端口需要带上端口号,例如:“http://www.your_domain.com:12450”“http://192.168.0.2:12450"

指令

指令 说明
/添加订阅 UID UID为B站用户的uid,不是直播间id,以下同理
/取消订阅 UID 删除订阅
/开启路灯 UID 开启直播间弹幕监听
/关闭路灯 UID 关闭直播间弹幕监听
/订阅列表
/查看面板 打开网页版查询
/开启统计 UID 开启弹幕统计,包含每场直播弹幕数,平均弹幕数,观看人数,每分钟弹幕数。
注:开启后磁盘将增加更多的占用空间,如果磁盘空间不足建议关闭数据统计。
/关闭统计 UID 关闭弹幕统计
/导入cookie 已登录账号的cookie 添加一个cookie,避免弹幕用户名打码

效果预览





反向代理(可选,如果需要配置外部网络访问面板)

这里仅以最简单的配置为例,不包含SSL访问

Nginx

server {
        listen       80;
        server_name  www.your_domain.com;

        location /danmaku/ {
            proxy_pass http://127.0.0.1:8080/danmaku/;
            proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection keep-alive;
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_cache_bypass $http_upgrade;
        }

        location /ws {
            deny all;
        }
    }

Apache

<VirtualHost *:80>
    ServerName  www.your_domain.com
    ProxyRequests Off
    ProxyPass "/danmaku/" http://127.0.0.1:8080/danmaku/
    ProxyPassReverse "/danmaku/" http://127.0.0.1:8080/danmaku/
</VirtualHost>

更新日志

  • v0.4.0
    • 支持添加cookie,避免弹幕用户名打码
  • v0.3.4
    • 添加词云
    • 新增黑暗模式
  • v0.3.3
    • 修复弹幕用户名打码
    • fix #12
  • v0.3.0
    • 适配nonebot2 2.0.0
    • 增加弹幕统计
    • 新增记录SuperChat内容,可在面板生成SuperChat图片
    • 更新依赖 #11
  • v0.2.9
    • 面板查询开播历史列表,标题旁展示该场直播的路灯数量
    • Bot被踢出群后清除该群的订阅
    • fix路灯列表搜索bug
    • Clean Up Code
  • v0.2.8
    • 封面地址不再绑定url,面板地址变更导致封面图片异常的可手动清理 #10
    • 面板添加侧边菜单应对多个订阅的展示
  • v0.2.7
    • 面板支持表情显示
  • v0.2.6
    • 😉 节日快乐
    • 面板稍微添加了一点小小的工作
  • v0.2.5
    • 前端添加条件搜索
  • v0.2.4
    • 移除直播间ws监听多余的输出
    • 更新前端
  • v0.2.0
    • 修复历史bug
    • 添加网页面板,外部访问请自行配置反向代理服务器
  • v0.1.4
    • 添加开播提醒,.env新增全局配置项danmaku_group_notice开关 #3
    • 调整日志级别 #5
  • v0.1.3
    • bot提醒在时间后面加上直播时长显示,避免直播画面没有当前时间的场景
  • v0.1.2
    • fix局部变量无法正常更新的bug
  • v0.1.0
    • 基于nonebot2,实现同步路灯弹幕到qq群

感谢

nonebot_plugin_blive_danmaku's People

Contributors

zangxx66 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nonebot_plugin_blive_danmaku's Issues

运行时出现报错

01-16 00:29:35 [ERROR] nonebot | Error when running startup function. Ignored!
Traceback (most recent call last):
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/tortoise/backends/sqlite/client.py", line 34, in translate_exceptions_
    return await func(self, query, *args)
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/tortoise/backends/sqlite/client.py", line 153, in execute_script
    async with self.acquire_connection() as connection:
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/tortoise/backends/base/client.py", line 220, in __aenter__
    await self.ensure_connection()
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/tortoise/backends/base/client.py", line 216, in ensure_connection
    await self.client.create_connection(with_db=True)
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/tortoise/backends/sqlite/client.py", line 69, in create_connection
    await self._connection._connect()
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/aiosqlite/core.py", line 137, in _connect
    self._connection = await future
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/aiosqlite/core.py", line 102, in run
    result = function()
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/aiosqlite/core.py", line 397, in connector
    return sqlite3.connect(loc, **kwargs)
sqlite3.OperationalError: unable to open database file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 19, in <module>
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/nonebot/__init__.py", line 331, in run
    get_driver().run(*args, **kwargs)
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/nonebot/drivers/none.py", line 56, in run
    loop.run_until_complete(self._serve())
  File "/usr/lib/python3.10/asyncio/base_events.py", line 636, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 603, in run_forever
    self._run_once()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1909, in _run_once
    handle._run()
  File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/nonebot/drivers/none.py", line 60, in _serve
    await self._startup()
> File "/root/livepushfortest/.venv/lib/python3.10/site-packages/nonebot/drivers/none.py", line 68, in _startup
    await self._lifespan.startup()
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/nonebot/internal/driver/_lifespan.py", line 41, in startup
    await self._run_lifespan_func(self._startup_funcs)
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/nonebot/internal/driver/_lifespan.py", line 35, in _run_lifespan_func
    await cast(ASYNC_LIFESPAN_FUNC, func)()
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/nonebot_plugin_blive_danmaku/database/db.py", line 28, in init
    await Tortoise.generate_schemas()  # type:ignore
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/tortoise/__init__.py", line 640, in generate_schemas
    await generate_schema_for_client(connection, safe)
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/tortoise/utils.py", line 31, in generate_schema_for_client
    await generator.generate_from_string(schema)
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/tortoise/backends/base/schema_generator.py", line 448, in generate_from_string
    await self.client.execute_script(creation_string)
  File "/root/livepushfortest/.venv/lib/python3.10/site-packages/tortoise/backends/sqlite/client.py", line 36, in translate_exceptions_
    raise OperationalError(exc)
tortoise.exceptions.OperationalError: unable to open database file

关于域名端口转发的问题

如果自定义端口转发,不用默认的80端口,改用8001,可以成功打开面板,但是所有的封面都获取不到。
我查了一下好像请求封面的url没有指定端口号,这个要怎么设置呢?
image

Bug?:开启路灯后报错 >>>

room=21452505 _handle_command() failed, command={'cmd': 'DANMU_MSG', 'info': [[0, 1, 25, 5816798, 1688413880504, 1688411487, 0, 'd332ad00', 0, 0, 0, '', 0, '{}', '{}', {'mode': 0, 'show_player_type': 0, 'extra': '{"send_from_me":false,"mode":0,"color":5816798,"dm_type":0,"font_size":25,"player_mode":1,"show_player_type":0,"content":"8888","user_hash":"3543313664","emoticon_unique":"","bulge_display":0,"recommend_score":1,"main_state_dm_color":"","objective_state_dm_color":"","direction":0,"pk_direction":0,"quartet_direction":0,"anniversary_crowd":0,"yeah_space_type":"","yeah_space_url":"","jump_to_url":"","space_type":"","space_url":"","animation":{},"emots":null,"is_audited":false,"id_str":"0481be3d673828ceae59ea2da4cd7a3411","icon":null}'}, {'activity_identity': '', 'activity_source': 0, 'not_show': 0}, 0], '8888', [0, '濑***', 0, 0, 0, 10000, 1, ''], [18, '脆鲨', '七海Nana7mi', 21452505, 13081892, '', 0, 13081892, 13081892, 13081892, 0, 1, 434334701], [10, 0, 9868950, '>50000', 0], ['', ''], 0, 0, None, {'ts': 1688413880, 'ct': '11ED4B71'}, 0, 0, None, None, 0, 63, [0]], 'dm_v2': 'CiIwNDgxYmUzZDY3MzgyOGNlYWU1OWVhMmRhNGNkN2EzNDExEAEYGSDeg+MCKghkMzMyYWQwMDIEODg4ODi4gb3qkTFI37qMpQZiAIoBAJoBEAoIMTFFRDRCNzEQuM2MpQaiAZIBEgbmv5EqKioiSmh0dHBzOi8vaTAuaGRzbGIuY29tL2Jmcy9mYWNlL2NiMDY1M2E4N2IxYTNjMGFmZjllYzY0MmJiNjIzNTdkZmZlMTcwNTEuanBnOJBOQAFaIAgSEgbohIbpsqggpLqeBjCkup4GOKS6ngZApLqeBlABYg8IChCWrdoEGgY+NTAwMDBqAHIAegCqARoI7deNzwESDeS4g+a1t05hbmE3bWkY2a2dCg=='}
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot_plugin_blive_danmaku\blivedm\blivedm\handlers.py", line 164, in handle
await callback(self, client, command)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot_plugin_blive_danmaku\command\subscribe\danmaku.py", line 73, in _on_danmaku
await save_danmaku(client.room_id, client.room_owner_uid, message.uname, int(message.timestamp / 1000), message.msg)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot_plugin_blive_danmaku\command\subscribe\danmaku.py", line 138, in save_danmaku
room = room_list[0]
IndexError: list index out of range
error log

使用命令”订阅列表“,提示”错误码: -403, 信息: 访问权限不足“

image

报错代码:
06-23 21:44:38 [INFO] nonebot | Event will be handled by Matcher(type='message', module=nonebot_plugin_blive_danmaku.command.sub.sub_list)
06-23 21:44:39 [INFO] nonebot | Matcher(type='message', module=nonebot_plugin_blive_danmaku.command.sub.sub_list) running complete
06-23 21:44:39 [ERROR] nonebot | Running Matcher(type='message', module=nonebot_plugin_blive_danmaku.command.sub.sub_list) failed.
Traceback (most recent call last):
File "/home/zhenxun_bot/bot.py", line 24, in
nonebot.run()
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/nonebot/init.py", line 309, in run
get_driver().run(*args, **kwargs)
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 198, in run
uvicorn.run(
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/uvicorn/main.py", line 569, in run
server.run()
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/nonebot/message.py", line 467, in check_and_run_matcher
await _run_matcher(

File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/nonebot/message.py", line 419, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 753, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 728, in simple_run
await handler(
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/nonebot/dependencies/init.py", line 108, in call
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/nonebot_plugin_blive_danmaku/command/sub/sub_list.py", line 21, in _
user = await get_user_info(sub.uid, reqtype="web", proxies=None)
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/bilireq/user/init.py", line 12, in get_user_info
return await get(url, params=params, auth=auth, reqtype=reqtype, **kwargs)
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/bilireq/utils/init.py", line 98, in get
return await request("GET", url, **kwargs)
File "/home/poetry-cache/virtualenvs/zhenxun-bot-UH4sDRIh-py3.10/lib/python3.10/site-packages/bilireq/utils/init.py", line 89, in request
raise ResponseCodeError(
bilireq.exceptions.ResponseCodeError: 错误码: -403, 信息: 访问权限不足

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.