mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2025-12-06 19:32:49 +08:00
fix zero length hostlist
This commit is contained in:
@@ -74,6 +74,7 @@ func GetDanmuInfo(roomID int, cookie string) (*DanmuInfo, error) {
|
|||||||
result := &DanmuInfo{}
|
result := &DanmuInfo{}
|
||||||
headers := &http.Header{}
|
headers := &http.Header{}
|
||||||
headers.Set("cookie", cookie)
|
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)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ func (c *Client) init() error {
|
|||||||
func (c *Client) connect() error {
|
func (c *Client) connect() error {
|
||||||
reqHeader := &http.Header{}
|
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")
|
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:
|
retry:
|
||||||
c.host = c.hostList[c.retryCount%len(c.hostList)]
|
c.host = c.hostList[c.retryCount%len(c.hostList)]
|
||||||
c.retryCount++
|
c.retryCount++
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
c := client.NewClient(23943357)
|
c := client.NewClient(0)
|
||||||
c.SetCookie("")
|
c.SetCookie("")
|
||||||
//弹幕事件
|
//弹幕事件
|
||||||
c.OnDanmaku(func(danmaku *message.Danmaku) {
|
c.OnDanmaku(func(danmaku *message.Danmaku) {
|
||||||
|
|||||||
Reference in New Issue
Block a user