Skip to content

Commit

Permalink
Merge branch 'bugfix-invalid-dmmsg'
Browse files Browse the repository at this point in the history
  • Loading branch information
keuin committed Jul 29, 2023
1 parent 9b5c391 commit c4dbd4a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bilibili/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
6 changes: 2 additions & 4 deletions bilibili/danmaku_server_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion bilibili/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion recording/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions recording/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions types/live_room.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit c4dbd4a

Please sign in to comment.