新增直播间搜索

用户信息可以获取直播间信息了
This commit is contained in:
Eigeen 2022-12-25 18:07:24 +08:00
parent b2b566f9dd
commit ed9189a313
9 changed files with 2525 additions and 773 deletions

2
.gitignore vendored
View File

@ -13,3 +13,5 @@
# Dependency directories (remove the comment below to include it)
# vendor/
*.toml

View File

@ -3,6 +3,7 @@ package biliapi
import (
"io"
"net/http"
"net/url"
"time"
)
@ -12,25 +13,41 @@ type Root struct {
TTL int `json:"ttl"`
Data interface{} `json:"data"`
}
type Jar struct {
cookies []*http.Cookie
}
func (jar *Jar) SetCookies(u *url.URL, cookies []*http.Cookie) {
jar.cookies = cookies
}
func (jar *Jar) Cookies(u *url.URL) []*http.Cookie {
return jar.cookies
}
type BaseService struct {
client *http.Client
url string
Client *http.Client
Url string
Headers map[string]string
}
func (srv *BaseService) DoRequest() ([]byte, error) {
req, err := http.NewRequest("GET", srv.url, nil)
req, err := http.NewRequest("GET", srv.Url, nil)
if err != nil {
return nil, err
}
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46")
if srv.Headers != nil {
for k, v := range srv.Headers {
req.Header.Add(k, v)
}
}
if srv.client == nil {
srv.client = &http.Client{
Timeout: time.Duration(5) * time.Second,
if srv.Client == nil {
srv.Client = &http.Client{
Timeout: 2 * time.Second,
}
}
resp, err := srv.client.Do(req)
resp, err := srv.Client.Do(req)
defer resp.Body.Close()
if err != nil {
return nil, err
@ -40,9 +57,6 @@ func (srv *BaseService) DoRequest() ([]byte, error) {
if err != nil {
return nil, err
}
//if resp.StatusCode != 200 {
// return body, NewAPIError(fmt.Sprintf("非正常返回值StatusCode %d", resp.StatusCode))
//}
return body, nil
}

View File

@ -9,8 +9,8 @@ func BasicInfo(mid uint) ([]byte, error) {
url := fmt.Sprintf("https://api.bilibili.com/x/space/wbi/acc/info?mid=%d", mid)
srv := BaseService{
client: &http.Client{},
url: url,
Client: &http.Client{},
Url: url,
}
respBody, err := srv.DoRequest()
if err != nil {

54
biliapi/search.go Normal file
View File

@ -0,0 +1,54 @@
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
}

View File

@ -18,8 +18,8 @@ func UserStat(mid uint) ([]byte, error) {
url := fmt.Sprintf("https://api.bilibili.com/x/relation/stat?vmid=%d", mid)
srv := BaseService{
client: &http.Client{},
url: url,
Client: &http.Client{},
Url: url,
}
respBody, err := srv.DoRequest()
if err != nil {

View File

@ -1,754 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v3.21.8
// source: api.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type StatRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Uid uint64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"`
}
func (x *StatRequest) Reset() {
*x = StatRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_api_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *StatRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*StatRequest) ProtoMessage() {}
func (x *StatRequest) ProtoReflect() protoreflect.Message {
mi := &file_api_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use StatRequest.ProtoReflect.Descriptor instead.
func (*StatRequest) Descriptor() ([]byte, []int) {
return file_api_proto_rawDescGZIP(), []int{0}
}
func (x *StatRequest) GetUid() uint64 {
if x != nil {
return x.Uid
}
return 0
}
type StatReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"`
Data *StatReply_Data `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *StatReply) Reset() {
*x = StatReply{}
if protoimpl.UnsafeEnabled {
mi := &file_api_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *StatReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*StatReply) ProtoMessage() {}
func (x *StatReply) ProtoReflect() protoreflect.Message {
mi := &file_api_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use StatReply.ProtoReflect.Descriptor instead.
func (*StatReply) Descriptor() ([]byte, []int) {
return file_api_proto_rawDescGZIP(), []int{1}
}
func (x *StatReply) GetCode() int32 {
if x != nil {
return x.Code
}
return 0
}
func (x *StatReply) GetMsg() string {
if x != nil {
return x.Msg
}
return ""
}
func (x *StatReply) GetData() *StatReply_Data {
if x != nil {
return x.Data
}
return nil
}
type InfoRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Uid uint64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"`
}
func (x *InfoRequest) Reset() {
*x = InfoRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_api_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *InfoRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*InfoRequest) ProtoMessage() {}
func (x *InfoRequest) ProtoReflect() protoreflect.Message {
mi := &file_api_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use InfoRequest.ProtoReflect.Descriptor instead.
func (*InfoRequest) Descriptor() ([]byte, []int) {
return file_api_proto_rawDescGZIP(), []int{2}
}
func (x *InfoRequest) GetUid() uint64 {
if x != nil {
return x.Uid
}
return 0
}
type InfoReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"`
Data *InfoReply_Data `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *InfoReply) Reset() {
*x = InfoReply{}
if protoimpl.UnsafeEnabled {
mi := &file_api_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *InfoReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*InfoReply) ProtoMessage() {}
func (x *InfoReply) ProtoReflect() protoreflect.Message {
mi := &file_api_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use InfoReply.ProtoReflect.Descriptor instead.
func (*InfoReply) Descriptor() ([]byte, []int) {
return file_api_proto_rawDescGZIP(), []int{3}
}
func (x *InfoReply) GetCode() int32 {
if x != nil {
return x.Code
}
return 0
}
func (x *InfoReply) GetMsg() string {
if x != nil {
return x.Msg
}
return ""
}
func (x *InfoReply) GetData() *InfoReply_Data {
if x != nil {
return x.Data
}
return nil
}
type StatReply_Data struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Mid uint64 `protobuf:"varint,1,opt,name=mid,proto3" json:"mid,omitempty"`
Following uint32 `protobuf:"varint,2,opt,name=following,proto3" json:"following,omitempty"`
Whisper uint32 `protobuf:"varint,3,opt,name=whisper,proto3" json:"whisper,omitempty"`
Black uint32 `protobuf:"varint,4,opt,name=black,proto3" json:"black,omitempty"`
Follower uint32 `protobuf:"varint,5,opt,name=follower,proto3" json:"follower,omitempty"`
}
func (x *StatReply_Data) Reset() {
*x = StatReply_Data{}
if protoimpl.UnsafeEnabled {
mi := &file_api_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *StatReply_Data) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*StatReply_Data) ProtoMessage() {}
func (x *StatReply_Data) ProtoReflect() protoreflect.Message {
mi := &file_api_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use StatReply_Data.ProtoReflect.Descriptor instead.
func (*StatReply_Data) Descriptor() ([]byte, []int) {
return file_api_proto_rawDescGZIP(), []int{1, 0}
}
func (x *StatReply_Data) GetMid() uint64 {
if x != nil {
return x.Mid
}
return 0
}
func (x *StatReply_Data) GetFollowing() uint32 {
if x != nil {
return x.Following
}
return 0
}
func (x *StatReply_Data) GetWhisper() uint32 {
if x != nil {
return x.Whisper
}
return 0
}
func (x *StatReply_Data) GetBlack() uint32 {
if x != nil {
return x.Black
}
return 0
}
func (x *StatReply_Data) GetFollower() uint32 {
if x != nil {
return x.Follower
}
return 0
}
type InfoReply_Data struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Mid uint64 `protobuf:"varint,1,opt,name=mid,proto3" json:"mid,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Sex string `protobuf:"bytes,3,opt,name=sex,proto3" json:"sex,omitempty"`
Face string `protobuf:"bytes,4,opt,name=face,proto3" json:"face,omitempty"`
FaceNft uint32 `protobuf:"varint,5,opt,name=face_nft,json=faceNft,proto3" json:"face_nft,omitempty"`
FaceNftType uint32 `protobuf:"varint,6,opt,name=face_nft_type,json=faceNftType,proto3" json:"face_nft_type,omitempty"`
Sign string `protobuf:"bytes,7,opt,name=sign,proto3" json:"sign,omitempty"`
Rank uint32 `protobuf:"varint,8,opt,name=rank,proto3" json:"rank,omitempty"`
Level uint32 `protobuf:"varint,9,opt,name=level,proto3" json:"level,omitempty"`
Jointime uint32 `protobuf:"varint,10,opt,name=jointime,proto3" json:"jointime,omitempty"`
Moral uint32 `protobuf:"varint,11,opt,name=moral,proto3" json:"moral,omitempty"`
Silence uint32 `protobuf:"varint,12,opt,name=silence,proto3" json:"silence,omitempty"`
Coins uint32 `protobuf:"varint,13,opt,name=coins,proto3" json:"coins,omitempty"`
FansBadge bool `protobuf:"varint,14,opt,name=fans_badge,json=fansBadge,proto3" json:"fans_badge,omitempty"`
IsFollowed bool `protobuf:"varint,21,opt,name=is_followed,json=isFollowed,proto3" json:"is_followed,omitempty"`
TopPhoto string `protobuf:"bytes,22,opt,name=top_photo,json=topPhoto,proto3" json:"top_photo,omitempty"`
Birthday string `protobuf:"bytes,26,opt,name=birthday,proto3" json:"birthday,omitempty"`
Tags []string `protobuf:"bytes,29,rep,name=tags,proto3" json:"tags,omitempty"`
IsSeniorMember uint32 `protobuf:"varint,31,opt,name=is_senior_member,json=isSeniorMember,proto3" json:"is_senior_member,omitempty"`
McnInfo string `protobuf:"bytes,32,opt,name=mcn_info,json=mcnInfo,proto3" json:"mcn_info,omitempty"`
GaiaResType uint32 `protobuf:"varint,33,opt,name=gaia_res_type,json=gaiaResType,proto3" json:"gaia_res_type,omitempty"`
GaiaData string `protobuf:"bytes,34,opt,name=gaia_data,json=gaiaData,proto3" json:"gaia_data,omitempty"`
IsRisk bool `protobuf:"varint,35,opt,name=is_risk,json=isRisk,proto3" json:"is_risk,omitempty"`
}
func (x *InfoReply_Data) Reset() {
*x = InfoReply_Data{}
if protoimpl.UnsafeEnabled {
mi := &file_api_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *InfoReply_Data) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*InfoReply_Data) ProtoMessage() {}
func (x *InfoReply_Data) ProtoReflect() protoreflect.Message {
mi := &file_api_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use InfoReply_Data.ProtoReflect.Descriptor instead.
func (*InfoReply_Data) Descriptor() ([]byte, []int) {
return file_api_proto_rawDescGZIP(), []int{3, 0}
}
func (x *InfoReply_Data) GetMid() uint64 {
if x != nil {
return x.Mid
}
return 0
}
func (x *InfoReply_Data) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *InfoReply_Data) GetSex() string {
if x != nil {
return x.Sex
}
return ""
}
func (x *InfoReply_Data) GetFace() string {
if x != nil {
return x.Face
}
return ""
}
func (x *InfoReply_Data) GetFaceNft() uint32 {
if x != nil {
return x.FaceNft
}
return 0
}
func (x *InfoReply_Data) GetFaceNftType() uint32 {
if x != nil {
return x.FaceNftType
}
return 0
}
func (x *InfoReply_Data) GetSign() string {
if x != nil {
return x.Sign
}
return ""
}
func (x *InfoReply_Data) GetRank() uint32 {
if x != nil {
return x.Rank
}
return 0
}
func (x *InfoReply_Data) GetLevel() uint32 {
if x != nil {
return x.Level
}
return 0
}
func (x *InfoReply_Data) GetJointime() uint32 {
if x != nil {
return x.Jointime
}
return 0
}
func (x *InfoReply_Data) GetMoral() uint32 {
if x != nil {
return x.Moral
}
return 0
}
func (x *InfoReply_Data) GetSilence() uint32 {
if x != nil {
return x.Silence
}
return 0
}
func (x *InfoReply_Data) GetCoins() uint32 {
if x != nil {
return x.Coins
}
return 0
}
func (x *InfoReply_Data) GetFansBadge() bool {
if x != nil {
return x.FansBadge
}
return false
}
func (x *InfoReply_Data) GetIsFollowed() bool {
if x != nil {
return x.IsFollowed
}
return false
}
func (x *InfoReply_Data) GetTopPhoto() string {
if x != nil {
return x.TopPhoto
}
return ""
}
func (x *InfoReply_Data) GetBirthday() string {
if x != nil {
return x.Birthday
}
return ""
}
func (x *InfoReply_Data) GetTags() []string {
if x != nil {
return x.Tags
}
return nil
}
func (x *InfoReply_Data) GetIsSeniorMember() uint32 {
if x != nil {
return x.IsSeniorMember
}
return 0
}
func (x *InfoReply_Data) GetMcnInfo() string {
if x != nil {
return x.McnInfo
}
return ""
}
func (x *InfoReply_Data) GetGaiaResType() uint32 {
if x != nil {
return x.GaiaResType
}
return 0
}
func (x *InfoReply_Data) GetGaiaData() string {
if x != nil {
return x.GaiaData
}
return ""
}
func (x *InfoReply_Data) GetIsRisk() bool {
if x != nil {
return x.IsRisk
}
return false
}
var File_api_proto protoreflect.FileDescriptor
var file_api_proto_rawDesc = []byte{
0x0a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61, 0x70, 0x69,
0x22, 0x1f, 0x0a, 0x0b, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x69,
0x64, 0x22, 0xdf, 0x01, 0x0a, 0x09, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12,
0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63,
0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x27, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65,
0x70, 0x6c, 0x79, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x82,
0x01, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x6d, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x6f, 0x6c,
0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x66, 0x6f,
0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x77, 0x68, 0x69, 0x73, 0x70,
0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x77, 0x68, 0x69, 0x73, 0x70, 0x65,
0x72, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x05, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x6f, 0x6c, 0x6c, 0x6f,
0x77, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x66, 0x6f, 0x6c, 0x6c, 0x6f,
0x77, 0x65, 0x72, 0x22, 0x1f, 0x0a, 0x0b, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52,
0x03, 0x75, 0x69, 0x64, 0x22, 0xba, 0x05, 0x0a, 0x09, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x70,
0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05,
0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x27, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61,
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x6e, 0x66,
0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74,
0x61, 0x1a, 0xdd, 0x04, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x69,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x6d, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73,
0x65, 0x78, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x61, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
0x52, 0x04, 0x66, 0x61, 0x63, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x66, 0x61, 0x63, 0x65, 0x5f, 0x6e,
0x66, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x66, 0x61, 0x63, 0x65, 0x4e, 0x66,
0x74, 0x12, 0x22, 0x0a, 0x0d, 0x66, 0x61, 0x63, 0x65, 0x5f, 0x6e, 0x66, 0x74, 0x5f, 0x74, 0x79,
0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x66, 0x61, 0x63, 0x65, 0x4e, 0x66,
0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x6e, 0x18, 0x07, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x73, 0x69, 0x67, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x6e,
0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x14, 0x0a,
0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x6c, 0x65,
0x76, 0x65, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x6a, 0x6f, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x18,
0x0a, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6a, 0x6f, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12,
0x14, 0x0a, 0x05, 0x6d, 0x6f, 0x72, 0x61, 0x6c, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05,
0x6d, 0x6f, 0x72, 0x61, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, 0x6c, 0x65, 0x6e, 0x63, 0x65,
0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x73, 0x69, 0x6c, 0x65, 0x6e, 0x63, 0x65, 0x12,
0x14, 0x0a, 0x05, 0x63, 0x6f, 0x69, 0x6e, 0x73, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05,
0x63, 0x6f, 0x69, 0x6e, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x66, 0x61, 0x6e, 0x73, 0x5f, 0x62, 0x61,
0x64, 0x67, 0x65, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x66, 0x61, 0x6e, 0x73, 0x42,
0x61, 0x64, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x73, 0x5f, 0x66, 0x6f, 0x6c, 0x6c, 0x6f,
0x77, 0x65, 0x64, 0x18, 0x15, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x69, 0x73, 0x46, 0x6f, 0x6c,
0x6c, 0x6f, 0x77, 0x65, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x74, 0x6f, 0x70, 0x5f, 0x70, 0x68, 0x6f,
0x74, 0x6f, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x74, 0x6f, 0x70, 0x50, 0x68, 0x6f,
0x74, 0x6f, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x69, 0x72, 0x74, 0x68, 0x64, 0x61, 0x79, 0x18, 0x1a,
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x69, 0x72, 0x74, 0x68, 0x64, 0x61, 0x79, 0x12, 0x12,
0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x1d, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61,
0x67, 0x73, 0x12, 0x28, 0x0a, 0x10, 0x69, 0x73, 0x5f, 0x73, 0x65, 0x6e, 0x69, 0x6f, 0x72, 0x5f,
0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x69, 0x73,
0x53, 0x65, 0x6e, 0x69, 0x6f, 0x72, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08,
0x6d, 0x63, 0x6e, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x20, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
0x6d, 0x63, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x22, 0x0a, 0x0d, 0x67, 0x61, 0x69, 0x61, 0x5f,
0x72, 0x65, 0x73, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x21, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b,
0x67, 0x61, 0x69, 0x61, 0x52, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x67,
0x61, 0x69, 0x61, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x22, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x67, 0x61, 0x69, 0x61, 0x44, 0x61, 0x74, 0x61, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x73, 0x5f, 0x72,
0x69, 0x73, 0x6b, 0x18, 0x23, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x52, 0x69, 0x73,
0x6b, 0x32, 0x74, 0x0a, 0x07, 0x42, 0x69, 0x6c, 0x69, 0x41, 0x50, 0x49, 0x12, 0x31, 0x0a, 0x0b,
0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x61, 0x70,
0x69, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e,
0x61, 0x70, 0x69, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12,
0x36, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x42, 0x61, 0x73, 0x69, 0x63, 0x49,
0x6e, 0x66, 0x6f, 0x12, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x6e, 0x66, 0x6f,
0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_api_proto_rawDescOnce sync.Once
file_api_proto_rawDescData = file_api_proto_rawDesc
)
func file_api_proto_rawDescGZIP() []byte {
file_api_proto_rawDescOnce.Do(func() {
file_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_proto_rawDescData)
})
return file_api_proto_rawDescData
}
var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_api_proto_goTypes = []interface{}{
(*StatRequest)(nil), // 0: api.StatRequest
(*StatReply)(nil), // 1: api.StatReply
(*InfoRequest)(nil), // 2: api.InfoRequest
(*InfoReply)(nil), // 3: api.InfoReply
(*StatReply_Data)(nil), // 4: api.StatReply.Data
(*InfoReply_Data)(nil), // 5: api.InfoReply.Data
}
var file_api_proto_depIdxs = []int32{
4, // 0: api.StatReply.data:type_name -> api.StatReply.Data
5, // 1: api.InfoReply.data:type_name -> api.InfoReply.Data
0, // 2: api.BiliAPI.GetUserStat:input_type -> api.StatRequest
2, // 3: api.BiliAPI.GetUserBasicInfo:input_type -> api.InfoRequest
1, // 4: api.BiliAPI.GetUserStat:output_type -> api.StatReply
3, // 5: api.BiliAPI.GetUserBasicInfo:output_type -> api.InfoReply
4, // [4:6] is the sub-list for method output_type
2, // [2:4] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_api_proto_init() }
func file_api_proto_init() {
if File_api_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*StatRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*StatReply); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_api_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InfoRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_api_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InfoReply); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_api_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*StatReply_Data); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_api_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InfoReply_Data); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_api_proto_rawDesc,
NumEnums: 0,
NumMessages: 6,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_api_proto_goTypes,
DependencyIndexes: file_api_proto_depIdxs,
MessageInfos: file_api_proto_msgTypes,
}.Build()
File_api_proto = out.File
file_api_proto_rawDesc = nil
file_api_proto_goTypes = nil
file_api_proto_depIdxs = nil
}

2269
rpc/pb/bili_api.pb.go Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.8
// source: api.proto
// source: bili_api.proto
package pb
@ -24,6 +24,8 @@ const _ = grpc.SupportPackageIsVersion7
type BiliAPIClient interface {
GetUserStat(ctx context.Context, in *StatRequest, opts ...grpc.CallOption) (*StatReply, error)
GetUserBasicInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoReply, error)
SearchVideo(ctx context.Context, in *SearchVideoReq, opts ...grpc.CallOption) (*SearchVideoReply, error)
SearchLiveRoom(ctx context.Context, in *SearchLiveRoomReq, opts ...grpc.CallOption) (*SearchLiveRoomReply, error)
}
type biliAPIClient struct {
@ -52,12 +54,32 @@ func (c *biliAPIClient) GetUserBasicInfo(ctx context.Context, in *InfoRequest, o
return out, nil
}
func (c *biliAPIClient) SearchVideo(ctx context.Context, in *SearchVideoReq, opts ...grpc.CallOption) (*SearchVideoReply, error) {
out := new(SearchVideoReply)
err := c.cc.Invoke(ctx, "/api.BiliAPI/SearchVideo", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *biliAPIClient) SearchLiveRoom(ctx context.Context, in *SearchLiveRoomReq, opts ...grpc.CallOption) (*SearchLiveRoomReply, error) {
out := new(SearchLiveRoomReply)
err := c.cc.Invoke(ctx, "/api.BiliAPI/SearchLiveRoom", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// BiliAPIServer is the server API for BiliAPI service.
// All implementations must embed UnimplementedBiliAPIServer
// for forward compatibility
type BiliAPIServer interface {
GetUserStat(context.Context, *StatRequest) (*StatReply, error)
GetUserBasicInfo(context.Context, *InfoRequest) (*InfoReply, error)
SearchVideo(context.Context, *SearchVideoReq) (*SearchVideoReply, error)
SearchLiveRoom(context.Context, *SearchLiveRoomReq) (*SearchLiveRoomReply, error)
mustEmbedUnimplementedBiliAPIServer()
}
@ -71,6 +93,12 @@ func (UnimplementedBiliAPIServer) GetUserStat(context.Context, *StatRequest) (*S
func (UnimplementedBiliAPIServer) GetUserBasicInfo(context.Context, *InfoRequest) (*InfoReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetUserBasicInfo not implemented")
}
func (UnimplementedBiliAPIServer) SearchVideo(context.Context, *SearchVideoReq) (*SearchVideoReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method SearchVideo not implemented")
}
func (UnimplementedBiliAPIServer) SearchLiveRoom(context.Context, *SearchLiveRoomReq) (*SearchLiveRoomReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method SearchLiveRoom not implemented")
}
func (UnimplementedBiliAPIServer) mustEmbedUnimplementedBiliAPIServer() {}
// UnsafeBiliAPIServer may be embedded to opt out of forward compatibility for this service.
@ -120,6 +148,42 @@ func _BiliAPI_GetUserBasicInfo_Handler(srv interface{}, ctx context.Context, dec
return interceptor(ctx, in, info, handler)
}
func _BiliAPI_SearchVideo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchVideoReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(BiliAPIServer).SearchVideo(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/api.BiliAPI/SearchVideo",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BiliAPIServer).SearchVideo(ctx, req.(*SearchVideoReq))
}
return interceptor(ctx, in, info, handler)
}
func _BiliAPI_SearchLiveRoom_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchLiveRoomReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(BiliAPIServer).SearchLiveRoom(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/api.BiliAPI/SearchLiveRoom",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BiliAPIServer).SearchLiveRoom(ctx, req.(*SearchLiveRoomReq))
}
return interceptor(ctx, in, info, handler)
}
// BiliAPI_ServiceDesc is the grpc.ServiceDesc for BiliAPI service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -135,7 +199,15 @@ var BiliAPI_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetUserBasicInfo",
Handler: _BiliAPI_GetUserBasicInfo_Handler,
},
{
MethodName: "SearchVideo",
Handler: _BiliAPI_SearchVideo_Handler,
},
{
MethodName: "SearchLiveRoom",
Handler: _BiliAPI_SearchLiveRoom_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "api.proto",
Metadata: "bili_api.proto",
}

View File

@ -81,7 +81,6 @@ func (s *Service) GetUserBasicInfo(ctx context.Context, req *pb.InfoRequest) (*p
Data: nil,
}, err
}
if bodyObj.Code != 0 {
fmt.Println("bad request: " + bodyObj.Message)
return &pb.InfoReply{
@ -93,7 +92,15 @@ func (s *Service) GetUserBasicInfo(ctx context.Context, req *pb.InfoRequest) (*p
// interface映射到结构体
data := &pb.InfoReply_Data{}
err = mapstructure.Decode(bodyObj.Data, data)
dataBytes, err := json.Marshal(bodyObj.Data)
if err != nil {
return &pb.InfoReply{
Code: 500,
Msg: err.Error(),
Data: nil,
}, err
}
err = json.Unmarshal(dataBytes, data)
if err != nil {
return &pb.InfoReply{
Code: 500,
@ -109,6 +116,94 @@ func (s *Service) GetUserBasicInfo(ctx context.Context, req *pb.InfoRequest) (*p
}
func (s *Service) SearchVideo(ctx context.Context, req *pb.SearchVideoReq) (*pb.SearchVideoReply, error) {
body, err := biliapi.SearchVideo(&biliapi.SearchParams{
Keyword: req.Keyword,
Order: req.Order,
Page: uint(req.Page),
Cookie: req.Cookie,
})
bodyObj := biliapi.Root{}
err = json.Unmarshal(body, &bodyObj)
if err != nil {
fmt.Println("bad request: " + err.Error())
return &pb.SearchVideoReply{
Code: 400,
Msg: err.Error(),
Data: nil,
}, err
}
if bodyObj.Code != 0 {
fmt.Println("bad request: " + bodyObj.Message)
return &pb.SearchVideoReply{
Code: int32(bodyObj.Code),
Msg: bodyObj.Message,
Data: nil,
}, err
}
// interface映射到结构体
data := &pb.SearchVideoReply_Data{}
err = mapstructure.Decode(bodyObj.Data, data)
if err != nil {
return &pb.SearchVideoReply{
Code: 500,
Msg: err.Error(),
Data: nil,
}, err
}
return &pb.SearchVideoReply{
Code: 200,
Msg: "",
Data: data,
}, nil
}
func (s *Service) SearchLiveRoom(ctx context.Context, req *pb.SearchLiveRoomReq) (*pb.SearchLiveRoomReply, error) {
body, err := biliapi.SearchLiveRoom(&biliapi.SearchParams{
Keyword: req.Keyword,
Order: req.Order,
Page: uint(req.Page),
Cookie: req.Cookie,
})
bodyObj := biliapi.Root{}
err = json.Unmarshal(body, &bodyObj)
if err != nil {
fmt.Println("bad request: " + err.Error())
return &pb.SearchLiveRoomReply{
Code: 400,
Msg: err.Error(),
Data: nil,
}, err
}
if bodyObj.Code != 0 {
fmt.Println("bad request: " + bodyObj.Message)
return &pb.SearchLiveRoomReply{
Code: int32(bodyObj.Code),
Msg: bodyObj.Message,
Data: nil,
}, err
}
// interface映射到结构体
data := &pb.SearchLiveRoomReply_Data{}
err = mapstructure.Decode(bodyObj.Data, data)
if err != nil {
return &pb.SearchLiveRoomReply{
Code: 500,
Msg: err.Error(),
Data: nil,
}, err
}
return &pb.SearchLiveRoomReply{
Code: 200,
Msg: "",
Data: data,
}, nil
}
func RegisterServices(s *grpc.Server) {
pb.RegisterBiliAPIServer(s, &Service{})
reflection.Register(s)