Skip to main content

哔哩哔哩直播间互动工具

Author LICENSE python

特色

  • 基于asyncio,可以满足更加丰富的使用场景
  • 基于bilibili三代协议,支持brotli压缩算法,效率更高
  • 事件钩子部分使用泛型,开发更友好

安装

pip install bilibili-live

使用

首先创建事件处理器类,类需要继承BilibiliLiveEventHandler类,并重写需要监听的事件方法:

from bilibili_live.events import BilibiliLiveEventHandler, Danmu, Event

class MyEventHandler(BilibiliLiveEventHandler):
    def onDanmu(self, event: Event[Danmu]):
        # do something
        ...

具体支持的事件可以参考BilibiliLiveEventHandler类

完成后,创建BilibiliLive对象,并启动监听:

from bilibili_live import BilibiliLive

room_id = 2411716
# 此处房间号为短号,即用户直接可见的房间号
bilibiliLive = BilibiliLive()
bilibiliLive.schedule(MyEventHandler, room_id)
bilibiliLive.start()

需要退出时,可使用stop方法停止:

bilibiliLive.stop()

此时即开启了事件循环。此函数为异步(非阻塞函数)。

本模块基于asyncio设计。start函数为一个包装函数,其中创建了一个线程并包装了协程操作。如需要直接使用asyncio方式操作,可使用start_asyncio函数。

Release files for bilibili-live 0.10.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bilibili-live 0.10.4
File Size Uploaded
bilibili-live-0.10.4.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bilibili-live 0.10.4
File Interpreter ABI Platform
bilibili_live-0.10.4-py3-none-any.whl Python 3 none any Details

Total release size: 33.3 kB

Release files / bilibili-live-0.10.4.tar.gz

Download URL bilibili-live-0.10.4.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7894137e94a3199d592cc061868addeaa8eb869696b60f6e69901f43399e15d4
BLAKE2b-256 checksum
How to use checksums
fbb87531e5f87d3869c08be2d6afa1d4f10051a33a41c8e503e7f6cd4f34030d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.10

Release files / bilibili_live-0.10.4-py3-none-any.whl

Download URL bilibili_live-0.10.4-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f28be96c4cd6d808ad4ec28c4755040f5f859aa50791438cb0c9beadab7a8f49
BLAKE2b-256 checksum
How to use checksums
314cdc9f45296c43fc749ad43d9c14ed8152cade1a095f88836fbd1868b09c99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.10

Release history Release notifications | RSS feed

This release

0.10.4 This release

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page