This repository was archived by the owner on Apr 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathapis.py
998 lines (877 loc) · 37.7 KB
/
apis.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2019/9/17 22:45
# @Author : Dawnnnnnn
# @Contact: 1050596704@qq.com
import json
import random
from utils import *
from PIL import Image
from io import BytesIO
from network import Request
request = Request()
# 取消关注 (直播站接口)
async def delete_follow(follow_uid, cookie, csrf, suname):
url = "https://api.live.bilibili.com/liveact/attention"
data = {
"type": 0,
"uid": follow_uid,
"token": "",
"csrf_token": csrf,
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"取消关注{follow_uid}回显:{response}", "INFO", "blue")
# 根据勋章id删除勋章
async def delete_medal(medal_id, cookie, csrf, suname):
url = "https://api.live.bilibili.com/i/ajaxDeleteMyFansMedal"
data = {
"medal_id": medal_id,
"csrf_token": csrf,
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"删除勋章{medal_id}回显:{response}", "INFO", "blue")
# 根据粉丝uid删除粉丝
async def delete_fans(fan_uid, cookie, csrf, suname):
url = "https://api.bilibili.com/x/relation/modify"
data = {
"fid": fan_uid,
"act": 7,
"re_src": 11,
"jsonp": "jsonp",
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"删除粉丝{fan_uid}回显:{response}", "INFO", "blue")
# 退出友爱社
async def quit_unionfans(cookie, suname):
url = "https://api.live.bilibili.com/activity/v1/UnionFans/quit"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"{suname}退出友爱社回显:{response}", "INFO", "blue")
return response
# 根据收藏夹id删除收藏夹
async def delete_favorite_pack(media_ids, cookie, csrf, suname):
url = "https://api.bilibili.com/medialist/gateway/base/del"
data = {
"media_ids": media_ids,
"jsonp": "jsonp",
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"删除收藏夹{media_ids}回显:{response}", "INFO", "blue")
# 根据动态id删除动态
async def del_dynamic_by_id(uid, dy_id, cookie, access_key, suname):
url = 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/rm_rp_dyn'
temp_data = f"_device=android&_hwid=SX1NL0wuHCsaKRt4BHhIfRguTXxOfj5WN1BkBTdLfhstTn9NfUouFiUV&access_key={access_key}&appkey=1d8b6e7d45233436&build=5310300&dynamic_id={dy_id}&mobi_app=android&platform=android&src=meizu&trace_id=20180909020900047&ts={CurrentTime() * 1000}&uid={uid}&version=5.31.3.5310300"
data = f"{temp_data}&sign={calc_sign(temp_data)}"
headers = {
"User-Agent": "Mozilla/5.0 BiliDroid/5.31.3 (bbcallen@gmail.com)",
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
"Cookie": cookie
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"删除动态{dy_id}回显:{response}", "INFO", "blue")
# 获取所有关注的另一种写法
# async def get_all_follows(uid, cookie, suname):
# url = f"https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?visitor_uid={uid}&host_uid={uid}"
# headers = {
# "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
# "Cookie": cookie
# }
# response = await request.req_add_job('get', url, headers=headers, suname=suname)
# response = json.loads(response)
# return response
# 获取所有关注人
async def get_all_follows(cookie, suname):
follows = []
page = 1
while 1:
url = f"https://api.live.bilibili.com/i/api/following?page={page}&pageSize=20"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
if response['data']['list']:
for k in range(0, len(response['data']['list'])):
follows.append(response['data']['list'][k]['uid'])
page = page + 1
continue
else:
break
return follows
# 获取没有互粉的关注人
async def get_all_follows_not_6(uid, cookie, suname):
follows = []
page = 1
while 1:
url = f"https://api.bilibili.com/x/relation/followings?vmid={uid}&pn={page}&ps=20&order=desc&jsonp=jsonp"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
if response['data']['list']:
for k in range(0, len(response['data']['list'])):
if response['data']['list'][k]['attribute'] != 6:
follows.append(response['data']['list'][k]['mid'])
page = page + 1
continue
else:
break
return follows
# 获取所有勋章
async def get_all_medal(cookie, suname):
url = "https://api.live.bilibili.com/i/api/medal?page=1&pageSize=30"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
return response
# 获取自己的100个粉丝
async def get_all_fans(uid, cookie, suname):
"""
印象中这个删除粉丝,每小时有数量限制,先设置成清除100个
:param cookie:
:param csrf:
:param suname:
:return:
"""
url = f"https://api.bilibili.com/x/relation/followers?vmid={uid}&pn=1&ps=100&order=desc"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
return response
# 获取所有收藏夹id
async def get_all_favorite_pack(uid, cookie, suname):
url = f"https://api.bilibili.com/x/space/fav/nav?mid={uid}"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
return response
# 获取所有动态id
async def get_all_dynamic(uid, cookie, access_key, suname):
dy_id = 0
dy_uid_list = []
start = 1
while 1:
temp_params = f"_device=android&_hwid=SX1NL0wuHCsaKRt4BHhIfRguTXxOfj5WN1BkBTdLfhstTn9NfUouFiUV&access_key={access_key}&appkey=1d8b6e7d45233436&build=5310300&host_uid={uid}&mobi_app=android&offset_dynamic_id={dy_id}&page={start}&platform=android&qn=32&src=meizu&trace_id=20180908182200005&ts={CurrentTime()}&version=5.31.3.5310300&visitor_uid={uid}"
url = f"https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?{temp_params}&sign={calc_sign(temp_params)}"
headers = {
"User-Agent": "Mozilla/5.0 BiliDroid/5.31.3 (bbcallen@gmail.com)",
"Cookie": cookie
}
response = await request.req_add_job("get", url, headers=headers, suname=suname)
response = json.loads(response)
exist = (response['data']['has_more'])
if exist == 0:
break
_len = len(response['data']['cards'])
for i in range(0, _len):
dyid = response['data']['cards'][i]['desc']['dynamic_id']
dy_uid_list.append(dyid)
dy_id = response['data']['cards'][_len - 1]['desc']['dynamic_id']
start = start + 1
continue
return dy_uid_list
# 清空自己的关注人
async def delete_all_follows(cookie, csrf, suname):
follows = await get_all_follows(cookie, suname)
for follow_uid in follows:
await delete_follow(follow_uid, cookie, csrf, suname)
# 清空自己的所有勋章
async def delete_all_medals(cookie, csrf, suname):
response = await get_all_medal(cookie, suname)
for k in range(0, len(response['data']['fansMedalList'])):
await delete_medal(response['data']['fansMedalList']['id'], cookie, csrf, suname)
# 清空自己的全部粉丝
async def delete_all_fans(uid, cookie, csrf, suname):
response = await get_all_fans(uid, cookie, suname)
for k in range(0, len(response['data']['list'])):
await delete_fans(response['data']['list'][k]['mid'], cookie, csrf, suname)
# 清空自己的所有收藏夹
async def delete_all_favorite_pack(uid, cookie, csrf, suname):
response = await get_all_favorite_pack(uid, cookie, suname)
for k in range(0, len(response['data']['archive'])):
await delete_favorite_pack(response['data']['archive'][k]['media_id'], cookie, csrf, suname)
# 清空所有的动态
async def delete_all_dynamic_ids(uid, cookie, access_key, suname):
dynamic_ids = await get_all_dynamic(uid, cookie, access_key, suname)
for dy_id in dynamic_ids:
await del_dynamic_by_id(uid, dy_id, cookie, access_key, suname)
# 关注
async def follow(follow_uid, cookie, csrf, suname):
url = "https://api.bilibili.com/x/relation/modify"
data = {
"fid": follow_uid,
"act": 1,
"re_src": 11,
"jsonp": "jsonp",
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"关注{follow_uid}回显:{response}", "INFO", "blue")
# 取消关注 (主站接口)
async def unfollow(follow_uid, cookie, csrf, suname):
url = "https://api.bilibili.com/x/relation/modify"
data = {
"fid": follow_uid,
"act": 2,
"re_src": 11,
"jsonp": "jsonp",
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"取关{follow_uid}回显:{response}", "INFO", "blue")
# 删除没有互粉的粉丝
async def delete_not_exchange_fans(uid, cookie, csrf, suname):
response = await get_all_fans(uid, cookie, suname)
for k in range(0, len(response['data']['list'])):
if response['data']['list'][k]['attribute'] != 6:
await delete_fans(response['data']['list']['mid'], cookie, csrf, suname)
# 删除没有互粉的关注人
async def delete_not_exchange_follows(cookie, csrf, suname):
follows = await get_all_follows_not_6(cookie, suname)
for follow_uid in follows:
await delete_follow(follow_uid, cookie, csrf, suname)
# 视频av转cid
async def get_av_cid(aid, cookie, suname):
url = f"https://api.bilibili.com/x/player/pagelist?aid={aid}"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
if response['code'] == 0:
cid = response['data'][0]['cid']
else:
cid = 0
return cid
# 随机得到一个av号
async def get_attention_video_or_random(cookie, suname):
follows = await get_all_follows(cookie, suname)
video_list = []
for mid in follows:
url = f"https://space.bilibili.com/ajax/member/getSubmitVideos?mid={mid}&pagesize=100&tid=0"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
datalen = len(response['data']['vlist'])
for i in range(0, datalen):
aid = response['data']['vlist'][i]['aid']
video_list.append(aid)
if len(video_list) >= 5:
break
if video_list:
return random.choice(video_list)
else:
while 1:
av_num = random.randint(10000000, 67967399)
cid = await get_av_cid(av_num, cookie, suname)
if cid != 0:
return av_num
else:
continue
# 随机分享一个视频,用于完成每日任务
async def share_random(cookie, access_key, suname):
av_num = await get_attention_video_or_random(cookie, suname)
url = "https://app.bilibili.com/x/v2/view/share/add"
headers = {
"User-Agent": "Mozilla/5.0 BiliDroid/5.26.3 (bbcallen@gmail.com)",
"Host": "app.bilibili.com",
"Cookie": "sid=8wfvu7i7"
}
temp_params = f"access_key={access_key}&aid={av_num}&appkey=1d8b6e7d45233436&build=5260003&from=7&mobi_app=android&platform=android&ts={CurrentTime()}"
sign = calc_sign(temp_params)
data = {
"access_key": access_key,
"aid": av_num,
"appkey": "1d8b6e7d45233436",
"build": "5260003",
"from": "7",
"mobi_app": "android",
"platform": "android",
"ts": CurrentTime(),
"sign": sign
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"分享视频{av_num}回显:{response}", "INFO", "blue")
# 根据av号分享视频
async def share(av_num, access_key, suname):
url = "https://app.bilibili.com/x/v2/view/share/add"
headers = {
"User-Agent": "Mozilla/5.0 BiliDroid/5.26.3 (bbcallen@gmail.com)",
"Host": "app.bilibili.com",
"Cookie": "sid=8wfvu7i7"
}
temp_params = f"access_key={access_key}&aid={av_num}&appkey=1d8b6e7d45233436&build=5260003&from=7&mobi_app=android&platform=android&ts={CurrentTime()}"
sign = calc_sign(temp_params)
data = {
"access_key": access_key,
"aid": av_num,
"appkey": "1d8b6e7d45233436",
"build": "5260003",
"from": "7",
"mobi_app": "android",
"platform": "android",
"ts": CurrentTime(),
"sign": sign
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"分享视频{av_num}回显:{response}", "INFO", "blue")
# 随机观看一个视频,用于完成每日任务
async def watch_av_random(uid, csrf, cookie, suname):
av_num = await get_attention_video_or_random(cookie, suname)
url = "https://api.bilibili.com/x/report/web/heartbeat"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Referer": f"https://www.bilibili.com/video/av{av_num}",
"Cookie": cookie
}
cid = await get_av_cid(av_num, cookie, suname)
data = {
"aid": av_num,
"cid": cid,
"mid": uid,
"csrf": csrf,
"played_time": "0",
"realtime": "0",
"start_ts": CurrentTime(),
"type": "3",
"dt": "2",
"play_type": "1"
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"观看视频{av_num}回显:{response}", "INFO", "blue")
# 根据av号观看视频
async def watch_av(av_num, uid, csrf, cookie, suname):
url = "https://api.bilibili.com/x/report/web/heartbeat"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Referer": f"https://www.bilibili.com/video/av{av_num}",
"Cookie": cookie
}
cid = await get_av_cid(av_num, cookie, suname)
data = {
"aid": av_num,
"cid": cid,
"mid": uid,
"csrf": csrf,
"played_time": "0",
"realtime": "0",
"start_ts": CurrentTime(),
"type": "3",
"dt": "2",
"play_type": "1"
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"观看视频{av_num}回显:{response}", "INFO", "blue")
# 根据av号一键三连
async def combo(aid, csrf, cookie, suname):
url = f"https://api.bilibili.com/x/web-interface/archive/like/triple"
data = {
'aid': aid,
'csrf': csrf,
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Referer": f"https://www.bilibili.com/video/av{aid}",
"Cookie": cookie
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"三连视频{aid}回显:{response}", "INFO", "blue")
# 主站信息获取 接口 1
async def userinfo_1(uid, cookie, suname):
"""
['data']['silence'] == 1 封禁
== 0 未封禁
:param uid:
:param cookie:
:param suname:
:return:
"""
url = f"https://api.bilibili.com/x/space/acc/info?mid={uid}&jsonp=jsonp"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"获取{uid}用户信息(封禁)API回显:{response}", "DEBUG", "yellow")
return response
# 主站信息获取 接口 1
async def userinfo_2(cookie, suname):
"""
:param cookie:
:param suname:
:return:
"""
url = "https://account.bilibili.com/home/userInfo"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"获取用户信息(主站信息)API回显:{response}", "DEBUG", "yellow")
return response
async def userinfo_3(cookie, suname):
"""
:param cookie:
:param suname:
:return:
"""
url = "https://api.bilibili.com/x/web-interface/nav"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"获取用户信息(主站信息2)API回显:{response}", "DEBUG", "yellow")
return response
# 直播站信息获取 接口 1
async def userinfo_4(cookie, suname):
"""
:param cookie:
:param suname:
:return:
"""
url = "https://api.live.bilibili.com/xlive/web-ucenter/user/get_user_info"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"获取用户信息(直播站信息)API回显:{response}", "DEBUG", "yellow")
return response
# 获取一言以伪造签名
async def get_sentence():
types = ["a", "b", "c", "d", "e", "f", "g"]
c = random.choice(types)
url = f"https://v1.hitokoto.cn?c={c}&encode=json&charset=utf-8"
response = await request.other_get(url)
response = json.loads(response)
hitokoto = response['hitokoto']
while len(hitokoto) >= 70:
response = await request.other_get(url)
response = json.loads(response)
hitokoto = response['hitokoto']
return hitokoto
# 获取头像图片
async def get_image(suname):
url = "https://acg.toubiec.cn/random.php?return=json"
response = await request.other_get(url)
response = json.loads(response)
img_url = response['acgurl']
printer.printer("成功获取到图片url", "DEBUG", "yellow")
response = await request.req_add_job('get', img_url, suname=suname)
f = BytesIO()
f.write(response)
img = Image.open(f)
img.thumbnail((180, 180))
f11 = BytesIO()
img.save(f11, format="jpeg")
return f11
# 上传头像,我猜有bug
async def upload_image(cookie, suname):
f11 = await get_image(suname)
# data = {"dopost": "save", "DisplayRank": "10000"}
# files = {'face': ('blob', f11.getvalue(), "image/jpeg")}
url = "http://account.bilibili.com/pendant/updateFace"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"Cookie": cookie
}
data = request.form_data
data.add_field('face', f11.getvalue(), content_type='image/jpeg')
data.add_field('dopost', 'save')
data.add_field('DisplayRank', '10000')
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
return response
# 根据av号和收藏夹id添加到收藏夹
async def add_something_to_favorite_pack(aid, media_id, cookie, csrf, suname):
url = "https://api.bilibili.com/medialist/gateway/coll/resource/deal"
data = {
"rid": aid,
"type": 2,
"add_media_ids": media_id,
"del_media_ids": "",
"jsonp": "jsonp",
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Referer": f"https://www.bilibili.com/video/av{aid}",
"Cookie": cookie
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"收藏视频{aid}回显:{response}", "INFO", "blue")
# 随机获取一些up主uid
async def get_follow_uid_list(suname):
page = random.randint(1, 25)
url = f"https://api.live.bilibili.com/room/v1/room/get_user_recommend?page={page}"
response = await request.req_add_job('get', url, suname=suname)
response = json.loads(response)
return response
# 获取50个番剧id
async def get_bangumi_list(suname):
url = "https://api.bilibili.com/pgc/season/index/result?season_version=-1&area=-1&is_finish=-1©right=-1&season_status=-1&season_month=-1&year=-1&style_id=-1&order=3&st=1&sort=0&page=1&season_type=1&pagesize=50&type=1"
response = await request.req_add_job('get', url, suname=suname)
response = json.loads(response)
return response
# 追番
async def add_bangumi_to_follow(season_id, cookie, csrf, suname):
url = "https://api.bilibili.com/pgc/web/follow/add"
data = {
"season_id": season_id,
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie,
"Referer": f"https://www.bilibili.com/bangumi/play/ss{season_id}/"
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"添加追番{season_id}回显:{response}", "INFO", "blue")
# 取消追番
async def del_bangumi_in_follow(season_id, cookie, csrf, suname):
url = "https://api.bilibili.com/pgc/web/follow/del"
data = {
"season_id": season_id,
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie,
"Referer": f"https://www.bilibili.com/bangumi/play/ss{season_id}/"
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"取消追番{season_id}回显:{response}", "INFO", "blue")
async def get_owner_bangumi_list(uid, cookie, suname):
url = f"https://api.bilibili.com/x/space/bangumi/follow/list?type=1&follow_status=0&pn=1&ps=100&vmid={uid}"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"获取用户番剧列表回显:{response}", "DEBUG", "yellow")
return response
# 订阅标签
async def add_tag(tag_id, cookie, csrf, suname):
url = "https://api.bilibili.com/x/tag/subscribe/add"
data = {
"tag_id": tag_id,
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"订阅标签{tag_id}回显:{response}", "INFO", "blue")
# 设置各种不可见
async def set_private(action, uid, cookie, csrf, suname):
"""
fav_video
bangumi
tags
coins_video
user_info
played_game
:return:
"""
url = "http://space.bilibili.com/ajax/settings/setPrivacy"
data = {
action: 0,
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie,
'Origin': "https://space.bilibili.com",
'Referer': f"https://space.bilibili.com/{uid}/",
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"设置隐私{action}回显:{response}", "INFO", "blue")
# 佩戴勋章
async def wear_medal(medal, cookie, suname):
url = f"https://api.live.bilibili.com/i/ajaxWearFansMedal?medal_id={medal}"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"佩戴勋章{medal}回显:{response}", "INFO", "blue")
# 更新签名,出生年月,性别信息
async def update_info(uname, cookie, csrf, suname):
url = "https://api.bilibili.com/x/member/web/update"
data = {
"uname": uname,
"usersign": await get_sentence(),
"sex": random.choice(['男', '女', '保密']),
"birthday": random.choice(['1970-01-01', '2000-09-10', '2002-03-12']),
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"更新用户基本信息回显:{response}", "INFO", "blue")
# 直播间发送弹幕
async def send_danmu(msg, roomid, cookie, csrf, suname):
url = "https://api.live.bilibili.com/msg/send"
data = {
"color": 16777215,
"fontsize": 25,
"mode": 1,
"msg": msg,
"rnd": 0,
"roomid": roomid,
"bubble": 0,
"csrf_token": csrf,
"csrf": csrf
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, headers=headers, data=data, suname=suname)
response = json.loads(response)
printer.printer(f"发送弹幕{msg}回显:{response}", "INFO", "blue")
# 硬币换勋章
async def coin_to_medal(buy_uid, cookie, suname):
url = f"https://api.vc.bilibili.com/link_group/v1/member/buy_medal?coin_type=metal&master_uid={buy_uid}&platform=android"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"硬币购买勋章回显:{response}", "INFO", "blue")
return response
# 银瓜子换硬币
async def sliver_to_coin(cookie, csrf, suname):
url = "https://api.live.bilibili.com/pay/v1/Exchange/silver2coin"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
data = {
"platform": "pc",
"csrf_token": csrf
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"银瓜子兑换硬币回显:{response}", "INFO", "blue")
return response
# 查询直播站实物礼物列表
async def query_live_reward(access_key, suname):
url = f"https://api.live.bilibili.com/lottery/v1/Award/award_list?access_key={access_key}"
headers = {
"User-Agent": "Mozilla/5.0 BiliDroid/5.31.3 (bbcallen@gmail.com)"
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"{suname}查询直播站实物礼物回显:{response['data']['list']}", "INFO", "blue")
return response
# 参与实物抽奖
async def draw_lottery(aid, number, cookie, suname):
url = f"https://api.live.bilibili.com/lottery/v1/box/draw?aid={aid}&number={number}"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"{suname}实物抽奖编号{aid}第{number}轮次回显:{response}", "INFO", "blue")
return response
# 查询最新一条系统通知
async def query_system_notice(cookie, suname):
url = "https://message.bilibili.com/api/notify/query.sysnotify.list.do?data_type=1"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"{suname}最新一条系统通知回显:{response['data'][0]['content']}", "INFO", "blue")
return response
# 给评论点赞
async def comment_like(oid, otype, rpid, cookie, csrf, suname):
url = "https://api.bilibili.com/x/v2/reply/action"
data = {
'oid': oid,
'type': otype,
'rpid': rpid,
'action': 1,
'jsonp': "jsonp",
'csrf': csrf,
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"评论点赞回显:{response}", "INFO", "blue")
return response
# 给评论点踩
async def comment_hate(oid, otype, rpid, cookie, csrf, suname):
url = "https://api.bilibili.com/x/v2/reply/hate"
data = {
'oid': oid,
'type': otype,
'rpid': rpid,
'action': 1,
'jsonp': "jsonp",
'csrf': csrf,
}
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"评论点踩回显:{response}", "INFO", "blue")
return response
# 评论发送
async def comment_send(oid, otype, message, cookie, csrf, suname):
url = "https://api.bilibili.com/x/v2/reply/add"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
data = {
'oid': oid,
'type': otype,
'message': message,
'plat': 1,
'jsonp': "jsonp",
'csrf': csrf,
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"评论发送回显:{response}", "INFO", "blue")
return response
# 评论回复,需要多传入根评论id和父评论id
async def comment_reply(oid, otype, root, parent, message, cookie, csrf, suname):
url = "https://api.bilibili.com/x/v2/reply/add"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
data = {
'oid': oid,
'type': otype,
'root': root,
'parent': parent,
'message': message,
'plat': 1,
'jsonp': "jsonp",
'csrf': csrf,
}
response = await request.req_add_job('post', url, data=data, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"评论回复回显:{response}", "INFO", "blue")
return response
# 通过act_id进行抽奖
async def act_id_lottery(act_id, cookie, suname):
url = f"https://www.bilibili.com/matsuri/index?act_id={act_id}"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('post', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"{suname}参与{act_id}抽奖回显:{response}", "INFO", "blue")
return response
# 通过act_id进行获取抽奖次数
async def act_id_get_chance(act_id, cookie, suname):
url = f"https://www.bilibili.com/matsuri/add/lottery/times?act_id={act_id}"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"{suname}获取{act_id}抽奖机会回显:{response}", "INFO", "blue")
return response
# 通过act_id进行查看当前抽奖次数
async def act_id_check_chance(act_id, cookie, suname):
url = f"https://www.bilibili.com/matsuri/get/act/mylotterytimes?act_id={act_id}"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": cookie
}
response = await request.req_add_job('get', url, headers=headers, suname=suname)
response = json.loads(response)
printer.printer(f"{suname}查询{act_id}抽奖机会回显:{response}", "INFO", "blue")
return response