Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/BotPlayerNeo/bili-live-api
bilibili(B站)直播API调用的Go语言实现
https://github.com/BotPlayerNeo/bili-live-api
bilibili golang websocket
Last synced: 9 days ago
JSON representation
bilibili(B站)直播API调用的Go语言实现
- Host: GitHub
- URL: https://github.com/BotPlayerNeo/bili-live-api
- Owner: PlayerNeo42
- License: apache-2.0
- Archived: true
- Created: 2021-11-16T07:56:02.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-09-17T10:56:24.000Z (about 2 years ago)
- Last Synced: 2024-10-28T11:55:49.523Z (11 days ago)
- Topics: bilibili, golang, websocket
- Language: Go
- Homepage:
- Size: 71.3 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-bilibili-extra - Bili-live-api - B 站直播 API 的 Go 语言实现(目前仅支持弹幕相关). (开发 / 直播脚本)
README
# B站直播API
B站直播相关API的Go语言实现
目前仅支持直播间弹幕相关API
## 支持
- 礼物
- 超级留言
- 弹幕
- 其他 websocket 事件详见`dto/`目录下的文件
## 快速开始
### 安装
```shell
go get github.com/botplayerneo/bili-live-api
```### 使用
```go
package mainimport (
"fmt"api "github.com/botplayerneo/bili-live-api"
"github.com/botplayerneo/bili-live-api/dto"
"github.com/botplayerneo/bili-live-api/log"
"github.com/botplayerneo/bili-live-api/websocket"
)func main() {
// 设置内部 logger 打印日志等级
// 或通过 log.ReplaceDefault(customLogger) 来使用自定义 logger
log.SetLogLevel(log.LevelWarn)// 参数为房间号
l := api.NewLive(510)// 内部通过 type switch 来判断 handler 类型
// handler 类型定义在 websocket 包中
err := l.RegisterHandlers(
danmakuHandler(),
giftHandler(),
guardHandler(),
superChatHandler(),
)
if err != nil {
panic(err)
}l.Start()
}func danmakuHandler() websocket.DanmakuHandler {
return func(danmaku *dto.Danmaku) {
fmt.Printf("%s:%s\n", danmaku.Uname, danmaku.Content)
}
}func giftHandler() websocket.GiftHandler {
return func(gift *dto.Gift) {
fmt.Printf("%s 赠送 [礼物%.1f¥]%s x %d\n", gift.Uname, float64(gift.Price)/1000, gift.GiftName, gift.Num)
}
}func guardHandler() websocket.GuardHandler {
return func(guard *dto.Guard) {
fmt.Printf("%s 开通舰长,级别%d", guard.Username, guard.GuardLevel)
}
}func superChatHandler() websocket.SuperChatHandler {
return func(superChat *dto.SuperChat) {
fmt.Printf("[%d¥SC]%s:%s\n", superChat.Price, superChat.UserInfo.Uname, superChat.Message)
}
}```
## 相关
项目组织结构参考: [botgo](https://github.com/tencent-connect/botgo)