mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2025-12-15 23:58:16 +08:00
✨ 支持表情弹幕
This commit is contained in:
@@ -7,14 +7,22 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Danmaku struct {
|
const (
|
||||||
Sender User
|
TextDanmaku = iota
|
||||||
|
EmoticonDanmaku
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Danmaku struct {
|
||||||
|
Sender *User
|
||||||
Content string
|
Content string
|
||||||
Extra Extra
|
Extra *Extra
|
||||||
|
Emoticon *Emoticon
|
||||||
|
Type int
|
||||||
Timestamp int64
|
Timestamp int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type Extra struct {
|
Extra struct {
|
||||||
SendFromMe bool `json:"send_from_me"`
|
SendFromMe bool `json:"send_from_me"`
|
||||||
Mode int `json:"mode"`
|
Mode int `json:"mode"`
|
||||||
Color int `json:"color"`
|
Color int `json:"color"`
|
||||||
@@ -30,25 +38,42 @@ type Extra struct {
|
|||||||
SpaceType string `json:"space_type"`
|
SpaceType string `json:"space_type"`
|
||||||
SpaceUrl string `json:"space_url"`
|
SpaceUrl string `json:"space_url"`
|
||||||
}
|
}
|
||||||
|
Emoticon struct {
|
||||||
|
BulgeDisplay int `json:"bulge_display"`
|
||||||
|
EmoticonUnique string `json:"emoticon_unique"`
|
||||||
|
Height int `json:"height"`
|
||||||
|
InPlayerArea int `json:"in_player_area"`
|
||||||
|
IsDynamic int `json:"is_dynamic"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
Width int `json:"width"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func (d *Danmaku) Parse(data []byte) {
|
func (d *Danmaku) Parse(data []byte) {
|
||||||
sb := bytes.NewBuffer(data).String()
|
sb := bytes.NewBuffer(data).String()
|
||||||
info := gjson.Get(sb, "info")
|
info := gjson.Get(sb, "info")
|
||||||
|
ext := new(Extra)
|
||||||
|
emo := new(Emoticon)
|
||||||
|
err := json.Unmarshal([]byte(info.Get("0.15.extra").String()), ext)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("parse danmuku extra failed")
|
||||||
|
}
|
||||||
|
err = json.Unmarshal([]byte(info.Get("0.13").String()), emo)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("parse danmuku emoticon failed")
|
||||||
|
}
|
||||||
d.Content = info.Get("1").String()
|
d.Content = info.Get("1").String()
|
||||||
d.Sender = User{
|
d.Sender = &User{
|
||||||
Uid: int(info.Get("2.0").Int()),
|
Uid: int(info.Get("2.0").Int()),
|
||||||
Uname: info.Get("2.1").String(),
|
Uname: info.Get("2.1").String(),
|
||||||
Medal: Medal{
|
Medal: &Medal{
|
||||||
Name: info.Get("3.1").String(),
|
Name: info.Get("3.1").String(),
|
||||||
Level: int(info.Get("3.0").Int()),
|
Level: int(info.Get("3.0").Int()),
|
||||||
Up: info.Get("3.2").String(),
|
Up: info.Get("3.2").String(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ext := new(Extra)
|
d.Extra = ext
|
||||||
err := json.Unmarshal([]byte(info.Get("0.15.extra").String()), ext)
|
d.Emoticon = emo
|
||||||
if err != nil {
|
d.Type = int(info.Get("0.12").Int())
|
||||||
log.Error("parse danmuku extra failed")
|
|
||||||
}
|
|
||||||
d.Extra = *ext
|
|
||||||
d.Timestamp = info.Get("0.4").Int()
|
d.Timestamp = info.Get("0.4").Int()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package message
|
|||||||
type User struct {
|
type User struct {
|
||||||
Uid int
|
Uid int
|
||||||
Uname string
|
Uname string
|
||||||
Medal Medal
|
Medal *Medal
|
||||||
}
|
}
|
||||||
|
|
||||||
type Medal struct {
|
type Medal struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user