🎨 move GetDanmuInfo to api

This commit is contained in:
Akiba
2022-03-24 19:58:43 +08:00
parent 0d421f943b
commit a51470041d
2 changed files with 1 additions and 40 deletions

View File

@@ -1,14 +1,12 @@
package client
import (
"encoding/json"
"errors"
"fmt"
"github.com/Akegarasu/blivedm-go/api"
"github.com/Akegarasu/blivedm-go/packet"
"github.com/gorilla/websocket"
log "github.com/sirupsen/logrus"
"net/http"
"strconv"
"time"
)
@@ -40,7 +38,7 @@ func (c *Client) Connect() error {
c.roomID = realID
}
if c.host == "" {
info, err := getDanmuInfo(c.roomID)
info, err := api.GetDanmuInfo(c.roomID)
if err != nil {
return err
}
@@ -120,17 +118,3 @@ func (c *Client) sendEnterPacket() error {
log.Debugf("send: EnterPacket: %v", pkt)
return nil
}
func getDanmuInfo(roomID string) (*DanmuInfo, error) {
url := fmt.Sprintf("https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?id=%s&type=0", roomID)
resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
result := &DanmuInfo{}
if err = json.NewDecoder(resp.Body).Decode(result); err != nil {
return nil, err
}
return result, nil
}

View File

@@ -1,23 +0,0 @@
package client
// DanmuInfo
// api https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?id={}&type=0 response
type DanmuInfo struct {
Code int `json:"code"`
Message string `json:"message"`
Ttl int `json:"ttl"`
Data struct {
Group string `json:"group"`
BusinessId int `json:"business_id"`
RefreshRowFactor float64 `json:"refresh_row_factor"`
RefreshRate int `json:"refresh_rate"`
MaxDelay int `json:"max_delay"`
Token string `json:"token"`
HostList []struct {
Host string `json:"host"`
Port int `json:"port"`
WssPort int `json:"wss_port"`
WsPort int `json:"ws_port"`
} `json:"host_list"`
} `json:"data"`
}