Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/4t145/bilive-danmaku
b站直播api,将bilibili直播间的wss连接转化成事件(弹幕,礼物,sc之类),多runtime
https://github.com/4t145/bilive-danmaku
bilibili bilibili-api bilibili-live rudanmaku rust tokio typescript wasm
Last synced: about 1 month ago
JSON representation
b站直播api,将bilibili直播间的wss连接转化成事件(弹幕,礼物,sc之类),多runtime
- Host: GitHub
- URL: https://github.com/4t145/bilive-danmaku
- Owner: 4t145
- License: apache-2.0
- Created: 2022-05-22T08:31:12.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-31T10:08:13.000Z (about 1 year ago)
- Last Synced: 2024-10-28T11:57:45.953Z (about 2 months ago)
- Topics: bilibili, bilibili-api, bilibili-live, rudanmaku, rust, tokio, typescript, wasm
- Language: Rust
- Homepage:
- Size: 110 KB
- Stars: 22
- Watchers: 1
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-bilibili-extra - Bilive-danmaku - b 站直播 api,将 bilibili 直播间的 wss 连接转化成事件.![Rust](svg/rust.svg?raw=true) (开发 / 直播脚本)
README
# bilive-danmaku
[![Crates.io][crates-badge]][crates-url]
[![Publish][ci-publish-badge]][ci-publish-url]
[![Build][ci-build-badge]][ci-build-url][crates-badge]: https://img.shields.io/crates/v/bilive-danmaku.svg
[crates-url]: https://crates.io/crates/bilive-danmaku
[ci-publish-badge]: https://github.com/4t145/bilive-danmaku/actions/workflows/publish.yml/badge.svg?branch=publish
[ci-publish-url]: https://github.com/4t145/bilive-danmaku/actions/workflows/publish.yml/?branch=publish
[ci-build-badge]: https://github.com/4t145/bilive-danmaku/actions/workflows/rust.yml/badge.svg?branch=master
[ci-build-url]: https://github.com/4t145/bilive-danmaku/actions/workflows/rust.yml/?branch=master这个库提供模拟bilibili直播的wss连接的功能,持续迭代中
关于发送弹幕等主动api,可以看我这个仓库: https://github.com/4t145/bilibili-client
## 使用
### 通过websocket
通过使用 https://github.com/4t145/rudanmaku-core这使你可以通过ws来获取事件,计划在未来支持ipc通讯(uds for linux,命名管道 for windows)
在`Cargo.toml`中加入
```toml
bilive-danmaku = { version = "0.3", features = ["rt_tokio"] }
```
使用
```rust
use bilive_danmaku::Connector;
use futures_util::StreamExt;async fn tokio_main() {
let roomid = 851181;
let connector = Connector::init(roomid, None).await.unwrap();
let mut stream = connector.connect().await.unwrap();
while let Some(maybe_evt) = stream.next().await {
match maybe_evt {
Ok(evt) => {
log::info!("{:?}", evt);
}
Err(e) => {
log::warn!("{:?}", e);
}
}
}
stream.abort();
}
```数据类型在`model`模块中, 事件类型在`event`模块中
```rust
use model::{User, FansMedal};
use event::Event as BiliEvent;
```
## 已经支持的事件
[参考这个文件](./src/event.rs)可参考:
- [命令原始数据](./src/tests/mock/cmd/)## feature flag
|flag|功能|
|:---:|:--:|
|`event`|只启用model和event,不包含连接,默认启用|
|`rt_tokio`|使用tokio连接直播间|
|`rt_wasm`|运行在wasm直播间|
|`bincode`|启用bincode正反序列化|
|`json`|启用json正反序列化|默认只启用`event`
比如你想把收到的消息序列化为json格式,启用
```toml
[dependencies.bilive-danmaku]
# ****
features = ["rt_tokio", "json"]
```# 提交代码
提交代码请fork一份,在自己的那一份签出新分支,然后提交到master分支提交前请进行格式化和clippy check,可以直接运行根目录的脚本文件
windows
```shell
./fix-all
```linux
```bash
bash fix-all.sh
```