diff --git a/api/info.go b/api/info.go index c53ee27..76750df 100644 --- a/api/info.go +++ b/api/info.go @@ -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 diff --git a/client/client.go b/client/client.go index 02cd29d..a4654bf 100644 --- a/client/client.go +++ b/client/client.go @@ -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++ diff --git a/example/main.go b/example/main.go index a58be65..d88c9e2 100644 --- a/example/main.go +++ b/example/main.go @@ -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) {