实现通过直播间获取furry等

用户信息新增直播间房间号字段

能用了,但不是很好用
This commit is contained in:
Eigeen 2022-12-25 18:06:03 +08:00
parent 511d889557
commit 4f44e60168
24 changed files with 2919 additions and 783 deletions

2
.gitignore vendored
View File

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

1
go.mod
View File

@ -24,6 +24,7 @@ require (
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/robfig/cron/v3 v3.0.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect

2
go.sum
View File

@ -120,6 +120,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E=
github.com/robfig/cron/v3 v3.0.0/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=

17
main.go
View File

@ -3,9 +3,26 @@ package main
import (
"github.com/eigeen/furryboard/spider-scheduler/pkg/conf"
"github.com/eigeen/furryboard/spider-scheduler/pkg/log"
"github.com/eigeen/furryboard/spider-scheduler/pkg/task"
"github.com/robfig/cron/v3"
"os"
"os/signal"
)
func main() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, os.Kill)
log.InitLogger(false)
conf.InitConfig("config.toml")
c := cron.New()
c.AddFunc("@every 10m", task.SearchUpsFromVideo)
c.AddFunc("@every 10m", task.SearchUpsFromLiveRoom)
c.AddFunc("@daily", task.UpdateUserInfo)
c.AddFunc("@daily", task.UpdateFans)
c.Start()
log.Logger().Infof("定时任务已启动")
sig := <-sigChan
log.Logger().Infof("Signal: %s", sig)
}

View File

