Skip to content

Commit

Permalink
[feat] 增加话题动态接口
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrie committed Jan 15, 2023
1 parent 9857e61 commit 2b710b4
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions internal/pkg/bilibili/video.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package bilibili

import (
"encoding/json"
"fmt"
"net/http"
"net/url"

"git.vtb.link/eoefans/internal/pkg/httpclient"
"github.com/go-resty/resty/v2"
Expand All @@ -14,12 +16,29 @@ const (
webVideoSearchURL = "https://api.bilibili.com/x/web-interface/search/type?context=&search_type=video&page=%d&order=pubdate&keyword=%s&duration=0&category_id=&tids_2=&__refresh__=true&_extra=&tids=0&highlight=1&single_column=0"
webVideoInfoURL = "https://api.bilibili.com/x/web-interface/view?bvid=%s"
webVideoTagInfoURL = "https://api.bilibili.com/x/web-interface/view/detail/tag?aid=%s"
topicHistory = "https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_history?offset_dynamic_id=%d&"
)

const (
cookie = `buvid3=84D177FC-9F90-100D-8BE2-09EE5D9912C823748infoc; b_nut=1672450523; i-wanna-go-back=-1; b_lsid=10D3F3189_18565D1C03E; _uuid=1F95104D7-B7410-FFAD-4263-1EF4BFB14B61023203infoc; buvid_fp=beb12c3870e59666cfee50c6431e8b1a; buvid4=2F7A4DEB-FE17-1579-67FF-E0004E5BFE6D24471-022123109-ytYURKXzrIAOEIOhWNJfdQ%3D%3D; SESSDATA=239cfdaf%2C1688002658%2Ca176f%2Ac2; bili_jct=f4be98b5fb468b646b7260f10ba547e1; DedeUserID=554518161; DedeUserID__ckMd5=d1653a8f679dcf53; CURRENT_FNVAL=4048; sid=870jixri; is-2022-channel=1; hit-new-style-dyn=0; hit-dyn-v2=1; b_ut=5; innersign=1; rpdid=|(u~|||~Y)m)0J\'uY~kRl|~uu'`
)

type DynamicType uint

const (
DynamicDraw DynamicType = 2 //图片动态
)

const (
//topicHistory用topic_id查出来的数据有问题,故暂时用topic_name
topNameWan = "小莞熊在这里"
topNameUn = "柚恩的蜜罐子"
topNameGoGo = "GOGO队立大功!" //中文感叹号
topNameMoMo = "虞你在一起"
topNameMino = "和米诺的对抗路日常"
topNameEOE = "EOE的魔法盒"
)

type SDK struct {
logger *zap.Logger
}
Expand All @@ -35,6 +54,33 @@ type ResponseBasic struct {
Data interface{} `json:"data"`
}

type DynamicInfo struct {
Cards []DynamicCard `json:"cards"`
HasMore uint `json:"has_more"`
Offset string `json:"offset"`
}

type DynamicCard struct {
Desc struct {
Type DynamicType `json:"type"`
} `json:"desc"`
Card json.RawMessage `json:"card"`
}

// Card是json字符串,需要进一步解析
type DynamicCardContent struct {
Item struct {
Pictures DynamicPictures `json:"pictures"`
} `json:"item"`
}

type DynamicPictures []DynamicPicture
type DynamicPicture struct {
Height float64 `json:"img_height"`
Size float64 `json:"img_size"`
Width float64 `json:"img_width"`
ImgSrc string `json:"image_src"`
}
type VideoSearchInfo struct {
Type string `json:"type"`
Id int `json:"id"`
Expand Down Expand Up @@ -290,3 +336,15 @@ func (sdk *SDK) VideoWebTagInfo(aid string) (data *VideoTagResponse, err error)
}
return data, nil
}

func (sdk *SDK) TopicDynamic(topicName string, offsetDynamicId uint64) (data *DynamicInfo, err error) {
params := url.Values{}
params.Add("topic_name", topicName)
url := fmt.Sprintf(topicHistory, offsetDynamicId)
url = url + params.Encode()
fmt.Println(url)
if err = sdk.fastGet(url, &data); err != nil {
return nil, err
}
return data, nil
}

0 comments on commit 2b710b4

Please sign in to comment.