forked from lifegpc/bili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.py
2716 lines (2703 loc) · 110 KB
/
start.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
999
1000
# (C) 2019-2020 lifegpc
# This file is part of bili.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import os
import traceback
if '-c' in sys.argv:
try:
os.chdir(os.path.abspath(os.path.split(sys.argv[0])[0]))
except:
traceback.print_exc()
input()
import requests
import HTMLParser
import JSONParser
import PrintInfo
import biliLogin
import biliPlayerXmlParser
import biliDanmu
import biliTime
import chon
import videodownload
import biliBv
from re import search, I, match
import os
import sys
from command import gopt
import json
from math import ceil
from dictcopy import copyip, copydict
from biliHdVideo import HDVideoParser
import biliLiveDanmu
from lang import getlan, getdict
import JSONParser2
from threading import Thread
from biliVersion import checkver
from time import sleep, time
from Logger import Logger
from inspect import currentframe
from autoopenlist import autoopenfilelist
from urllib.parse import parse_qs, urljoin
from bstr import hasPar
# 远程调试用代码
# import ptvsd
# ptvsd.enable_attach(("0.0.0.0", 44123))
# ptvsd.wait_for_attach()
NOT_FOUND = -404
lan = None
se = JSONParser.loadset()
if se == -1 or se == -2:
se = {}
ip = {}
def main(ip={}, menuInfo=None):
"""ip 命令行参数字典
menuInfo AU号专辑/歌单信息"""
logg: Logger = ip['logg'] if 'logg' in ip else None
log = logg is not None
global se
global lan
uc = True # 是否检测更新
if JSONParser.getset(se, 'uc') is True:
uc = False
if 'uc' in ip:
uc = ip['uc']
if uc:
checkver(logg)
ns = True
if 's' in ip:
ns = False
if not isinstance(se, dict):
se = None
print(f'{lan["RUN_SETTINGS_TIPS"]}')
nte = False
if JSONParser.getset(se, 'te') is False:
nte = True
if 'te' in ip:
nte = not ip['te']
if 'i' in ip:
inp = ip['i']
elif ns:
inp = input(f"{lan['INPUT1']}{lan['OUTPUT13']}")
else:
print(f'{lan["ERROR1"]}')
return -1
inpl = inp.split(',')
if log:
logg.write(f"inp = '{inp}'\ninpl = {inpl}", currentframe(), 'Input URL')
mt = False
if JSONParser.getset(se, 'mt') is True:
mt = True
if 'mt' in ip:
mt = ip['mt']
if len(inpl) != 1:
for inp2 in inpl:
ip2 = copydict(ip)
ip2['i'] = inp2
ip2['uc'] = False # 禁用重复检测
if log:
logg.write(f"ip2 = {ip2}", currentframe(), 'multi-input parameters')
if mt:
ru = mains(ip2)
ru.start()
else:
read = main(ip2)
if read == NOT_FOUND:
continue
if read != 0:
return read
return 0
acfun = False # Acfun网站
acvideo = False # Acfun Video acxxxxx
acbangumi = False # Acfun Bangumi
av = False
ss = False
ep = False
pl = False # 收藏夹
hd = False # 互动视频
ch = False # 频道
uv = False # 投稿
md = False # 番剧信息页
sm = False # 小视频
lr = False # 直播回放
che = False # B站课程
chel = False # B站课程已购列表
live = False # 直播
au = False # 音频区音乐
ac = False # 音频区收藏夹/专辑/歌单
uid = -1 # 收藏夹/频道主人id
fid = -1 # 收藏夹id
cid = -1 # 频道id
uvd = {} # 投稿查询信息
pld = {} # 收藏夹扩展信息
chd = {} # 频道扩展信息
mid = -1 # md号
sid = -1 # 小视频id
rid = "" # 直播回放id
ssid = -1 # B站课程SS号
epid = -1 # B站课程EP号
auid = -1 # AU号
roomid = -1 # 直播房间ID
menuid = -1 # 音频区AM号
collid = -1 # 音频区收藏夹ID
acvideoid = -1 # Acfun AC号
acbangumiid = -1 # Acfun AA号
acepisodeid = -1 # Acfun 剧集号(EP号
if inp[0:2].lower() == 'ss' and inp[2:].isnumeric():
s = "https://www.bilibili.com/bangumi/play/ss" + inp[2:]
ss = True
if log and not logg.hasf():
logg.openf(f"log/SS{inp[2:]}_{round(time())}.log")
elif inp[0:2].lower() == 'ep' and inp[2:].isnumeric():
s = "https://www.bilibili.com/bangumi/play/ep" + inp[2:]
ep = True
if log and not logg.hasf():
logg.openf(f"log/EP{inp[2:]}_{round(time())}.log")
elif inp[0:2].lower() == 'av' and inp[2:].isnumeric():
s = "https://www.bilibili.com/video/av" + inp[2:]
av = True
if log and not logg.hasf():
logg.openf(f"log/AV{inp[2:]}_{round(time())}.log")
elif inp[0:2].lower() == 'bv':
inp = str(biliBv.debv(inp))
s = "https://www.bilibili.com/video/av" + inp
av = True
if log and not logg.hasf():
logg.openf(f"log/AV{inp}_{round(time())}.log")
elif inp[0:2].lower() == 'md' and inp[2:].isnumeric():
md = True
mid = int(inp[2:])
if log and not logg.hasf():
logg.openf(f"log/MD{inp}_{round(time())}.log")
elif inp[0:2].lower() == "au" and inp[2:].isnumeric():
au = True
auid = int(inp[2:])
if log and not logg.hasf():
logg.openf(f"log/AU{auid}_{round(time())}.log")
elif inp[0:2].lower() == "am" and inp[2:].isnumeric():
ac = True
menuid = int(inp[2:])
if log and not logg.hasf():
logg.openf(f"log/AM{menuid}_{round(time())}.log")
elif inp[:2].lower() == "ac" and inp[2:].isnumeric():
acfun = True
acvideo = True
acvideoid = int(inp[2:])
if log and not logg.hasf():
logg.openf(f"log/AC{acvideoid}_{round(time())}.log")
elif inp[:2].lower() == "aa" and inp[2:].isnumeric():
acfun = True
acbangumi = True
acbangumiid = int(inp[2:])
if log and not logg.hasf():
logg.openf(f"log/AA{acbangumiid}_{round(time())}.log")
elif inp[:2].lower() == "aa" and match(r'\d+_36188_\d+', inp[2:]):
rs = search(r'(\d+)_36188_(\d+)', inp[2:])
rs = rs.groups()
acfun = True
acbangumi = True
acbangumiid = int(rs[0])
acepisodeid = int(rs[1])
if log and not logg.hasf():
logg.openf(f"log/AA{acbangumiid}_{round(time())}.log")
elif inp.isnumeric():
s = "https://www.bilibili.com/video/av" + inp
av = True
if log and not logg.hasf():
logg.openf(f"log/AV{inp}_{round(time())}.log")
else:
re = search(r'([^:]+://)?(www\.)?(space\.)?(vc\.)?(m\.)?(live\.)?bilibili\.com/(s?/?video/av([0-9]+))?(s?/?video/(bv[0-9A-Z]+))?(bangumi/play/(ss[0-9]+))?(bangumi/play/(ep[0-9]+))?(([0-9]+)/favlist(\?(.+)?)?)?(([0-9]+)/channel/(index)?(detail\?(.+))?)?((([0-9]+)/video|medialist/play/([0-9]+))(\?.+)?)?(bangumi/media/md([0-9]+))?(video/([0-9]+))?(mobile/detail\?vc=([0-9]+))?(record/([^\?]+))?(cheese/play/ss([0-9]+))?(cheese/play/ep([0-9]+))?(v/cheese/mine/list)?(cheese/mine/list)?([0-9]+)?(audio/au([0-9]+))?(audio/mycollection/([0-9]+))?(audio/am([0-9]+))?(festival/[^/\?]+\?(.+))?', inp, I)
if re is None:
re = search(r'([^:]+://)?(www\.)?b23\.tv/(av([0-9]+))?(bv[0-9A-Z]+)?(ss[0-9]+)?(ep[0-9]+)?(au([0-9]+))?', inp, I)
if re is None:
re = search(r'([^:]+://)?(www\.)?acfun\.cn/(v/ac([0-9]+))?(bangumi/aa(\d+)(_36188_(\d+))?)?', inp)
if re is None:
re = search(r"[^:]+://", inp)
if re is None:
inp = "https://" + inp
re = requests.head(inp)
if 'Location' in re.headers:
ip['i'] = re.headers['Location']
ip['uc'] = False
return main(ip)
else:
print(f'{lan["ERROR2"]}') # 输入有误
return -1
else:
re = re.groups()
if log:
logg.write(f"re = {re}", currentframe(), "Input Regex 3")
if re[2]:
acfun = True
acvideo = True
acvideoid = int(re[3])
if log and not logg.hasf():
logg.openf(f"log/AC{acvideoid}_{round(time())}.log")
elif re[4]:
acfun = True
acbangumi = True
acbangumiid = int(re[5])
if re[6]:
acepisodeid = int(re[7])
if log and not logg.hasf():
logg.openf(f"log/AA{acbangumiid}_{round(time())}.log")
else:
print(f'{lan["ERROR2"]}') # 输入有误
return -1
else:
re = re.groups()
if log:
logg.write(f"re = {re}", currentframe(), "INPUT REGEX 2")
if re[3]:
inp = re[3]
s = "https://www.bilibili.com/video/av" + inp
av = True
if log and not logg.hasf():
logg.openf(f"log/AV{inp}_{round(time())}.log")
elif re[4]:
inp = str(biliBv.debv(re[4]))
s = "https://www.bilibili.com/video/av" + inp
av = True
if log and not logg.hasf():
logg.openf(f"log/AV{inp}_{round(time())}.log")
elif re[5]:
inp = re[5]
s = "https://www.bilibili.com/bangumi/play/" + inp
ss = True
if log and not logg.hasf():
logg.openf(f"log/SS{inp}_{round(time())}.log")
elif re[6]:
inp = re[6]
s = "https://www.bilibili.com/bangumi/play/" + inp
ep = True
if log and not logg.hasf():
logg.openf(f"log/EP{inp}_{round(time())}.log")
elif re[7]:
au = True
auid = int(re[8])
if log and not logg.hasf():
logg.openf(f"log/AU{auid}_{round(time())}.log")
else:
re = search(r"[^:]+://", inp)
if re is None:
inp = "https://" + inp
re = requests.head(inp)
if 'Location' in re.headers:
ip['i'] = re.headers['Location']
ip['uc'] = False
return main(ip)
else:
print(f'{lan["ERROR2"]}') # 输入有误
return -1
else:
re = re.groups()
if log:
logg.write(f"re = {re}", currentframe(), "INPUT REGEX 1")
if re[7]:
inp = re[7]
s = "https://www.bilibili.com/video/av" + inp
av = True
if log and not logg.hasf():
logg.openf(f"log/AV{inp}_{round(time())}.log")
elif re[9]:
inp = str(biliBv.debv(re[9]))
s = "https://www.bilibili.com/video/av" + inp
av = True
if log and not logg.hasf():
logg.openf(f"log/AV{inp}_{round(time())}.log")
elif re[11]:
inp = re[11]
s = "https://www.bilibili.com/bangumi/play/" + inp
ss = True
if log and not logg.hasf():
logg.openf(f"log/SS{inp}_{round(time())}.log")
elif re[13]:
inp = re[13]
s = "https://www.bilibili.com/bangumi/play/" + inp
ep = True
if log and not logg.hasf():
logg.openf(f"log/EP{inp}_{round(time())}.log")
elif re[15]:
pl = True
uid = int(re[15])
pld['k'] = ''
pld['t'] = 0
if re[17]:
sl = parse_qs(re[17])
if 'fid' in sl:
for s in sl['fid']:
if s.isnumeric():
fid = int(s)
break
if 'keyword' in sl:
pld['k'] = sl['keyword'][0]
if 'type' in sl:
for s in sl['type']:
if s.isnumeric():
pld['t'] = int(s)
break
if 'tid' in sl:
for s in sl['tid']:
if s.isnumeric():
pld['tid'] = int(s)
break
if 'order' in sl:
pld['order'] = sl['order'][0]
if 't' not in pld: # 如果没有指定使用默认值
pld['t'] = 0
if 'tid' not in pld:
pld['tid'] = 0
if 'order' not in pld:
pld['order'] = 'mtime'
if log and not logg.hasf():
if fid == -1:
logg.openf(f"log/UID{uid}_FAV_{round(time())}.log")
else:
logg.openf(f"log/FAV{fid}_{round(time())}.log")
if log:
logg.write(f"uid = {uid}\nfid = {fid}\npld = {pld}", currentframe(), "FAVLIST Parser")
elif re[18] and (re[20] or (re[22] and hasPar(re[22], 'cid', r'^([0-9]+)$'))):
ch = True
uid = int(re[19])
if re[22]:
ls = parse_qs(re[22])
if 'cid' in ls:
for v in ls['cid']:
if v.isnumeric():
cid = int(v)
break
if 'order' in ls:
for v in ls['order']:
if v.isnumeric():
chd['order'] = int(v)
break
if 'order' not in chd:
chd['order'] = 0
if log and not logg.hasf():
if cid == -1:
logg.openf(f"log/UID{uid}_CHID_{round(time())}.log")
else:
logg.openf(f"log/CHID{cid}_{round(time())}.log")
if log:
logg.write(f"uid = {uid}\ncid = {cid}", currentframe(), "CHANNEL Parser")
elif re[23]:
uv = True
uid = int(re[25]) if re[25] else int(re[26])
uvd['t'] = 0
uvd['k'] = ''
uvd['o'] = 'pubdate'
if re[27]:
sl = parse_qs(re[27][1:])
if 'tid' in sl:
for v in sl['tid']:
if v.isnumeric():
uvd['t'] = int(v)
break
if 'keyword' in sl:
uvd['k'] = sl['keyword'][0]
if 'order' in sl:
uvd['o'] = sl['order'][0]
if log and not logg.hasf():
logg.openf(f"log/UID{uid}_{round(time())}.log")
if log:
logg.write(f"uid = {uid}\nuvd = {uvd}", currentframe(), "UPLOADER VIDEO Parser")
elif re[28]:
md = True
mid = int(re[29])
if log and not logg.hasf():
logg.openf(f"log/MD{mid}_{round(time())}.log")
elif re[30]:
sm = True
sid = int(re[31])
if log and not logg.hasf():
logg.openf(f"log/SID{sid}_{round(time())}.log")
elif re[32]:
sm = True
sid = int(re[33])
if log and not logg.hasf():
logg.openf(f"log/SID{sid}_{round(time())}.log")
elif re[34]:
lr = True
rid = re[35]
if log and not logg.hasf():
logg.openf(f"log/RID{rid}_{round(time())}.log")
elif re[36]:
ss = True
che = True
ssid = int(re[37])
if log and not logg.hasf():
logg.openf(f"log/SS{ssid}_{round(time())}.log")
elif re[38]:
ep = True
che = True
epid = int(re[39])
if log and not logg.hasf():
logg.openf(f"log/EP{epid}_{round(time())}.log")
elif re[40] or re[41]:
chel = True
elif re[5] and re[42]:
live = True
roomid = int(re[42])
if log and not logg.hasf():
logg.openf(f"log/LIVEROOM{roomid}_{round(time())}.log")
elif re[43]:
au = True
auid = int(re[44])
if log and not logg.hasf():
logg.openf(f"log/AU{auid}_{round(time())}.log")
elif re[45]:
ac = True
collid = int(re[46])
if log and not logg.hasf():
logg.openf(f"log/COLL{collid}_{round(time())}.log")
elif re[47]:
ac = True
menuid == int(re[48])
if log and not logg.hasf():
logg.openf(f"log/AM{menuid}_{round(time())}.log")
elif re[49]:
para = parse_qs(re[50])
if 'bvid' in para:
inp = str(biliBv.debv(para['bvid'][0]))
s = "https://www.bilibili.com/video/av" + inp
av = True
if log and not logg.hasf():
logg.openf(f"log/AV{inp}_{round(time())}.log")
else:
print(f'{lan["ERROR2"]}')
return -1
else:
print(f'{lan["ERROR2"]}')
return -1
section = requests.session()
section.headers.update({"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36", "Connection": "keep-alive", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8"})
if 'httpproxy' in ip or 'httpsproxy' in ip:
pr = {}
if 'httpproxy' in ip:
pr['http'] = ip['httpproxy']
if 'httpsproxy' in ip:
pr['https'] = ip['httpsproxy']
section.proxies = pr
if nte:
section.trust_env = False
ckfn = "acfun_cookies.json" if acfun else "cookies.json"
read = JSONParser.loadcookie(section, logg, ckfn)
ud = {}
login = 0
if read == 0:
if acfun:
read = biliLogin.acCheckLogin(section, ud, logg)
else:
read = biliLogin.tryok(section, ud, logg)
if read is True:
if ns:
print(f"{lan['OUTPUT1']}") # 登录校验成功!
login = 1
elif read is False:
print(f'{lan["ERROR3"]}') # 网络错误!校验失败!
return -1
else:
print(f"{lan['WARN1']}") # 登录信息已过期!
login = 2
elif read == -1:
login = 2
else:
print(f"{lan['ERROR4']}") # 文件读取错误!
login = 2
if login == 2:
if os.path.exists(ckfn):
os.remove(ckfn)
if acfun:
read = biliLogin.acLogin(section, ud, ip, logg)
else:
read = biliLogin.login(section, ud, ip, logg)
if read == 0:
login = 1
elif read == 1:
return -1
else:
return -1
if 'd' not in ud:
return -1
if not acfun:
ud['vip'] = ud['d']['vipStatus']
if log:
logg.write(f"read = {read}\nlogin = {login}\nud = {ud}", currentframe(), "VERIFY LOGIN 2")
if sm:
if log:
logg.write(f"GET https://api.vc.bilibili.com/clip/v1/video/detail?video_id={sid}&need_playurl=1", currentframe(), "GET SMALL VIDEO INFO")
re = section.get('https://api.vc.bilibili.com/clip/v1/video/detail?video_id=%s&need_playurl=1' % (sid))
re.encoding = "utf8"
if log:
logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "SMALL VIDEO INFO RESULT")
re = re.json()
if re['code'] != 0:
print('%s %s' % (re['code'], re['message']))
if re['code'] == 65531:
return NOT_FOUND
return -1
inf = JSONParser2.getsmi(re)
if log:
logg.write(f"inf = {inf}", currentframe(), "READ SMALL VIDEO INFO")
if ns:
PrintInfo.printInfo9(inf)
cho5 = False
bs = True
if not ns:
bs = False
read = JSONParser.getset(se, 'cd')
if read is True:
bs = False
cho5 = True
elif read is False:
bs = False
if 'ac' in ip:
if ip['ac']:
bs = False
cho5 = True
else:
bs = False
cho5 = False
while bs:
inp = input(f'{lan["INPUT2"]}(y/n)') # 是否开启继续下载功能?
if len(inp) > 0:
if inp[0].lower() == 'y':
cho5 = True
bs = False
elif inp[0].lower() == 'n':
bs = False
if log:
logg.write(f"cho5 = {cho5}", currentframe(), "SMALL VIDEO para")
videodownload.smdownload(section, inf, cho5, se, ip)
return 0
if md:
if log:
logg.write(f"GET https://www.bilibili.com/bangumi/media/md{mid}", currentframe(), "GET MD WEBPAGE")
re = section.get('https://www.bilibili.com/bangumi/media/md%s' % (mid))
re.encoding = "utf8"
if log:
logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "MD WEBPAGE CONTENT")
rs = search(r'__INITIAL_STATE__=([^;]+)', re.text, I)
if rs is not None:
rs = rs.groups()[0]
if log:
logg.write(f"rs = {rs}", currentframe(), "MD WEBPAGE REGEX CONTENT")
try:
re = json.loads(rs)
except json.JSONDecodeError:
if log:
logg.write(traceback.format_exc(), currentframe(), "MD WEBPAGE LOAD JSON ERROR")
pa = HTMLParser.Myparser3()
pa.feed(re.text)
if log:
logg.write(f"pa.videodata = {pa.videodata}", currentframe(), "MD WABPAGE JSON CONTENT")
try:
re = json.loads(pa.videodata)
except json.JSONDecodeError:
if log:
logg.write(traceback.format_exc(), currentframe(), "MD WEBPAGE LOAD JSON ERROR 2")
print(f'{lan["ERROR5"]}') # md号解析失败
return -1
ip2 = copyip(ip)
if 'p' in ip:
ip2['p'] = ip['p']
ip2['i'] = 'ss%s' % (re['mediaInfo']['season_id'])
ip2['uc'] = False
if log:
logg.write(f"ip2 = {ip2}", currentframe(), "MD REDIRECT PARAMETERS")
read = main(ip2)
if log:
logg.write(f"read = {read}", currentframe(), "MD REDIRECT RETURN")
if read != 0 and read != NOT_FOUND:
return read
else:
print(f'{lan["ERROR5"]}') # md号解析失败
return -1
return 0
if pl:
if fid == -1:
af = False
if JSONParser.getset(se, 'af') is True:
af = True
if 'af' in ip:
af = ip['af']
if log:
logg.write(f"af = {af}\nGET https://api.bilibili.com/x/v3/fav/folder/created/list-all?up_mid={uid}&jsonp=jsonp", currentframe(), "PL PARAMETERS & GET LIST")
re = section.get('https://api.bilibili.com/x/v3/fav/folder/created/list-all?up_mid=%s&jsonp=jsonp' % (uid))
re.encoding = 'utf8'
if log:
logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "PL GET LIST RETURN")
re = re.json()
if re['code'] != 0:
print('%s %s' % (re['code'], re['message']))
return -1
else:
if 'data' in re and re['data'] is not None and 'list' in re['data'] and re['data']['count'] > 0:
if af:
dc = re['data']['count']
if ns:
PrintInfo.printInfo8(re)
bs = True
f = True
while bs:
if f and 'afp' in ip:
f = False
inp = ip['afp']
elif ns:
inp = input(f'{lan["INPUT3"]}')
else:
print(f'{lan["ERROR6"]}')
return -1
cho = []
if len(inp) > 0 and inp[0] == 'a':
if ns:
print(f'{lan["OUTPUT2"]}')
for i in range(1, dc + 1):
cho.append(i)
bs = False
elif len(inp) > 0:
inp = inp.split(',')
bb = True
for i in inp:
if i.isnumeric() and int(i) > 0 and int(i) <= dc and (not (int(i) in cho)):
cho.append(int(i))
else:
rrs = search(r"([0-9]+)-([0-9]+)", i)
if rrs is not None:
rrs = rrs.groups()
i1 = int(rrs[0])
i2 = int(rrs[1])
if i2 < i1:
tt = i1
i1 = i2
i2 = tt
for i in range(i1, i2 + 1):
if i > 0 and i <= dc and (not (i in cho)):
cho.append(i)
else:
bb = False
if bb:
bs = False
for i in cho:
if ns:
print(lan['OUTPUT3'] + str(i) + "," + re['data']['list'][i - 1]['title'])
for i in cho:
ip2 = copyip(ip)
ip2['i'] = "https://space.bilibili.com/%s/favlist?fid=%s" % (uid, re['data']['list'][i - 1]['id'])
ip2['uc'] = False
if log:
logg.write(f"ip2 = {ip2}", currentframe(), "PL MULTPLY-PL PRARMETERS")
read = main(ip2)
if read != 0:
return read
if log:
logg.write(f"read = {read}", currentframe(), "PL MULTPLY-PL RETURN")
return 0
else:
fid = re['data']['list'][0]['id']
else:
print(lan["ERROR7"])
return NOT_FOUND
if log:
logg.write(f"fid = {fid}", currentframe(), "PL FID OUT")
if 'ltid' in ip:
re = JSONParser2.getpltid(section, fid, uid, logg)
if re == -1:
return -1
if len(re) > 0:
print(lan['PLITID'])
PrintInfo.printplitid(re)
else:
print(lan['PLITIDNUL'])
return 0
i = 1
re = JSONParser2.getpli(section, fid, i, pld, logg)
if re == -1:
return -1
pli = JSONParser2.getplinfo(re)
if log:
logg.write(f"pli = {pli}", currentframe(), "PL INFO RESULT")
if ns:
PrintInfo.printInfo3(pli)
n = ceil(pli['count'] / 20)
plv = []
JSONParser2.getpliv(plv, re)
while i < n:
i = i + 1
re = JSONParser2.getpli(section, fid, i, pld, logg)
if re == -1:
return -1
JSONParser2.getpliv(plv, re)
if log:
logg.write(f"plv = {plv}", currentframe(), "PL VIDEO LIST RESULT")
if len(plv) != pli['count']:
print(lan['ERROR8']) # 视频数量与预计数量不符,貌似BUG了。
return -1
if ns:
PrintInfo.printInfo4(plv)
bs = True
f = True
while bs:
if f and 'p' in ip:
f = False
inp = ip['p']
elif ns:
inp = input(lan['OUTPUT4']) # 请输入你想下载的视频编号(每两个编号间用,隔开,全部下载可输入a):
else:
print(lan['ERROR9']) # 请使用-p <number>选择视频编号
return -1
cho = []
if inp[0] == 'a':
if ns:
print(lan['OUTPUT5']) # 您全选了所有视频
for i in range(1, pli['count'] + 1):
cho.append(i)
bs = False
else:
inp = inp.split(',')
bb = True
for i in inp:
if i.isnumeric() and int(i) > 0 and int(i) <= pli['count'] and (not (int(i) in cho)):
cho.append(int(i))
else:
rrs = search(r"([0-9]+)-([0-9]+)", i)
if rrs is not None:
rrs = rrs.groups()
i1 = int(rrs[0])
i2 = int(rrs[1])
if i2 < i1:
tt = i1
i1 = i2
i2 = tt
for i in range(i1, i2 + 1):
if i > 0 and i <= pli['count'] and (not (i in cho)):
cho.append(i)
else:
bb = False
if bb:
bs = False
for i in cho:
if ns:
print(lan['OUTPUT6'] + str(i) + ',' + plv[i - 1]['title']) # 您选中了视频:
bs = True
c1 = False
if not ns:
bs = False
read = JSONParser.getset(se, 'da')
if read is not None:
c1 = read
bs = False
if 'da' in ip:
c1 = ip['da']
bs = False
while bs:
inp = input(f"{lan['INPUT4']}(y/n)") # 是否自动下载每一个视频的所有分P?
if len(inp) > 0:
if inp[0].lower() == 'y':
c1 = True
bs = False
elif inp[0].lower() == 'n':
bs = False
if log:
logg.write(f"c1 = {c1}", currentframe(), "PLI PARAMETERS")
for i in cho:
ip2 = copyip(ip)
ip2['i'] = str(plv[i - 1]['id'])
ip2['uc'] = False
if c1:
ip2['p'] = 'a'
if log:
logg.write(f"ip2 = {ip2}", currentframe(), "PLI PARAMETERS 2")
read = main(ip2)
if log:
logg.write(f"read = {read}", currentframe(), "PLI RETURN")
if read != 0 and read != NOT_FOUND:
return read
return 0
if ch:
r = requests.Session()
r.headers = copydict(section.headers)
r.proxies = section.proxies
if nte:
r.trust_env = False
read = JSONParser.loadcookie(r, logg)
if read != 0:
print(lan['ERROR10']) # 读取cookies.json出现错误
return -1
r.cookies.set('CURRENT_QUALITY', '125', domain='.bilibili.com', path='/')
r.cookies.set('CURRENT_FNVAL', '80', domain='.bilibili.com', path='/')
r.cookies.set('laboratory', '1-1', domain='.bilibili.com', path='/')
r.cookies.set('stardustvideo', '1', domain='.bilibili.com', path='/')
if cid == -1:
r.headers.update({'referer': 'https://space.bilibili.com/%s/channel/index' % (uid)})
if log:
logg.write(f"GET https://api.bilibili.com/x/space/channel/list?mid={uid}&guest=false&jsonp=jsonp", currentframe(), "GET CHANNEL LIST")
re = r.get("https://api.bilibili.com/x/space/channel/list?mid=%s&guest=false&jsonp=jsonp" % (uid))
re.encoding = 'utf8'
if log:
logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "GET CHANNEL LIST RESULT")
re = re.json()
if re['code'] != 0:
print('%s %s' % (re['code'], re['message']))
return -1
chl = JSONParser2.getchl(re)
if log:
logg.write(f"chl = {chl}", currentframe(), "CHANNEL LIST RESULT")
if len(chl) == 0:
return NOT_FOUND
if ns:
PrintInfo.printInfo5(chl)
bs = True
f = True
while bs:
if f and 'p' in ip:
f = False
inp = ip['p']
elif ns:
inp = input(lan['INPUT5']) # 请输入你想下载的频道(每两个编号间用,隔开,全部下载可输入a):
else:
print(lan['ERROR9']) # 请使用-p <number>选择视频编号
return -1
cho = []
if inp[0] == 'a':
if ns:
print(lan['OUTPUT7']) # 您全选了所有频道
for i in range(1, len(chl) + 1):
cho.append(i)
bs = False
else:
inp = inp.split(',')
bb = True
for i in inp:
if i.isnumeric() and int(i) > 0 and int(i) <= len(chl) and (not (int(i) in cho)):
cho.append(int(i))
else:
rrs = search(r"([0-9]+)-([0-9]+)", i)
if rrs is not None:
rrs = rrs.groups()
i1 = int(rrs[0])
i2 = int(rrs[1])
if i2 < i1:
tt = i1
i1 = i2
i2 = tt
for i in range(i1, i2 + 1):
if i > 0 and i <= len(chl) and (not (i in cho)):
cho.append(i)
else:
bb = False
if bb:
bs = False
for i in cho:
if ns:
print(lan['OUTPUT8'] + str(i) + ',' + chl[i - 1]['name']) # 您选中了频道:
for i in cho:
ip2 = copyip(ip)
ip2['i'] = 'https://space.bilibili.com/%s/channel/detail?cid=%s' % (uid, chl[i - 1]['cid'])
ip2['uc'] = False
if log:
logg.write(f"ip2 = {ip2}", currentframe(), "CHANNLE LIST PARAMETERS")
read = main(ip2)
if log:
logg.write(f"read = {read}", currentframe(), "CHANNLE LIST RESULT")
if read != 0 and read != NOT_FOUND:
return read
return 0
r.headers.update({'referer': 'https://space.bilibili.com/%s/channel/detail?cid=%s' % (uid, cid)})
re = JSONParser2.getchi(r, uid, cid, 1, chd, logg)
if re == -1:
return -1
chi = JSONParser2.getchn(re)
if log:
logg.write(f"chi = {chi}", currentframe(), "CHANNLE INFO RESULT")
n = ceil(chi['count'] / 30)
i = 1
chv = []
JSONParser2.getchs(chv, re)
while i < n:
i = i + 1
re = JSONParser2.getchi(r, uid, cid, i, chd, logg)
if re == -1:
return -1
JSONParser2.getchs(chv, re)
if log:
logg.write(f"chv = {chv}", currentframe(), "CHANNLE VIDEO LIST RESULT")
if len(chv) == 0:
return NOT_FOUND
if chi['count'] != len(chv):
print(lan['ERROR8']) # 视频数量与预计数量不符,貌似BUG了。
return -1
if ns:
PrintInfo.printInfo6(chv, chi)
bs = True
f = True
while bs:
if f and 'p' in ip:
f = False
inp = ip['p']
elif ns:
inp = input(lan['OUTPUT4']) # 请输入你想下载的视频编号(每两个编号间用,隔开,全部下载可输入a):
else:
print(lan['ERROR9']) # 请使用-p <number>选择视频编号
return -1
cho = []
if inp[0] == 'a':
if ns:
print(lan['OUTPUT5']) # 您全选了所有视频
for i in range(1, chi['count'] + 1):
cho.append(i)
bs = False
else:
inp = inp.split(',')
bb = True
for i in inp:
if i.isnumeric() and int(i) > 0 and int(i) <= chi['count'] and (not (int(i) in cho)):
cho.append(int(i))
else:
rrs = search(r"([0-9]+)-([0-9]+)", i)
if rrs is not None:
rrs = rrs.groups()
i1 = int(rrs[0])
i2 = int(rrs[1])
if i2 < i1:
tt = i1
i1 = i2
i2 = tt
for i in range(i1, i2 + 1):
if i > 0 and i <= chi['count'] and (not (i in cho)):
cho.append(i)
else:
bb = False
if bb:
bs = False
for i in cho:
if ns:
print(lan['OUTPUT6'] + str(i) + ',' + chv[i - 1]['title']) # 您选中了视频:
bs = True
c1 = False
if not ns:
bs = False
read = JSONParser.getset(se, 'da')
if read is not None:
c1 = read