From 04826c03a741aeb95ba01bff95fc68ace31819b9 Mon Sep 17 00:00:00 2001 From: dech53 <93471086+dech53@users.noreply.github.com> Date: Thu, 5 Dec 2024 22:28:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E6=83=85=E5=8C=85=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=92=8C=E9=A6=96=E9=A1=B5=E6=8E=A8=E8=8D=90=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=93=E4=BF=AE=E6=94=B9=20(#90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加表情接口,修改首页推荐视频结构体 * 名称修改 * 名称修改 --- emote.go | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ video.go | 50 ++++++++++++++++++++++++-- 2 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 emote.go diff --git a/emote.go b/emote.go new file mode 100644 index 0000000..686df8e --- /dev/null +++ b/emote.go @@ -0,0 +1,106 @@ +package bilibili + +import "github.com/go-resty/resty/v2" + +type EmoteActionParam struct { + Package_id int `json:"package_id"` //表情包ID + Bussiness string `json:"business"` //表情包使用场景 + Ids []int `json:"ids"` //表情包ID集合 +} +type EmotePackageFlags struct { + Added bool `json:"added"` // 是否已添加,需要登录(SESSDATA)否则恒为false,true:已添加 false:未添加 +} +type Meta struct { + Size int `json:"size"` // 表情尺寸信息 1:小 2:大 + ItemID int `json:"item_id,omitempty"` // 购买物品 ID,可能为空 + ItemURL string `json:"item_url,omitempty"` // 购买物品页面 URL,可能为空 + Alias string `json:"alias"` //简写名 +} +type EmoteFlags struct { + NoAccess bool `json:"no_access"` // 是否为禁用 true:禁用 +} + +type Emote struct { + ID int `json:"id"` // 表情 ID + PackageID int `json:"package_id"` // 表情包 ID + Text string `json:"text"` // 表情转义符或颜文字 + URL string `json:"url"` // 表情图片 URL 或颜文字 + MTime int64 `json:"mtime"` // 创建时间,时间戳 + Type int `json:"type"` // 表情类型 1:普通 2:会员专属 3:购买所得 4:颜文字 + Attr int `json:"attr"` // 未知作用 + Meta Meta `json:"meta"` // 属性信息 + Flags EmoteFlags `json:"flags"` // 禁用标志 +} + +type EmotePackage struct { + ID int `json:"id"` // 表情包 ID + Text string `json:"text"` // 表情包名称 + URL string `json:"url"` // 表情包标志图片 URL + MTime int64 `json:"mtime"` // 创建时间,时间戳 + Type int `json:"type"` // 表情类型 1:普通 2:会员专属 3:购买所得 4:颜文字 + Attr int `json:"attr"` // 未知作用 + Meta Meta `json:"meta"` // 属性信息 + Emote []Emote `json:"emote"` // 表情列表 + Flags EmotePackageFlags `json:"flags"` // 是否添加标志 +} + +// AddEmote添加表情包 +func (c *Client) AddEmote(param EmoteActionParam) error { + const ( + method = resty.MethodPost + url = "https://api.bilibili.com/x/emote/package/add" + ) + _, err := execute[any](c, method, url, param, fillCsrf(c)) + return err +} + +// RemoveEmote移除表情包 +func (c *Client) RemoveEmote(param EmoteActionParam) error { + const ( + method = resty.MethodPost + url = "https://api.bilibili.com/x/emote/package/remove" + ) + _, err := execute[any](c, method, url, param, fillCsrf(c)) + return err +} + +type EmoteList struct { + EmotePackages []EmotePackage `json:"packages"` // 表情包包列表 +} + +// GetMyEmoteList获取我的表情包列表 +func (c *Client) GetMyEmoteList(param EmoteActionParam) (*EmoteList, error) { + const ( + method = resty.MethodGet + url = "https://api.bilibili.com/x/emote/user/panel" + ) + return execute[*EmoteList](c, method, url, param) +} + +// GetEmotePackageDetailInfo获取指定ID表情包的详细信息 +func (c *Client) GetEmotePackageDetailInfo(param EmoteActionParam) (*EmoteList, error) { + const ( + method = resty.MethodGet + url = "https://api.bilibili.com/x/emote/package" + ) + return execute[*EmoteList](c, method, url, param) +} + +type Mall struct { + Title string `json:"title"` //商城名称 + Url string `json:"url"` //商城页面url +} + +type AllEmoteList struct { + User_panel_packages []EmotePackage `json:"user_panel_packages"` + All_packages []EmotePackage `json:"all_packages"` + Mall Mall `json:"mall"` +} + +func (c *Client) GetAllEmoteList(param EmoteActionParam) (*AllEmoteList, error) { + const ( + method = resty.MethodGet + url = "https://api.bilibili.com/x/emote/setting/panel" + ) + return execute[*AllEmoteList](c, method, url, param) +} diff --git a/video.go b/video.go index 2dff53d..cde08e6 100644 --- a/video.go +++ b/video.go @@ -207,7 +207,51 @@ type ArgueInfo struct { ArgueMsg string `json:"argue_msg"` // 警告/争议提示信息 ArgueType int `json:"argue_type"` // 作用尚不明确 } - +type TopRecommendVideoList struct { + BusinessCard any `json:"business_card"` //无意义 + FloorInfo any `json:"floor_info"` //无意义 + Item []TopRecommendVideoItem `json:"item"` //推荐列表 + Mid int `json:"mid"` //用户mid,未登录为0 + PreloadExposePct float64 `json:"preload_expose_pct"` //用于预加载? + PreloadFloorExposePct float64 `json:"preload_floor_expose_pct"` //用于预加载? + SideBarColumn []any `json:"side_bar_column"` //边栏列表? 可参考字段 item 及对应功能文档 + UserFeature any `json:"user_feature"` //无意义 +} + +// 推荐理由 +type RcmdReason struct { + ReasonType int `json:"reason_type"` // 原因类型 + Content string `json:"content"` // 原因描述(仅当 reason_type 为 3 时存在) +} + +type TopRecommendVideoItem struct { + AvFeature any `json:"av_feature"` // 暂无参考意义 + BusinessInfo any `json:"business_info"` // 商业推广信息,通常为 null + Bvid string `json:"bvid"` // 视频 bvid + Cid int `json:"cid"` // 视频 cid + DislikeSwitch int `json:"dislike_switch"` // 不感兴趣开关 + DislikeSwitchPC int `json:"dislike_switch_pc"` // PC端不感兴趣开关 + Duration int `json:"duration"` // 视频时长 + EnableVt int `json:"enable_vt"` // 未知作用 + Goto string `json:"goto"` // 目标类型 (av, ogv, live) + Id int `json:"id"` // 视频 avid / 直播间 id + IsFollowed int `json:"is_followed"` // 是否已关注 + IsStock int `json:"is_stock"` // 未知作用 + OgvInfo any `json:"ogv_info"` // 通常为 null + Owner Owner `json:"owner"` // 视频 UP 主信息 + Pic string `json:"pic"` // 视频封面 + Pic43 string `json:"pic_4_3"` // 4:3 比例封面 + Pos int `json:"pos"` // 位置 + Pubdate int `json:"pubdate"` // 发布时间(秒级时间戳) + RcmdReason RcmdReason `json:"rcmd_reason"` // 推荐理由 + RoomInfo any `json:"room_info"` // 通常为 null + ShowInfo int `json:"show_info"` // 展示信息(1: 普通视频, 0: 直播) + Stat any `json:"stat"` // 视频状态信息 + Title string `json:"title"` // 视频标题 + TrackId string `json:"track_id"` // 跟踪标识 + Uri string `json:"uri"` // 目标页 URI + VtDisplay string `json:"vt_display"` // 未知作用 +} type VideoInfo struct { Bvid string `json:"bvid"` // 稿件bvid Aid int `json:"aid"` // 稿件avid @@ -487,12 +531,12 @@ type GetTopRecommendVideoParam struct { } // GetTopRecommendVideo 获取首页视频推荐列表 -func (c *Client) GetTopRecommendVideo(param GetTopRecommendVideoParam) ([]VideoInfo, error) { +func (c *Client) GetTopRecommendVideo(param GetTopRecommendVideoParam) (*TopRecommendVideoList, error) { const ( method = resty.MethodGet url = "https://api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd" ) - return execute[[]VideoInfo](c, method, url, param) + return execute[*TopRecommendVideoList](c, method, url, param) } type GetVideoCollectionInfoParam struct {