summaryrefslogtreecommitdiff
path: root/common/testutil.go
blob: d6c38993b6fd883f91d804f1f2d73c0b21850621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package common

import (
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

/*
Some utility function for test-purpose only.
*/

type LiveList struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	TTL     int    `json:"ttl"`
	Data    struct {
		Count int `json:"count"`
		Data  []struct {
			Face     string `json:"face"`
			Link     string `json:"link"`
			Roomid   int    `json:"roomid"`
			Roomname string `json:"roomname"`
			Nickname string `json:"nickname"`
		} `json:"data"`
	} `json:"data"`
}

func GetLiveListForGuestUser() (liveList LiveList, err error) {
	url := "https://api.live.bilibili.com/xlive/web-interface/v1/index/WebGetUnLoginRecList"
	resp, err := http.Get(url)
	if err != nil {
		return
	}
	if resp.StatusCode != http.StatusOK {
		err = fmt.Errorf("bad http response: %v", resp.StatusCode)
		return
	}
	b, err := io.ReadAll(resp.Body)
	if err != nil {
		return
	}
	err = json.Unmarshal(b, &liveList)
	return
}