forked from CuteReimu/bilibili
/
video_zone.go
144 lines (134 loc) · 4.53 KB
/
video_zone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package bilibili
import (
"encoding/json"
"strconv"
"github.com/pkg/errors"
)
type ZoneArchive struct {
Aid int `json:"aid"`
Videos int `json:"videos"`
Tid int `json:"tid"`
Tname string `json:"tname"`
Copyright int `json:"copyright"`
Pic string `json:"pic"`
Title string `json:"title"`
Pubdate int `json:"pubdate"`
Ctime int `json:"ctime"`
Desc string `json:"desc"`
State int `json:"state"`
Duration int `json:"duration"`
MissionId int `json:"mission_id,omitempty"`
Rights struct {
Bp int `json:"bp"`
Elec int `json:"elec"`
Download int `json:"download"`
Movie int `json:"movie"`
Pay int `json:"pay"`
Hd5 int `json:"hd5"`
NoReprint int `json:"no_reprint"`
Autoplay int `json:"autoplay"`
UgcPay int `json:"ugc_pay"`
IsCooperation int `json:"is_cooperation"`
UgcPayPreview int `json:"ugc_pay_preview"`
NoBackground int `json:"no_background"`
ArcPay int `json:"arc_pay"`
PayFreeWatch int `json:"pay_free_watch"`
} `json:"rights"`
Owner struct {
Mid int64 `json:"mid"`
Name string `json:"name"`
Face string `json:"face"`
} `json:"owner"`
Stat struct {
Aid int `json:"aid"`
View int `json:"view"`
Danmaku int `json:"danmaku"`
Reply int `json:"reply"`
Favorite int `json:"favorite"`
Coin int `json:"coin"`
Share int `json:"share"`
NowRank int `json:"now_rank"`
HisRank int `json:"his_rank"`
Like int `json:"like"`
Dislike int `json:"dislike"`
Vt int `json:"vt"`
Vv int `json:"vv"`
} `json:"stat"`
Dynamic string `json:"dynamic"`
Cid int `json:"cid"`
Dimension struct {
Width int `json:"width"`
Height int `json:"height"`
Rotate int `json:"rotate"`
} `json:"dimension"`
SeasonId int `json:"season_id,omitempty"`
ShortLinkV2 string `json:"short_link_v2"`
FirstFrame string `json:"first_frame"`
PubLocation string `json:"pub_location"`
Bvid string `json:"bvid"`
SeasonType int `json:"season_type"`
IsOgv bool `json:"is_ogv"`
OgvInfo interface{} `json:"ogv_info"`
RcmdReason string `json:"rcmd_reason"`
EnableVt int `json:"enable_vt"`
AiRcmd interface{} `json:"ai_rcmd"`
UpFromV2 int `json:"up_from_v2,omitempty"`
}
type ZoneNewVideos struct {
Page struct {
Num int `json:"num"`
Size int `json:"size"`
Count int `json:"count"`
} `json:"page"`
Archives []ZoneArchive `json:"archives"`
}
// GetZoneNewVideos 获取分区最新视频
func GetZoneNewVideos(tid, pageNum, pagesize int) (*ZoneNewVideos, error) {
return std.GetZoneNewVideos(tid, pageNum, pagesize)
}
func (c *Client) GetZoneNewVideos(tid, pageNum, pagesize int) (*ZoneNewVideos, error) {
resp, err := c.resty().R().
SetQueryParams(map[string]string{
"rid": strconv.Itoa(tid),
"pn": strconv.Itoa(pageNum),
"ps": strconv.Itoa(pagesize),
}).
Get("https://api.bilibili.com/x/web-interface/dynamic/region")
if err != nil {
return nil, errors.WithStack(err)
}
data, err := getRespData(resp, "获取分区最新视频")
if err != nil {
return nil, err
}
var ret ZoneNewVideos
err = json.Unmarshal(data, &ret)
return &ret, errors.WithStack(err)
}
// GetZoneNewVideosWithTag 获取分区最新视频
func GetZoneNewVideosWithTag(tid int, tagID string, pageNum, pagesize int) (*ZoneNewVideos, error) {
return std.GetZoneNewVideosWithTag(tid, tagID, pageNum, pagesize)
}
// 近期投稿 https://api.bilibili.com/x/web-interface/newlist_rank?main_ver=v3&search_type=video&view_type=hot_rank©_right=-1&new_web_tag=1&order=scores&cate_id=236&page=1&pagesize=30&time_from=20231105&time_to=20231112&keyword=%E5%B0%84%E5%87%BB
// 最新动态 https://api.bilibili.com/x/web-interface/dynamic/tag?ps=14&pn=1&rid=236&tag_id=6697
// 热门 https://api.bilibili.com/x/web-interface/ranking/tag?tag_id=6697&rid=236
func (c *Client) GetZoneNewVideosWithTag(tid int, tagID string, pageNum, pagesize int) (*ZoneNewVideos, error) {
resp, err := c.resty().R().
SetQueryParams(map[string]string{
"tag_id": tagID,
"rid": strconv.Itoa(tid),
"pn": strconv.Itoa(pageNum),
"ps": strconv.Itoa(pagesize),
}).
Get("https://api.bilibili.com/x/web-interface/dynamic/tag")
if err != nil {
return nil, errors.WithStack(err)
}
data, err := getRespData(resp, "获取分区标签最新视频")
if err != nil {
return nil, err
}
var ret ZoneNewVideos
err = json.Unmarshal(data, &ret)
return &ret, errors.WithStack(err)
}