mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2025-12-06 11:22:50 +08:00
update api
This commit is contained in:
25
api/api.go
25
api/api.go
@@ -1,8 +1,11 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type IApi interface {
|
||||
GetUid() (int, error)
|
||||
GetDanmuInfo(roomID int) (*DanmuInfo, error)
|
||||
GetDanmuInfo(roomID int) (int, *DanmuInfo, error)
|
||||
GetRoomInfo(roomID int) (*RoomInfo, error)
|
||||
}
|
||||
|
||||
@@ -10,12 +13,18 @@ type defaultClient struct {
|
||||
cookie string
|
||||
}
|
||||
|
||||
func (d *defaultClient) GetUid() (int, error) {
|
||||
return GetUid(d.cookie)
|
||||
}
|
||||
|
||||
func (d *defaultClient) GetDanmuInfo(roomID int) (*DanmuInfo, error) {
|
||||
return GetDanmuInfo(roomID, d.cookie)
|
||||
func (d *defaultClient) GetDanmuInfo(roomID int) (int, *DanmuInfo, error) {
|
||||
var uid int = 0
|
||||
var err error
|
||||
if d.cookie != "" {
|
||||
uid, err = GetUid(d.cookie)
|
||||
if err != nil {
|
||||
uid = 0
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
result, err := GetDanmuInfo(roomID, d.cookie)
|
||||
return uid, result, err
|
||||
}
|
||||
|
||||
func (d *defaultClient) GetRoomInfo(roomID int) (*RoomInfo, error) {
|
||||
|
||||
@@ -74,11 +74,6 @@ func (c *Client) init() error {
|
||||
log.Errorf("cannot found account token")
|
||||
return errors.New("账号未登录")
|
||||
}
|
||||
uid, err := c.api.GetUid()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
c.Uid = uid
|
||||
re := regexp.MustCompile("_uuid=(.+?);")
|
||||
result := re.FindAllStringSubmatch(c.Cookie, -1)
|
||||
if len(result) > 0 {
|
||||
@@ -92,7 +87,8 @@ func (c *Client) init() error {
|
||||
}
|
||||
c.RoomID = roomInfo.Data.RoomId
|
||||
if c.host == "" {
|
||||
info, err := c.api.GetDanmuInfo(c.RoomID)
|
||||
uid, info, err := c.api.GetDanmuInfo(c.RoomID)
|
||||
c.Uid = uid
|
||||
if err != nil {
|
||||
c.hostList = []string{"broadcastlv.chat.bilibili.com"}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user