fix zero length hostlist

This commit is contained in:
aynakeya
2025-04-24 23:16:42 +08:00
parent 286c36c4dd
commit 66dbc68632
3 changed files with 5 additions and 1 deletions

View File

@@ -74,6 +74,7 @@ func GetDanmuInfo(roomID int, cookie string) (*DanmuInfo, error) {
result := &DanmuInfo{}
headers := &http.Header{}
headers.Set("cookie", cookie)
headers.Set("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36")
err := GetJsonWithHeader(fmt.Sprintf("https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?id=%d&type=0", roomID), headers, result)
if err != nil {
return nil, err

View File

@@ -115,6 +115,9 @@ func (c *Client) init() error {
func (c *Client) connect() error {
reqHeader := &http.Header{}
reqHeader.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36")
if len(c.hostList) == 0 {
return errors.New("blivedm-go: no host found when connecting")
}
retry:
c.host = c.hostList[c.retryCount%len(c.hostList)]
c.retryCount++

View File

@@ -13,7 +13,7 @@ import (
func main() {
log.SetLevel(log.DebugLevel)
c := client.NewClient(23943357)
c := client.NewClient(0)
c.SetCookie("")
//弹幕事件
c.OnDanmaku(func(danmaku *message.Danmaku) {