2024 年全年可用,无需key
Tiktok弹幕抓取 发送websocket服务器 , 需要试用的请联系 qq: 174389107
Receive live stream events such as comments and gifts and send to your websocket server tool in Go language.
Go语言实现,js注入
- 下载安装包
- 解压运行 Barrage.exe
- 关闭所有Chrome浏览器(可以不关闭,但必须在窗口中设置一个单独的Chrome用户目录,专门给Barrage使用)
- 输入正确的key,点Start运行
- 开启模拟ws客户端 用这个在线ws测试网站,连接 ws://127.0.0.1:9494/ws?systemId=tiktok ,也可以用其他ws测试网站 http://www.jsons.cn/websocket/
- Unity csharp客户端连接代码在 msgs_csharp (基于besthttp),已测试通过
- 启动抓取后,客户端用websocket连接 ws://127.0.0.1:9494/ws?systemId=tiktok
- 接收并处理弹幕数据
- Barrage启动ws服务,打开chrome
- Barrage注入js,将消息发送到设置的ws服务地址
- 任意连接到Barrage的ws客户端,都会收到转发的消息
- 如果要发送到自己的ws服务器,可以关闭“开启本机ws服务” ,填入自己的ws服务器地址
Write a go server to receive and parse data like this
func (c *Client) Read() {
go func() {
for {
messageType, msg, err := c.Socket.ReadMessage()
if err != nil {
if messageType == -1 && websocket.IsCloseError(err, websocket.CloseGoingAway, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) {
Manager.DisConnect <- c
return
} else if messageType != websocket.PingMessage {
return
}
} else {
msgString := string(msg)
var jsonData map[string]interface{}
err := json.Unmarshal([]byte(msgString), &jsonData)
if err != nil {
logrus.Error("Failed to unmarshal JSON:", err)
}
if common, ok := jsonData["common"].(map[string]interface{}); ok {
if method, ok := common["method"].(string); ok {
logrus.Info("Method:", method)
if method == "WebcastGiftMessage" {
var giftMessage msgs.WebcastGiftMessage
err := json.Unmarshal([]byte(msgString), &giftMessage)
if err != nil {
logrus.Error("Failed to unmarshal JSON into WebcastGiftMessage:", err)
} else {
c.LogChan <- giftMessage.User.Nickname + "使用了" + giftMessage.Gift.Describe + "数量" + giftMessage.GroupCount
}
// Process the giftMessage struct as needed
}
if method == "WebcastLikeMessage" {
var likeMessage msgs.WebcastLikeMessage
err := json.Unmarshal([]byte(msgString), &likeMessage)
if err != nil {
logrus.Error("Failed to unmarshal JSON into WebcastGiftMessage:", err)
} else {
c.LogChan <- likeMessage.User.Nickname + "点赞" + likeMessage.Count + "次,总数" + likeMessage.Total
}
// Process the giftMessage struct as needed
}
if method == "WebcastChatMessage" {
var chatMessage msgs.WebcastChatMessage
err := json.Unmarshal([]byte(msgString), &chatMessage)
if err != nil {
logrus.Error("Failed to unmarshal JSON into WebcastGiftMessage:", err)
} else {
c.LogChan <- chatMessage.User.Nickname + ":" + chatMessage.Content
}
// Process the giftMessage struct as needed
}
}
}
}
}
}()
}
消息json格式为:msg 消息标识(Chat,Gift,Like,Member....) data 为具体数据如下
msg_csharp里面部分字段不全,根据需要可自行填补
All data structures are in the msgs directory