55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package biliapi
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type SearchParams struct {
|
|
Cookie string
|
|
Keyword string
|
|
Order string
|
|
Page uint
|
|
}
|
|
|
|
func SearchVideo(params *SearchParams) ([]byte, error) {
|
|
url := fmt.Sprintf("https://api.bilibili.com/x/web-interface/search/type?"+
|
|
"page=%d&page_size=42&order=%s&platform=pc&keyword=%s&source_tag=3&search_type=video&dynamic_offset=0",
|
|
params.Page, params.Order, params.Keyword)
|
|
|
|
srv := BaseService{
|
|
Client: &http.Client{
|
|
Jar: nil,
|
|
Timeout: 2 * time.Second,
|
|
},
|
|
Url: url,
|
|
Headers: map[string]string{"Cookie": params.Cookie},
|
|
}
|
|
respBody, err := srv.DoRequest()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return respBody, nil
|
|
}
|
|
|
|
func SearchLiveRoom(params *SearchParams) ([]byte, error) {
|
|
url := fmt.Sprintf("https://api.bilibili.com/x/web-interface/search/type?"+
|
|
"page=%d&page_size=42&order=%s&platform=pc&keyword=%s&source_tag=3&search_type=live_room&dynamic_offset=0",
|
|
params.Page, params.Order, params.Keyword)
|
|
|
|
srv := BaseService{
|
|
Client: &http.Client{
|
|
Jar: nil,
|
|
Timeout: 2 * time.Second,
|
|
},
|
|
Url: url,
|
|
Headers: map[string]string{"Cookie": params.Cookie},
|
|
}
|
|
respBody, err := srv.DoRequest()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return respBody, nil
|
|
}
|