From c4dbd4a7b2ad86fcb0220a4e2ffdae68d0d00103 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 29 Jul 2023 20:28:19 +0800 Subject: Merge branch 'bugfix-invalid-dmmsg' --- bilibili/connect.go | 2 +- bilibili/danmaku_server_info.go | 6 ++---- bilibili/request.go | 2 +- recording/runner.go | 3 ++- recording/watcher.go | 4 ++-- types/live_room.go | 2 ++ 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/bilibili/connect.go b/bilibili/connect.go index 472c979..de608d0 100644 --- a/bilibili/connect.go +++ b/bilibili/connect.go @@ -5,7 +5,7 @@ import ( "nhooyr.io/websocket" ) -func (b Bilibili) DialWebSocket(ctx context.Context, url string) (*websocket.Conn, error) { +func (b *Bilibili) DialWebSocket(ctx context.Context, url string) (*websocket.Conn, error) { ws, _, err := websocket.Dial(ctx, url, &websocket.DialOptions{ HTTPClient: b.http, }) diff --git a/bilibili/danmaku_server_info.go b/bilibili/danmaku_server_info.go index 8c79d51..119a8f9 100644 --- a/bilibili/danmaku_server_info.go +++ b/bilibili/danmaku_server_info.go @@ -7,8 +7,6 @@ import ( "net/url" ) -type WebBannerResponse = BaseResponse[interface{}] - const apiUrlPrefix = "https://api.live.bilibili.com" func (b *Bilibili) GetDanmakuServerInfo(roomId types.RoomId) (resp types.DanmakuServerInfoResponse, err error) { @@ -38,10 +36,10 @@ func (b *Bilibili) GetBUVID() (string, error) { } // GetLiveBUVID initializes cookie `LIVE_BUVID`. This should be called before GetDanmakuServerInfo. -func (b *Bilibili) GetLiveBUVID(roomId types.RoomId) (resp WebBannerResponse, err error) { +func (b *Bilibili) GetLiveBUVID(roomId types.RoomId) (resp types.WebBannerResponse, err error) { u := fmt.Sprintf("https://api.live.bilibili.com/activity/v1/Common/webBanner?"+ "platform=web&position=6&roomid=%d&area_v2_parent_id=0&area_v2_id=0&from=", roomId) - resp, err = callGet[WebBannerResponse](b, u) + resp, err = callGet[types.WebBannerResponse](b, u) if err == nil { uu, _ := url.Parse(apiUrlPrefix) b.logger.Info("Cookie info: %v", b.http.Jar.Cookies(uu)) diff --git a/bilibili/request.go b/bilibili/request.go index 613530c..39479a1 100644 --- a/bilibili/request.go +++ b/bilibili/request.go @@ -60,7 +60,7 @@ func callGetRaw(b *Bilibili, url string) (resp *http.Response, respBody []byte, } // callGet make a GET request and parse response as a JSON document with given model. -func callGet[T BaseResponse[V], V any](b Bilibili, url string) (resp T, err error) { +func callGet[T types.BaseResponse[V], V any](b *Bilibili, url string) (resp T, err error) { r, data, err := callGetRaw(b, url) if err != nil { return diff --git a/recording/runner.go b/recording/runner.go index 9e5f83c..9be78c9 100644 --- a/recording/runner.go +++ b/recording/runner.go @@ -12,6 +12,7 @@ import ( "fmt" "github.com/keuin/slbr/bilibili" errs "github.com/keuin/slbr/bilibili/errors" + "github.com/keuin/slbr/common" "github.com/keuin/slbr/common/files" "github.com/keuin/slbr/common/myurl" "github.com/keuin/slbr/logging" @@ -128,7 +129,7 @@ func tryRunTask(t *RunningTask) error { dmInfo.BUVID3, liveStatusChecker, t.logger, - &bi, + bi, ) // the context is cancelled if errors.Is(err, context.Canceled) { diff --git a/recording/watcher.go b/recording/watcher.go index ff9bde1..269869b 100644 --- a/recording/watcher.go +++ b/recording/watcher.go @@ -4,8 +4,8 @@ import ( "context" "encoding/base64" "encoding/json" - errs "github.com/keuin/slbr/bilibili" - "github.com/keuin/slbr/bilibili/errors" + "github.com/keuin/slbr/bilibili" + errs "github.com/keuin/slbr/bilibili/errors" "github.com/keuin/slbr/danmaku" "github.com/keuin/slbr/danmaku/dmmsg" "github.com/keuin/slbr/danmaku/dmpkg" diff --git a/types/live_room.go b/types/live_room.go index 77588c5..a9a057a 100644 --- a/types/live_room.go +++ b/types/live_room.go @@ -2,6 +2,8 @@ package types type RoomUrlInfoResponse = BaseResponse[roomUrlInfo] +type WebBannerResponse = BaseResponse[interface{}] + type roomUrlInfo struct { CurrentQuality int `json:"current_quality"` AcceptQuality []string `json:"accept_quality"` -- cgit v1.2.3