@ -29,6 +29,7 @@ type Database struct {
type SpiderCore struct {
Host string `toml:"host" default:"localhost"`
Port uint16 `toml:"port" default:"9996"`
BiliCookie string `toml:"bili_cookie"`
}
var (

View File

@ -67,6 +67,8 @@ func autoMigrate() {
var err error
err = db.AutoMigrate(&model.Changelog{})
err = db.AutoMigrate(&model.Fans{})
err = db.AutoMigrate(&model.Metadata{})
err = db.AutoMigrate(&model.LiveRoom{})
if err != nil {
return
}

View File

@ -1,10 +1,20 @@
package model
const (
StatusOK = iota
StatusIgnore
StatusAccountClosed
StatusPendingVideo
StatusPendingLive
StatusUntracked
)
type Furry struct {
ID uint `gorm:"primaryKey"`
UID uint `gorm:"uniqueIndex;not null"`
Name string `gorm:"index;not null;default:''"`
Status int `gorm:"index;not null;default:0"`
LiveRoomID uint `gorm:"index;not null;default:0"`
}
func (Furry) TableName() string {

View File

@ -0,0 +1,8 @@
package model
type LiveRoom struct {
ID uint `gorm:"primaryKey"`
RoomID uint `gorm:"uniqueIndex;not null"`
Title string `gorm:"not null;default:''"`
Tags string `gorm:"not null;default:''"`
}

View File

@ -0,0 +1,7 @@
package model
type Metadata struct {
ID uint `gorm:"primaryKey"`
Key string `gorm:"uniqueIndex;not null"`
Value string `gorm:"not null;default:''"`
}

View File

@ -1,5 +1,11 @@
package exception
/**
4xxx 数据库异常
5xxx 业务逻辑异常
6xxx 网络API异常
*/
func InternalError(msg string) BaseError {
shortMsg := "系统异常,请联系管理员"
return BaseError{Code: 500, Msg: msg, ShortMsg: shortMsg}
@ -7,20 +13,30 @@ func InternalError(msg string) BaseError {
func ErrFetchUserInfo(msg string) BaseError {
shortMsg := "用户信息获取失败"
return BaseError{Code: 4001, Msg: msg, ShortMsg: shortMsg}
}
func ErrFetchStat(msg string) BaseError {
shortMsg := "获取用户统计信息失败"
return BaseError{Code: 4002, Msg: msg, ShortMsg: shortMsg}
}
func ErrUserMismatch(msg string) BaseError {
shortMsg := "操作的两个用户不匹配"
return BaseError{Code: 5001, Msg: msg, ShortMsg: shortMsg}
}
func ErrFetchFurries(msg string) BaseError {
shortMsg := "获取Furry列表失败"
return BaseError{Code: 5002, Msg: msg, ShortMsg: shortMsg}
return BaseError{Code: 6001, Msg: msg, ShortMsg: shortMsg}
}
func ErrUserMismatch(msg string) BaseError {
shortMsg := "操作的两个用户不匹配"
return BaseError{Code: 5003, Msg: msg, ShortMsg: shortMsg}
func ErrSearchVideo(msg string) BaseError {
shortMsg := "分类视频搜索失败"
return BaseError{Code: 6002, Msg: msg, ShortMsg: shortMsg}
}
func ErrFetchStat(msg string) BaseError {
shortMsg := "获取用户统计信息失败"
return BaseError{Code: 5004, Msg: msg, ShortMsg: shortMsg}
func ErrSearchLiveRoom(msg string) BaseError {
shortMsg := "直播间搜索失败"
return BaseError{Code: 6003, Msg: msg, ShortMsg: shortMsg}
}

View File

@ -10,3 +10,4 @@
[spider_core]
host = "localhost"
port = 9101
bili_cookie = "buvid3=E114B569-ECF7-50D6-5874-7221C956F4F323116infoc; i-wanna-go-back=-1; _uuid=9DC109D51-C164-D1A8-D18D-CDB410A6B733223200infoc; buvid4=2EFA9D48-F352-9314-066E-800EAD1A3B3024163-022061118-7XDfT9HnZ75xcCl6GNqbKvvAaotbbCqK1dff9AggS2AFysI2RsiDgg%3D%3D; CURRENT_BLACKGAP=0; blackside_state=0; nostalgia_conf=-1; buvid_fp_plain=undefined; b_ut=5; LIVE_BUVID=AUTO2216549597211800; hit-dyn-v2=1; b_nut=100; fingerprint3=8b45c9c8e2c3bde2334046651927bc11; CURRENT_QUALITY=80; hit-new-style-dyn=0; CURRENT_FNVAL=4048; rpdid=|(J~R|~)~|Y)0J'uYY)Y|JmkY; dy_spec_agreed=1; fingerprint=64f6f507fa149d279783afea30316e2b; SESSDATA=0312b6e2%2C1687167210%2C5c48e%2Ac1; bili_jct=12bdeb674ff87c20afd2d245128d6734; DedeUserID=90931399; DedeUserID__ckMd5=507c5d481d60b7bb; sid=5n2lvshx; buvid_fp=64f6f507fa149d279783afea30316e2b; bp_t_offset_90931399=742134893995098144; PVID=2; share_source_origin=QQ; bsource=share_source_qqchat; b_lsid=4578914A_1853786E484; innersign=0"

35
pkg/logic/liveroom.go Normal file
View File

@ -0,0 +1,35 @@
package logic
import (
"github.com/eigeen/furryboard/spider-scheduler/pkg/dao"
"github.com/eigeen/furryboard/spider-scheduler/pkg/dao/model"
)
func GetLiveRoomsFromDB(roomIDs *[]uint64) ([]*model.LiveRoom, error) {
var liveRooms []*model.LiveRoom
tx := dao.DB().Model(&model.LiveRoom{}).Where("room_id in (?)", *roomIDs).Find(&liveRooms)
return liveRooms, tx.Error
}
//
//func UpdateLiveRoom(infos []*pb.InfoReply_Data) (int, error) {
// // 获取数据库里已有的info
// var roomIDs []uint64
// for _, info := range infos {
// if info.LiveRoom == nil {
// continue
// }
// roomIDs = append(roomIDs, info.LiveRoom.Roomid)
// }
// oldInfos, err := GetLiveRoomsFromDB(&roomIDs)
//
// err = dao.DB().Transaction(func(tx *gorm.DB) error {
// for i, info := range infos {
// if oldInfos[i].Title != info.LiveRoom
// }
// })
// if err != nil {
// return
// }
//
//}

42
pkg/logic/metadata.go Normal file
View File

@ -0,0 +1,42 @@
package logic
import (
"errors"
"github.com/eigeen/furryboard/spider-scheduler/pkg/dao"
"github.com/eigeen/furryboard/spider-scheduler/pkg/dao/model"
"gorm.io/gorm"
)
func AddOrUpdateMetadata(key, value string) error {
metadata, err := GetMetadata(key)
if err != nil {
return err
}
var tx *gorm.DB
if metadata != nil {
metadata.Value = value
tx = dao.DB().Save(metadata)
} else {
tx = dao.DB().Create(&model.Metadata{
Key: key,
Value: value,
})
}
return tx.Error
}
func DeleteMetadata(key string) error {
tx := dao.DB().Model(&model.Metadata{}).Delete("key = ?", key)
return tx.Error
}
func GetMetadata(key string) (*model.Metadata, error) {
var metadata model.Metadata
tx := dao.DB().Model(&model.Metadata{}).Where("key = ?", key).First(&metadata)
err := tx.Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return &metadata, tx.Error
}

148
pkg/logic/search.go Normal file
View File

@ -0,0 +1,148 @@
package logic
import (
"context"
"fmt"
"github.com/eigeen/furryboard/spider-scheduler/pkg/dao"
"github.com/eigeen/furryboard/spider-scheduler/pkg/dao/model"
"github.com/eigeen/furryboard/spider-scheduler/pkg/exception"
"github.com/eigeen/furryboard/spider-scheduler/rpc"
"github.com/eigeen/furryboard/spider-scheduler/rpc/pb"
"gorm.io/gorm"
"time"
)
// SearchNewestVideos b站搜索 最新发布排序 仅搜索视频
func SearchNewestVideos(keyword, cookie string, page uint) ([]*pb.SearchVideoResult, error) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
info, err := rpc.SpiderCore().SearchVideo(ctx, &pb.SearchVideoReq{
Keyword: keyword,
Order: "pubdate",
Page: uint32(page),
Cookie: cookie,
})
if err != nil {
return nil, exception.InternalError("获取最新视频搜索信息失败:" + err.Error())
}
if info.Code != 200 { // -400 -411请求被拦截
if info.Msg == "" {
info.Msg = "Unknown"
}
return nil, exception.ErrSearchVideo(
fmt.Sprintf("最新视频搜索信息[keyword=%s]获取失败:%s(Code: %d)", keyword, info.Msg, info.Code))
}
return info.Data.Result, nil
}
func UpdateVideoCheckpoint(value string) error {
return AddOrUpdateMetadata("SearchVideoCheckpoint", value)
}
// SearchLiveRooms b站搜索 默认排序 仅搜索直播间
func SearchLiveRooms(keyword, cookie string, page uint) ([]*pb.SearchLiveRoomResult, error) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
info, err := rpc.SpiderCore().SearchLiveRoom(ctx, &pb.SearchLiveRoomReq{
Keyword: keyword,
Order: "online",
Page: uint32(page),
Cookie: cookie,
})
if err != nil {
return nil, exception.InternalError("获取直播间搜索信息失败:" + err.Error())
}
if info.Code != 200 {
if info.Msg == "" {
info.Msg = "Unknown"
}
return nil, exception.ErrSearchLiveRoom(
fmt.Sprintf("直播间搜索信息[keyword=%s]获取失败:%s(Code: %d)", keyword, info.Msg, info.Code))
}
return info.Data.Result, nil
}
func GetLiveRoomPageNum(keyword, cookie string) (int, error) {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
info, err := rpc.SpiderCore().SearchLiveRoom(ctx, &pb.SearchLiveRoomReq{
Keyword: keyword,
Order: "online",
Page: 1,
Cookie: cookie,
})
if err != nil {
return 0, exception.InternalError("获取直播间搜索信息失败:" + err.Error())
}
if info.Code != 200 {
if info.Msg == "" {
info.Msg = "Unknown"
}
return 0, exception.ErrSearchLiveRoom(
fmt.Sprintf("直播间搜索信息[keyword=%s]获取失败:%s(Code: %d)", keyword, info.Msg, info.Code))
}
return int(info.Data.NumPages), nil
}
// GetLiveRoomByRoomID 通过room_id从数据库查询直播间信息 返回值不为nil
func GetLiveRoomByRoomID(roomID uint64) (*model.LiveRoom, error) {
var room model.LiveRoom
tx := dao.DB().Model(&model.LiveRoom{}).Where("room_id = ?", roomID).Find(&room)
if tx.Error != nil {
return &room, tx.Error
}
return &room, nil
}
func UpdateLiveRoomInfo(rooms []*pb.SearchLiveRoomResult) (int, error) {
err := dao.DB().Transaction(func(tx *gorm.DB) error {
for _, room := range rooms {
roomInfo, err := GetLiveRoomByRoomID(room.Roomid)
if err != nil {
return err
}
roomInfo.RoomID = uint(room.Roomid)
roomInfo.Title = room.Title
roomInfo.Tags = room.Tags
if err = tx.Save(roomInfo).Error; err != nil {
return err
}
}
return nil
})
if err != nil {
return 0, err
}
err = dao.DB().Transaction(func(tx *gorm.DB) error {
for _, room := range rooms {
exists, err := IsUserExistsByUID(uint(room.Uid))
if err != nil {
return err
}
if !exists {
tx.Create(&model.Furry{
UID: uint(room.Uid),
Name: room.Uname,
Status: model.StatusPendingLive,
LiveRoomID: uint(room.Roomid),
})
continue
}
if err = tx.Model(&model.Furry{}).Where("uid = ?", room.Uid).Update("live_room_id", room.Roomid).Error; err != nil {
return err
}
}
return nil
})
if err != nil {
return 0, err
}
return len(rooms), nil
}

35
pkg/logic/search_test.go Normal file
View File

@ -0,0 +1,35 @@
package logic
import (
"github.com/eigeen/furryboard/spider-scheduler/pkg/conf"
"testing"
)
func TestSearchNewestVideos(t *testing.T) {
BeforeTesting()
videos, err := SearchNewestVideos("furry", conf.Conf.SpiderCore.BiliCookie, 1)
if err != nil {
t.Error(err)
}
t.Log(len(videos))
t.Log(videos[0])
}
func TestGetLiveRoomPageNum(t *testing.T) {
BeforeTesting()
num, err := GetLiveRoomPageNum("furry", conf.Conf.SpiderCore.BiliCookie)
if err != nil {
t.Error(err)
}
t.Log(num)
}
func TestSearchLiveRooms(t *testing.T) {
BeforeTesting()
rooms, err := SearchLiveRooms("furry", conf.Conf.SpiderCore.BiliCookie, 1)
if err != nil {
t.Error(err)
}
t.Log(len(rooms))
t.Log(rooms[0])
}

View File

@ -16,11 +16,11 @@ import (
"time"
)
// GetUsers 分页获取用户信息(数据库)
func GetUsers(page, pageSize int) ([]*model.Furry, error) {
// GetValidUsers 分页获取用户信息(数据库)
func GetValidUsers(page, pageSize int) ([]*model.Furry, error) {
// 分页查询
var furries []*model.Furry
tx := dao.DB().Offset((page - 1) * pageSize).Limit(pageSize).Find(&furries)
tx := dao.DB().Where("status = 0").Offset((page - 1) * pageSize).Limit(pageSize).Find(&furries)
if tx.Error != nil {
return nil, exception.ErrFetchFurries("分页获取Furry列表时失败" + tx.Error.Error())
}
@ -45,6 +45,20 @@ func GetUserInfoByUID(uid uint) (*pb.InfoReply_Data, error) {
return info.Data, nil
}
// IsUserExistsByUID 通过UID判断用户是否存在数据库
func IsUserExistsByUID(uid uint) (bool, error) {
var count int64
tx := dao.DB().Model(&model.Furry{}).Where("uid = ?", uid).Count(&count)
if tx.Error != nil {
return false, exception.ErrFetchFurries(fmt.Sprintf("查找用户[%d]时发生错误:%s", uid, tx.Error.Error()))
}
if count == 0 {
return false, nil
} else {
return true, nil
}
}
// BatchGetUserInfo 批量获取用户基础信息
func BatchGetUserInfo(userIds *[]uint) []*pb.InfoReply_Data {
poolSize := 8
@ -82,8 +96,8 @@ func BatchGetUserInfo(userIds *[]uint) []*pb.InfoReply_Data {
func UpdateUserInfo(users []*model.Furry, infos []*pb.InfoReply_Data) (int, error) {
// 以UID为索引转换为map
infoMap := make(map[uint]*pb.InfoReply_Data)
for _, i := range infos {
infoMap[uint(i.Mid)] = i
for _, info := range infos {
infoMap[uint(info.Mid)] = info
}
// 检测变化
changelogs, changes, err := createChangelogs(users, infos)
@ -120,7 +134,7 @@ func userInfoDiff(user *model.Furry, info *pb.InfoReply_Data) (*model.Changelog,
return nil, nil, exception.ErrUserMismatch(fmt.Sprintf("对比用户ID不匹配%d和%d", user.UID, info.Mid))
}
changelog := model.Changelog{
Operation: "UpdateName",
Operation: "",
Target: strconv.FormatUint(uint64(user.UID), 10),
Result: "",
}
@ -129,9 +143,15 @@ func userInfoDiff(user *model.Furry, info *pb.InfoReply_Data) (*model.Changelog,
}
if user.Name != info.Name {
result, _ := json.Marshal(map[string]string{"previous_name": user.Name, "new_name": info.Name})
changelog.Operation = "UpdateName"
changelog.Result = string(result)
updated.Name = info.Name
return &changelog, &updated, nil
} else if info.LiveRoom != nil && user.LiveRoomID != uint(info.LiveRoom.Roomid) {
updated.LiveRoomID = uint(info.LiveRoom.Roomid)
changelog.Operation = "AddLiveRoom"
changelog.Result = strconv.FormatUint(info.LiveRoom.Roomid, 10)
return &changelog, &updated, nil
} else {
return nil, nil, nil
}
@ -238,5 +258,9 @@ func UpdateFansToDB(stats []*pb.StatReply_Data) (int, error) {
return 0, err
}
return len(stats), nil
}
func AddUser(user *model.Furry) error {
tx := dao.DB().Create(user)
return tx.Error
}

View File

@ -10,3 +10,4 @@
[spider_core]
host = "localhost"
port = 9101
bili_cookie = "buvid3=E114B569-ECF7-50D6-5874-7221C956F4F323116infoc; i-wanna-go-back=-1; _uuid=9DC109D51-C164-D1A8-D18D-CDB410A6B733223200infoc; buvid4=2EFA9D48-F352-9314-066E-800EAD1A3B3024163-022061118-7XDfT9HnZ75xcCl6GNqbKvvAaotbbCqK1dff9AggS2AFysI2RsiDgg%3D%3D; CURRENT_BLACKGAP=0; blackside_state=0; nostalgia_conf=-1; buvid_fp_plain=undefined; b_ut=5; LIVE_BUVID=AUTO2216549597211800; hit-dyn-v2=1; b_nut=100; fingerprint3=8b45c9c8e2c3bde2334046651927bc11; CURRENT_QUALITY=80; hit-new-style-dyn=0; CURRENT_FNVAL=4048; rpdid=|(J~R|~)~|Y)0J'uYY)Y|JmkY; dy_spec_agreed=1; fingerprint=64f6f507fa149d279783afea30316e2b; SESSDATA=0312b6e2%2C1687167210%2C5c48e%2Ac1; bili_jct=12bdeb674ff87c20afd2d245128d6734; DedeUserID=90931399; DedeUserID__ckMd5=507c5d481d60b7bb; sid=5n2lvshx; buvid_fp=64f6f507fa149d279783afea30316e2b; bp_t_offset_90931399=742134893995098144; PVID=2; share_source_origin=QQ; bsource=share_source_qqchat; b_lsid=4578914A_1853786E484; innersign=0"

46
pkg/task/liveroom.go Normal file
View File

@ -0,0 +1,46 @@
package task
//func UpdateLiveRoomInfo() {
// // 预查询数量
// // TODO: 预查询数量和分页策略功能可复用
// var count int64
// tx := dao.DB().Model(&model.Furry{}).Count(&count)
// if tx.Error != nil {
// err := exception.ErrFetchFurries("获取furries数量失败" + tx.Error.Error())
// log.Logger().Errorf("获取furries数量失败%s", err)
// return
// }
//
// pageSize := 32
// maxPage := int(math.Ceil(float64(count) / float64(pageSize)))
// for page := 0; page <= maxPage; page++ {
// // 获取目标用户列表(分页)
// users, err := logic.GetUsers(page, pageSize)
// if err != nil {
// log.Logger().Errorf("获取用户列表时发生错误:%s", err)
// continue
// }
// // 已获取完毕
// if users == nil {
// return
// }
// // 抽取uid列表
// var uids []uint
// for _, user := range users {
// uids = append(uids, user.UID)
// }
// // 通过API获取用户信息
// infos := logic.BatchGetUserInfo(&uids)
//
// // 更新live_rooms表
// c, err := logic.UpdateLiveRoom(infos)
// if err != nil {
// log.Logger().Errorf("更新数据时发生错误:%s", err)
// continue
// }
// log.Logger().Infof("成功更新了%d个用户信息", c)
// // delay
// time.Sleep(2 * time.Second)
// }
//
//}

141
pkg/task/search.go Normal file
View File

@ -0,0 +1,141 @@
package task
import (
"github.com/eigeen/furryboard/spider-scheduler/pkg/conf"
"github.com/eigeen/furryboard/spider-scheduler/pkg/dao/model"
"github.com/eigeen/furryboard/spider-scheduler/pkg/log"
"github.com/eigeen/furryboard/spider-scheduler/pkg/logic"
"time"
)
// SearchUpsFromVideo
// 通过关键词进行视频搜索的方式获取用户
// 新用户即写入用户表状态为StatusPending
//
// 策略每10分钟抓取前3页每页42条视频若抓取的内容中存在
// 一条视频与上次抓取内容的最后一条视频相同,则判断为已到达结尾
func SearchUpsFromVideo() {
// 获取最后一次抓取的记录
meta, err := logic.GetMetadata("SearchVideoCheckpoint")
if err != nil {
log.Logger().Warnf("获取上一次视频抓取记录失败:%s", err)
err = nil
}
var history = ""
if meta != nil {
history = meta.Value
}
var newHistory = ""
// 逐页获取判断
for page := 1; page <= 3; page++ {
videos, err := logic.SearchNewestVideos("furry", conf.Conf.SpiderCore.BiliCookie, 1)
if err != nil {
log.Logger().Errorf("搜索视频失败:%s", err)
return
}
if len(videos) == 0 {
log.Logger().Info("视频搜索已达末页")
break
}
// 第一次获取将第一个视频bv号作为newHistory
if page == 1 {
newHistory = videos[0].Bvid
}
// 从videos列表抽取视频bv号 map索引
var bvids = make(map[string]int, 0)
for i, video := range videos {
bvids[video.Bvid] = i
}
// 先判断是否到达上一次结尾
var historyPos = 42
if i, ok := bvids[history]; ok {
historyPos = i
}
// 防越界
if len(videos) < historyPos {
historyPos = len(videos)
}
// 先判断再抽取uid列表节省数据库资源
// 从videos列表抽取uid(mid) map去重
var uids = make(map[uint64]*model.Furry, 0)
for i := 0; i < historyPos; i++ {
uids[videos[i].Mid] = &model.Furry{
UID: uint(videos[i].Mid),
Name: videos[i].Author,
Status: model.StatusPendingVideo,
}
}
// 逐个判断用户是否存在于数据库,不存在则新增
for uid, user := range uids {
exists, err := logic.IsUserExistsByUID(uint(uid))
if err != nil {
log.Logger().Warnf("判断用户存在性时发生错误:%s", err)
continue
}
if !exists {
err = logic.AddUser(user)
if err != nil {
log.Logger().Warnf("新增用户[%d]时失败:%s", uid, err)
continue
}
log.Logger().Infof("通过视频搜索新增用户:%s(%d)", user.Name, uid)
}
}
// 已到达上一次结尾,中断循环,否则继续获取下一页
if historyPos != 42 {
break
}
time.Sleep(1 * time.Second)
}
// 更新history
err = logic.UpdateVideoCheckpoint(newHistory)
if err != nil {
log.Logger().Warnf("更新Metadata: SearchVideoCheckpoint时发生错误%s", err)
}
}
func SearchUpsFromLiveRoom() {
// TODO: 多关键词可复用
// 先获取页数,后逐页获取
pageNum, err := logic.GetLiveRoomPageNum("furry", conf.Conf.SpiderCore.BiliCookie)
if err != nil {
log.Logger().Errorf("搜索直播间错误:%s", err)
return
}
for page := 1; page <= pageNum; page++ {
rooms, err := logic.SearchLiveRooms("furry", conf.Conf.SpiderCore.BiliCookie, uint(page))
if err != nil {
log.Logger().Errorf("搜索直播间错误:%s", err)
return
}
count, err := logic.UpdateLiveRoomInfo(rooms)
if err != nil {
log.Logger().Errorf("更新直播间信息错误:%s", err)
return
}
log.Logger().Infof("更新了%d个直播间信息", count)
time.Sleep(1 * time.Second)
}
// 先获取页数,后逐页获取
pageNum, err = logic.GetLiveRoomPageNum("冬聚", conf.Conf.SpiderCore.BiliCookie)
if err != nil {
log.Logger().Errorf("搜索直播间错误:%s", err)
return
}
for page := 1; page <= pageNum; page++ {
rooms, err := logic.SearchLiveRooms("冬聚", conf.Conf.SpiderCore.BiliCookie, uint(page))
if err != nil {
log.Logger().Errorf("搜索直播间错误:%s", err)
return
}
count, err := logic.UpdateLiveRoomInfo(rooms)
if err != nil {
log.Logger().Errorf("更新直播间信息错误:%s", err)
return
}
log.Logger().Infof("更新了%d个直播间信息", count)
time.Sleep(1 * time.Second)
}
}

13
pkg/task/search_test.go Normal file
View File

@ -0,0 +1,13 @@
package task
import "testing"
func TestSearchUntrackedUps(t *testing.T) {
BeforeTesting()
SearchUpsFromVideo()
}
func TestSearchUpsFromLiveRoom(t *testing.T) {
BeforeTesting()
SearchUpsFromLiveRoom()
}

View File

@ -27,7 +27,7 @@ func UpdateUserInfo() {
maxPage := int(math.Ceil(float64(count) / float64(pageSize)))
for page := 0; page <= maxPage; page++ {
// 获取目标用户列表(分页)
users, err := logic.GetUsers(page, pageSize)
users, err := logic.GetValidUsers(page, pageSize)
if err != nil {
log.Logger().Errorf("获取用户列表时发生错误:%s", err)
continue
@ -56,11 +56,12 @@ func UpdateUserInfo() {
}
}
// UpdateFans 更新粉丝数,将记录写入表中,增量记录
func UpdateFans() {
// TODO: 与UpdateUserInfo有大量重复可抽离复用代码
// 预查询数量
var count int64
tx := dao.DB().Model(&model.Furry{}).Count(&count)
tx := dao.DB().Model(&model.Furry{}).Where("status = 0").Count(&count)
if tx.Error != nil {
err := exception.ErrFetchFurries("获取furries数量失败" + tx.Error.Error())
log.Logger().Errorf("获取furries数量失败%s", err)
@ -71,7 +72,7 @@ func UpdateFans() {
maxPage := int(math.Ceil(float64(count) / float64(pageSize)))
for page := 0; page <= maxPage; page++ {
// 获取目标用户列表(分页)
users, err := logic.GetUsers(page, pageSize)
users, err := logic.GetValidUsers(page, pageSize)
if err != nil {
log.Logger().Errorf("获取用户列表时发生错误:%s", err)
continue
@ -97,7 +98,3 @@ func UpdateFans() {
time.Sleep(2 * time.Second)
}
}
func UpdateFansAndInfo() {
}

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",
}