-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasics.py
319 lines (257 loc) · 8.1 KB
/
basics.py
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import requests
import json
class Userget:
def __init__(self,uid):
self.uid = str(uid)
self.headers = {
"User-Agent":"Bili fans/1.0.0 (18108274905@163.com)",
"Host":"api.bilibili.com",
"Connection":"keep-alive"
}
#获取账户信息
self.info_url = 'https://api.bilibili.com/x/relation/stat?jsonp=jsonp&vmid=' + self.uid
self.user_info_j = json.loads(requests.get(self.info_url,headers=self.headers).text)
#up信息
self.upinfo_url = "https://api.bilibili.com/x/space/acc/info?mid="+ self.uid +"&jsonp=jsonp"
self.up_info_j = json.loads(requests.get(self.upinfo_url,headers=self.headers).text)
#获取直播信息
self.live_url = "https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=" + self.uid
self.user_live_j = json.loads(requests.get(self.live_url).text)
#大体视频信息
self.video_list_url = "https://space.bilibili.com/ajax/member/getSubmitVideos?mid=" + self.uid
self.big_video_j = json.loads(requests.get(self.video_list_url).text)
#账户信息回调
def userinfo(self):
'''
用户一般信息json
'''
return self.user_info_j
def id(self):
'''
用户uid int
'''
return self.user_info_j['data']['mid']
def following(self):
'''
用户关注数 int
'''
return self.user_info_j['data']['following']
def whisper(self):
'''
用户私信数 int 一般无法获取
'''
return self.user_info_j['data']['whisper']
def black(self):
'''
用户黑名单数 int
'''
return self.user_info_j['data']['black']
def follower(self):
'''
用户粉丝数 int
'''
return self.user_info_j['data']['follower']
#up信息回调
def upinfo(self):
'''
用户具体信息json
'''
return self.up_info_j
def username(self):
'''
用户名 str
'''
return self.up_info_j['data']['name']
def sex(self):
'''
用户性别 str
'''
return self.up_info_j['data']['sex']
def face(self):
'''
用户头像链接 str
'''
return self.up_info_j['data']['face']
def sign(self):
'''
用户个性签名 str
'''
return self.up_info_j['data']['sign']
def level(self):
'''
用户等级 int
'''
return self.up_info_j['data']['level']
def birthday(self):
'''
用户生日 mm-dd str
'''
return self.up_info_j['data']['birthday']
def badge(self):
'''
用户是否自己的粉丝勋章 Boolean
'''
return self.up_info_j['data']['fans_badge']
def intr(self):
'''
用户的认证信息 str
'''
return self.up_info_j['data']['official']['title']
def viptype(self):
'''
用户vip类别 int
0:无 1:普通VIP 2:年费VIP
'''
return self.up_info_j['data']['vip']['type']
def vipthemetype(self):
'''
vip主题状态 Boolean
'''
return self.up_info_j['data']['vip']['theme_type']
def isfollowed(self):
'''
是否可以被直接关注 Boolean
'''
return self.up_info_j['data']['is_followed']
def toppic(self):
'''
主页顶部图片url str
'''
return self.up_info_j['data']['top_photo']
#直播信息回调
def liveinfo(self):
return self.user_live_j
def liveurl(self):
'''
直播间链接 str
'''
return self.user_live_j['data']['url']
def liveroomid(self):
'''
直播间号 int
'''
return self.user_live_j['data']['roomid']
def liveroomcover(self):
'''
直播间封面链接 str
'''
return self.user_live_j['data']['cover']
#大体视频信息回调
def uservideoinfo(self):
return self.big_video_j
def usertags(self):
'''
用户视频标签list [str,...]
'''
tlist = [tag for tag in self.big_video_j['data']['tlist']]
tags = [tag for tag in tlist['name']]
return tags
def newv(self):
'''
用户最新视频id int
'''
return self.big_video_j['data']['vlist'][0]['aid']
class Videoget:
def __init__(self,aid):
self.aid = str(aid)
self.headers = {
"User-Agent":"Bili fans/1.0.0 (18108274905@163.com)",
"Host":"api.bilibili.com",
"Connection":"keep-alive"
}
#获取视频基本信息
self.vnum_url = 'https://api.bilibili.com/x/web-interface/archive/stat?aid=' + self.aid
self.vnum_j = json.loads(requests.get(self.vnum_url,headers=self.headers).text)
#获取视频详细信息
self.vinfo_url = 'https://api.bilibili.com/x/web-interface/view?aid=' + self.aid
self.vinfo_j = json.loads(requests.get(self.vinfo_url,headers=self.headers).text)
#获取视频下载信息 kanbilibili.com
self.vd_url = 'https://www.kanbilibili.com/api/video/'+ self.aid +'/download?cid=101560001&quality=64&page=1'
self.vd_j = json.loads(requests.get(self.vd_url,headers=self.headers).text)
#基本信息回调
def id(self):
return int(self.vnum_j['data']['aid'])
def view(self):
'''
观看数 int
'''
return self.vnum_j['data']['view']
def dan(self):
'''
弹幕数 int
'''
return self.vnum_j['data']['danmaku']
def reply(self):
'''
评论数
'''
return self.vnum_j['data']['reply']
def favorite(self):
'''
收藏数 int
'''
return self.vnum_j['data']['favorite']
def coin(self):
'''
硬币数 int
'''
return self.vnum_j['data']['coin']
def share(self):
'''
分享数 int
'''
return self.vnum_j['data']['share']
def like(self):
'''
点赞数 int
'''
return self.vnum_j['data']['like']
def copyright(self):
'''
版权状态 int
'''
return self.vnum_j['data']['copyright']
#杂项信息回调
def detail(self):
return self.vinfo_j
def ownerid(self):
'''
视频主人id int
'''
return self.vinfo_j['data']['owner']['mid']
def title(self):
'''
视频标题 str
'''
return self.vinfo_j['data']['title']
def cover(self):
'''
视频封面url str
'''
return self.vinfo_j['data']['pic']
def desc(self):
'''
视频简介 str
'''
return self.vinfo_j['data']['desc']
# class Downv:
# def __init__(self,aid):
# self.aid = str(aid)
# self.headers = {
# "User-Agent":"Bili fans/1.0.0 (18108274905@163.com)",
# "Host":"api.bilibili.com",
# "Connection":"keep-alive"
# }
# #获取视频下载信息 kanbilibili.com
# self.vd_url = 'https://www.kanbilibili.com/api/video/'+ self.aid +'/download?cid=101560001&quality=64&page=1'
# self.vd_j = json.loads(requests.Session().get(self.vd_url).text)
# self.dj = self.vd_j['data']['durl'][0]
# def url(self):
# dlist = [self.vd_j['data']['durl'][0]['url'],self.vd_j['data']['durl'][0]['backup_url']]
# return dlist
# def formats(self):
# return self.vd_j['data']['format']
# def size(self):
# return self.dj['size']
# def time(self):
# return self.dj['length']