diff options
author | Keuin <[email protected]> | 2023-07-02 14:48:47 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-07-02 14:49:17 +0800 |
commit | b6eb2c0da4e653c6fdd278bcbdcd55ec376cd481 (patch) | |
tree | bc0d58aedf6e8613d21351cd3cdfd8cd5b5999e2 /bilibili | |
parent | b8d0d0c3b6b2ffe40921aa4c247c101dd0ce958d (diff) |
Refactor: move RoomId type to the correct package. Type all room ID usages.
Diffstat (limited to 'bilibili')
-rw-r--r-- | bilibili/danmaku_server_info.go | 3 | ||||
-rw-r--r-- | bilibili/danmaku_server_info_test.go | 6 | ||||
-rw-r--r-- | bilibili/play_url.go | 3 | ||||
-rw-r--r-- | bilibili/play_url_test.go | 6 | ||||
-rw-r--r-- | bilibili/room_profile.go | 7 | ||||
-rw-r--r-- | bilibili/room_profile_test.go | 8 | ||||
-rw-r--r-- | bilibili/room_status.go | 3 | ||||
-rw-r--r-- | bilibili/room_status_test.go | 6 | ||||
-rw-r--r-- | bilibili/streaming.go | 2 | ||||
-rw-r--r-- | bilibili/streaming_test.go | 6 |
10 files changed, 24 insertions, 26 deletions
diff --git a/bilibili/danmaku_server_info.go b/bilibili/danmaku_server_info.go index 1a91b14..b68d4b5 100644 --- a/bilibili/danmaku_server_info.go +++ b/bilibili/danmaku_server_info.go @@ -2,7 +2,6 @@ package bilibili import ( "fmt" - "github.com/keuin/slbr/common" ) type DanmakuServerInfoResponse = BaseResponse[danmakuInfo] @@ -22,7 +21,7 @@ type danmakuInfo struct { } `json:"host_list"` } -func (b Bilibili) GetDanmakuServerInfo(roomId common.RoomId) (resp DanmakuServerInfoResponse, err error) { +func (b Bilibili) GetDanmakuServerInfo(roomId RoomId) (resp DanmakuServerInfoResponse, err error) { url := fmt.Sprintf("https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?id=%d&type=0", roomId) return callGet[DanmakuServerInfoResponse](b, url) } diff --git a/bilibili/danmaku_server_info_test.go b/bilibili/danmaku_server_info_test.go index 3166304..7cfa8fe 100644 --- a/bilibili/danmaku_server_info_test.go +++ b/bilibili/danmaku_server_info_test.go @@ -1,7 +1,7 @@ package bilibili import ( - "github.com/keuin/slbr/common" + testing2 "github.com/keuin/slbr/common/testing" "github.com/keuin/slbr/logging" "log" "testing" @@ -9,7 +9,7 @@ import ( func TestBilibili_GetDanmakuServerInfo(t *testing.T) { // get an online live room for testing - liveList, err := common.GetLiveListForGuestUser() + liveList, err := testing2.GetLiveListForGuestUser() if err != nil { t.Fatalf("Cannot get live list for testing: %v", err) } @@ -17,7 +17,7 @@ func TestBilibili_GetDanmakuServerInfo(t *testing.T) { if len(lives) <= 0 { t.Fatalf("No available live for guest user") } - roomId := common.RoomId(lives[0].Roomid) + roomId := lives[0].Roomid logger := log.Default() bi := NewBilibili(logging.NewWrappedLogger(logger, "test-logger")) diff --git a/bilibili/play_url.go b/bilibili/play_url.go index 36882bc..49e8298 100644 --- a/bilibili/play_url.go +++ b/bilibili/play_url.go @@ -2,7 +2,6 @@ package bilibili import ( "fmt" - "github.com/keuin/slbr/common" ) type RoomUrlInfoResponse = BaseResponse[roomUrlInfo] @@ -28,7 +27,7 @@ type StreamingUrlInfo struct { P2pType int `json:"p2p_type"` } -func (b Bilibili) GetStreamingInfo(roomId common.RoomId) (resp RoomUrlInfoResponse, err error) { +func (b Bilibili) GetStreamingInfo(roomId RoomId) (resp RoomUrlInfoResponse, err error) { url := fmt.Sprintf("https://api.live.bilibili.com/room/v1/Room/playUrl?"+ "cid=%d&otype=json&qn=10000&platform=web", roomId) return callGet[RoomUrlInfoResponse](b, url) diff --git a/bilibili/play_url_test.go b/bilibili/play_url_test.go index 7ec17ee..1ec0729 100644 --- a/bilibili/play_url_test.go +++ b/bilibili/play_url_test.go @@ -1,7 +1,7 @@ package bilibili import ( - "github.com/keuin/slbr/common" + testing2 "github.com/keuin/slbr/common/testing" "github.com/keuin/slbr/logging" "log" "testing" @@ -9,7 +9,7 @@ import ( func TestBilibili_GetStreamingInfo(t *testing.T) { // get an online live room for testing - liveList, err := common.GetLiveListForGuestUser() + liveList, err := testing2.GetLiveListForGuestUser() if err != nil { t.Fatalf("cannot get live list for testing: %v", err) } @@ -17,7 +17,7 @@ func TestBilibili_GetStreamingInfo(t *testing.T) { if len(lives) <= 0 { t.Fatalf("no live for guest available") } - roomId := common.RoomId(lives[0].Roomid) + roomId := lives[0].Roomid logger := log.Default() bi := NewBilibili(logging.NewWrappedLogger(logger, "test-logger")) diff --git a/bilibili/room_profile.go b/bilibili/room_profile.go index 9eed175..98cc790 100644 --- a/bilibili/room_profile.go +++ b/bilibili/room_profile.go @@ -2,12 +2,11 @@ package bilibili import ( "fmt" - "github.com/keuin/slbr/common" ) type roomProfile struct { UID int `json:"uid"` - RoomID int `json:"room_id"` + RoomID RoomId `json:"room_id"` ShortID int `json:"short_id"` Attention int `json:"attention"` Online int `json:"online"` @@ -80,7 +79,9 @@ type roomProfile struct { type RoomProfileResponse = BaseResponse[roomProfile] -func (b Bilibili) GetRoomProfile(roomId common.RoomId) (resp RoomProfileResponse, err error) { +func (b Bilibili) GetRoomProfile(roomId RoomId) (resp RoomProfileResponse, err error) { url := fmt.Sprintf("https://api.live.bilibili.com/room/v1/Room/get_info?room_id=%d", roomId) return callGet[RoomProfileResponse](b, url) } + +type RoomId uint64 diff --git a/bilibili/room_profile_test.go b/bilibili/room_profile_test.go index 0abd8dd..a1d68c5 100644 --- a/bilibili/room_profile_test.go +++ b/bilibili/room_profile_test.go @@ -1,7 +1,7 @@ package bilibili import ( - "github.com/keuin/slbr/common" + testing2 "github.com/keuin/slbr/common/testing" "github.com/keuin/slbr/logging" "log" "testing" @@ -9,7 +9,7 @@ import ( func TestBilibili_GetRoomProfile(t *testing.T) { // get an online live room for testing - liveList, err := common.GetLiveListForGuestUser() + liveList, err := testing2.GetLiveListForGuestUser() if err != nil { t.Fatalf("cannot get live list for testing: %v", err) } @@ -17,7 +17,7 @@ func TestBilibili_GetRoomProfile(t *testing.T) { if len(lives) <= 0 { t.Fatalf("no live for guest available") } - roomId := common.RoomId(lives[0].Roomid) + roomId := lives[0].Roomid logger := log.Default() bi := NewBilibili(logging.NewWrappedLogger(logger, "test-logger")) @@ -28,7 +28,7 @@ func TestBilibili_GetRoomProfile(t *testing.T) { if resp.Code != 0 || resp.Message != "ok" || resp.Data.UID <= 0 || - resp.Data.RoomID != int(roomId) || + resp.Data.RoomID != roomId || resp.Data.LiveStatus != int(Streaming) || resp.Data.Title == "" { t.Fatalf("Invalid GetRoomProfile response: %v", resp) diff --git a/bilibili/room_status.go b/bilibili/room_status.go index fc6219a..cbb8bc4 100644 --- a/bilibili/room_status.go +++ b/bilibili/room_status.go @@ -6,7 +6,6 @@ package bilibili import ( "fmt" - "github.com/keuin/slbr/common" ) type LiveStatus int @@ -51,7 +50,7 @@ func (s LiveStatus) String() string { return liveStatusStringMap[s] } -func (b Bilibili) GetRoomPlayInfo(roomId common.RoomId) (resp RoomPlayInfoResponse, err error) { +func (b Bilibili) GetRoomPlayInfo(roomId RoomId) (resp RoomPlayInfoResponse, err error) { url := fmt.Sprintf("https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo"+ "?room_id=%d&protocol=0,1&format=0,1,2&codec=0,1&qn=0&platform=web&ptype=8&dolby=5&panorama=1", roomId) return callGet[RoomPlayInfoResponse](b, url) diff --git a/bilibili/room_status_test.go b/bilibili/room_status_test.go index f97cf51..dde99f7 100644 --- a/bilibili/room_status_test.go +++ b/bilibili/room_status_test.go @@ -1,7 +1,7 @@ package bilibili import ( - "github.com/keuin/slbr/common" + testing2 "github.com/keuin/slbr/common/testing" "github.com/keuin/slbr/logging" "log" "testing" @@ -9,7 +9,7 @@ import ( func TestBilibili_GetRoomPlayInfo(t *testing.T) { // get an online live room for testing - liveList, err := common.GetLiveListForGuestUser() + liveList, err := testing2.GetLiveListForGuestUser() if err != nil { t.Fatalf("cannot get live list for testing: %v", err) } @@ -17,7 +17,7 @@ func TestBilibili_GetRoomPlayInfo(t *testing.T) { if len(lives) <= 0 { t.Fatalf("no live for guest available") } - roomId := common.RoomId(lives[0].Roomid) + roomId := lives[0].Roomid logger := log.Default() bi := NewBilibili(logging.NewWrappedLogger(logger, "test-logger")) diff --git a/bilibili/streaming.go b/bilibili/streaming.go index 97b8e23..8f6c491 100644 --- a/bilibili/streaming.go +++ b/bilibili/streaming.go @@ -16,7 +16,7 @@ const InitReadBytes = 4096 // 4KiB // CopyLiveStream read data from a livestream video stream, copy them to a writer. func (b Bilibili) CopyLiveStream( ctx context.Context, - roomId common.RoomId, + roomId RoomId, stream StreamingUrlInfo, fileCreator func() (*os.File, error), bufSize int64, diff --git a/bilibili/streaming_test.go b/bilibili/streaming_test.go index ef438db..3b5bd3a 100644 --- a/bilibili/streaming_test.go +++ b/bilibili/streaming_test.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "github.com/keuin/slbr/common" + testing2 "github.com/keuin/slbr/common/testing" "github.com/keuin/slbr/logging" "log" "os" @@ -13,7 +13,7 @@ import ( func TestBilibili_CopyLiveStream(t *testing.T) { // get an online live room for testing - liveList, err := common.GetLiveListForGuestUser() + liveList, err := testing2.GetLiveListForGuestUser() if err != nil { t.Fatalf("cannot get live list for testing: %v", err) } @@ -21,7 +21,7 @@ func TestBilibili_CopyLiveStream(t *testing.T) { if len(lives) <= 0 { t.Fatalf("no live for guest available") } - roomId := common.RoomId(lives[0].Roomid) + roomId := lives[0].Roomid logger := log.Default() bi := NewBilibili(logging.NewWrappedLogger(logger, "test-logger")) |