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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
"""

bilibili_api.bangumi



番剧相关



概念:

+ media_id: 番剧本身的 ID,有时候也是每季度的 ID,如 https://www.bilibili.com/bangumi/media/md28231846/

+ season_id: 每季度的 ID

+ episode_id: 每集的 ID,如 https://www.bilibili.com/bangumi/play/ep374717



"""

import datetime
from enum import Enum
from typing import Any, List, Tuple, Union, Optional

from bilibili_api.utils.danmaku import Danmaku

from . import settings
from .video import Video
from .utils.utils import get_api
from .utils.credential import Credential
from .exceptions.ApiException import ApiException
from .utils.network import Api, get_session, HEADERS
from .utils.initial_state import (
    get_initial_state,
    get_initial_state_sync,
    InitialDataType,
)

API = get_api("bangumi")


episode_data_cache = {}


class BangumiCommentOrder(Enum):
    """

    短评 / 长评 排序方式



    + DEFAULT: 默认

    + CTIME: 发布时间倒序

    """

    DEFAULT = 0
    CTIME = 1


class BangumiType(Enum):
    """

    番剧类型



    + BANGUMI: 番剧

    + FT: 影视

    + GUOCHUANG: 国创

    """

    BANGUMI = 1
    FT = 3
    GUOCHUANG = 4


async def get_timeline(type_: BangumiType, before: int = 7, after: int = 0) -> dict:
    """

    获取番剧时间线



    Args:

        type_(BangumiType): 番剧类型

        before(int)       : 几天前开始(0~7), defaults to 7

        after(int)        : 几天后结束(0~7), defaults to 0

    """
    api = API["info"]["timeline"]
    params = {"types": type_.value, "before": before, "after": after}
    return await Api(**api).update_params(**params).result


class IndexFilter:
    """

    番剧索引相关固定参数以及值

    """

    class Type(Enum):
        """

        索引类型



        + ANIME: 番剧

        + MOVIE: 电影

        + DOCUMENTARY: 纪录片

        + GUOCHUANG: 国创

        + TV: 电视剧

        + VARIETY: 综艺

        """

        ANIME = 1
        MOVIE = 2
        DOCUMENTARY = 3
        GUOCHUANG = 4
        TV = 5
        VARIETY = 7

    class Version(Enum):
        """

        番剧版本



        + ALL: 全部

        + MAIN: 正片

        + FILM: 电影

        + OTHER: 其他

        """

        ALL = -1
        MAIN = 1
        FILM = 2
        OTHER = 3

    class Spoken_Language(Enum):
        """

        配音



        + ALL: 全部

        + ORIGINAL: 原声

        + CHINESE: 中配

        """

        ALL = -1
        ORIGINAL = 1
        CHINESE = 2

    class Finish_Status(Enum):
        """

        完结状态



        + ALL: 全部

        + FINISHED: 完结

        + UNFINISHED: 连载

        """

        ALL = -1
        FINISHED = 1
        UNFINISHED = 0

    class Copyright(Enum):
        """

        版权方



        + ALL: 全部

        + EXCLUSIVE: 独家

        + OTHER: 其他

        """

        ALL = -1
        EXCLUSIVE = 3
        OTHER = "1,2,4"

    class Season(Enum):
        """

        季度



        + ALL: 全部

        + SPRING: 春季

        + SUMMER: 夏季

        + AUTUMN: 秋季

        + WINTER: 冬季

        """

        ALL = -1
        WINTER = 1
        SPRING = 4
        SUMMER = 7
        AUTUMN = 10

    @staticmethod
    def make_time_filter(

        start: Optional[Union[datetime.datetime, str, int]] = None,

        end: Optional[Union[datetime.datetime, str, int]] = None,

        include_start: bool = True,

        include_end: bool = False,

    ) -> str:
        """

        生成番剧索引所需的时间条件



        番剧、国创直接传入年份,为 int 或者 str 类型,如 `make_time_filter(start=2019, end=2020)`



        影视、纪录片、电视剧传入 datetime.datetime,如 `make_time_filter(start=datetime.datetime(2019, 1, 1), end=datetime.datetime(2020, 1, 1))`



        start 或 end 为 None 时则表示不设置开始或结尾



        Args:

            start (datetime, str, int): 开始时间. 如果是 None 则不设置开头.



            end   (datetime, str, int): 结束时间. 如果是 None 则不设置结尾.



            include_start (bool): 是否包含开始时间. 默认为 True.



            include_end   (bool): 是否包含结束时间. 默认为 False.



        Returns:

            str: 年代条件

        """
        start_str = ""
        end_str = ""

        if start != None:
            if isinstance(start, datetime.datetime):
                start_str = start.strftime("%Y-%m-%d %H:%M:%S")
            else:
                start_str = start
        if end != None:
            if isinstance(end, datetime.datetime):
                end_str = end.strftime("%Y-%m-%d %H:%M:%S")
            else:
                end_str = end

        # 是否包含边界
        if include_start:
            start_str = f"[{start_str}"
        else:
            start_str = f"({start_str}"
        if include_end:
            end_str = f"{end_str}]"
        else:
            end_str = f"{end_str})"

        return f"{start_str},{end_str}"

    class Producer(Enum):
        """

        制作方



        + ALL: 全部

        + CCTV: CCTV

        + BBC: BBC

        + DISCOVERY: 探索频道

        + NATIONAL_GEOGRAPHIC: 国家地理

        + NHK: NHK

        + HISTORY: 历史频道

        + SATELLITE: 卫视

        + SELF: 自制

        + ITV: ITV

        + SKY: SKY

        + ZDF: ZDF

        + PARTNER: 合作机构

        + SONY: 索尼

        + GLOBAL_NEWS: 环球

        + PARAMOUNT: 派拉蒙

        + WARNER: 华纳

        + DISNEY: 迪士尼

        + DOMESTIC_OTHER: 国内其他

        + FOREIGN_OTHER: 国外其他

        """

        ALL = -1
        CCTV = 4
        BBC = 1
        DISCOVERY = 7
        NATIONAL_GEOGRAPHIC = 14
        NHK = 2
        HISTORY = 6
        SATELLITE = 8
        SELF = 9
        ITV = 5
        SKY = 3
        ZDF = 10
        PARTNER = 11
        DOMESTIC_OTHER = 12
        FOREIGN_OTHER = 13
        SONY = 15
        GLOBAL_NEWS = 16
        PARAMOUNT = 17
        WARNER = 18
        DISNEY = 19

    class Payment(Enum):
        """

        观看条件



        + ALL: 全部

        + FREE: 免费

        + PAID: 付费

        + VIP: 大会员

        """

        ALL = -1
        FREE = 1
        PAID = "2,6"
        VIP = "4,6"

    class Area(Enum):
        """

        地区



        + ALL: 全部

        + CHINA: 中国

        + CHINA_MAINLAND: 中国大陆

        + CHINA_HONGKONG_AND_TAIWAN: 中国港台

        + JAPAN: 日本

        + USA: 美国

        + UK: 英国

        + SOUTH_KOREA: 韩国

        + FRANCE: 法国

        + THAILAND: 泰国

        + GERMANY: 德国

        + ITALY: 意大利

        + SPAIN: 西班牙

        + ANIME_OTHER: 番剧其他

        + MOVIE_OTHER: 影视其他

        + DOCUMENTARY_OTHER: 纪录片其他



        注意:各索引的 其他 表示的地区都不同

        """

        ALL = "-1"
        CHINA = "1,6,7"
        CHINA_MAINLAND = "1"
        CHINA_HONGKONG_AND_TAIWAN = "6,7"
        JAPAN = "2"
        USA = "3"
        UK = "4"
        SOUTH_KOREA = "8"
        FRANCE = "9"
        THAILAND = "10"
        GERMANY = "15"
        ITALY = "35"
        SPAIN = "13"
        ANIME_OTHER = "1,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"
        TV_OTHER = "5,8,9,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"
        MOVIE_OTHER = "5,11,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,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"

    class Style:
        """

        风格,根据索引不同,可选的风格也不同

        """

        class Anime(Enum):
            """

            番剧风格



            + ALL: 全部

            + ORIGINAL: 原创

            + COMIC: 漫画改

            + NOVEL: 小说改

            + GAME: 游戏改

            + TOKUSATSU: 特摄

            + BUDAIXI: 布袋戏

            + WARM: 热血

            + TIMEBACK: 穿越

            + IMAGING: 奇幻

            + WAR: 战斗

            + FUNNY: 搞笑

            + DAILY: 日常

            + SCIENCE_FICTION: 科幻

            + MOE: 萌系

            + HEAL: 治愈

            + SCHOOL: 校园

            + CHILDREN: 儿童

            + NOODLES: 泡面

            + LOVE: 恋爱

            + GIRLISH: 少女

            + MAGIC: 魔法

            + ADVENTURE: 冒险

            + HISTORY: 历史

            + ALTERNATE: 架空

            + MACHINE_BATTLE: 机战

            + GODS_DEM: 神魔

            + VOICE: 声控

            + SPORT: 运动

            + INSPIRATION: 励志

            + MUSIC: 音乐

            + ILLATION: 推理

            + SOCIEITES: 社团

            + OUTWIT: 智斗

            + TEAR: 催泪

            + FOOD: 美食

            + IDOL: 偶像

            + OTOME: 乙女

            + WORK: 职场

            """

            ALL = -1
            ORIGINAL = 10010
            COMIC = 10011
            NOVEL = 10012
            GAME = 10013
            TOKUSATSU = 10102
            BUDAIXI = 10015
            WARM = 10016
            TIMEBACK = 10017
            IMAGING = 10018
            WAR = 10020
            FUNNY = 10021
            DAILY = 10022
            SCIENCE_FICTION = 10023
            MOE = 10024
            HEAL = 10025
            SCHOOL = 10026
            CHILDREN = 10027
            NOODLES = 10028
            LOVE = 10029
            GIRLISH = 10030
            MAGIC = 10031
            ADVENTURE = 10032
            HISTORY = 10033
            ALTERNATE = 10034
            MACHINE_BATTLE = 10035
            GODS_DEMONS = 10036
            VOICE = 10037
            SPORTS = 10038
            INSPIRATIONAL = 10039
            MUSIC = 10040
            ILLATION = 10041
            SOCIETIES = 10042
            OUTWIT = 10043
            TEAR = 10044
            FOODS = 10045
            IDOL = 10046
            OTOME = 10047
            WORK = 10048

        class Movie(Enum):
            """

            电影风格



            + ALL: 全部

            + SKETCH: 短片

            + PLOT: 剧情

            + COMEDY: 喜剧

            + ROMANTIC: 爱情

            + ACTION: 动作

            + SCAIRIER: 恐怖

            + SCIENCE_FICTION: 科幻

            + CRIME: 犯罪

            + TIRILLER: 惊悚

            + SUSPENSE: 悬疑

            + IMAGING: 奇幻

            + WAR: 战争

            + ANIME: 动画

            + BIOAGRAPHY: 传记

            + FAMILY: 家庭

            + SING_DANCE: 歌舞

            + HISTORY: 历史

            + DISCOVER: 探险

            + DOCUMENTARY: 纪录片

            + DISATER: 灾难

            + COMIC: 漫画改

            + NOVEL: 小说改

            """

            ALL = -1
            SKETCH = 10104
            PLOT = 10050
            COMEDY = 10051
            ROMANTIC = 10052
            ACTION = 10053
            SCAIRIER = 10054
            SCIENCE_FICTION = 10023
            CRIME = 10055
            TIRILLER = 10056
            SUSPENSE = 10057
            IMAGING = 10018
            WAR = 10058
            ANIME = 10059
            BIOAGRAPHY = 10060
            FAMILY = 10061
            SING_DANCE = 10062
            HISTORY = 10033
            DISCOVER = 10032
            DOCUMENTARY = 10063
            DISATER = 10064
            COMIC = 10011
            NOVEL = 10012

        class GuoChuang(Enum):
            """

            国创风格



            + ALL: 全部

            + ORIGINAL: 原创

            + COMIC: 漫画改

            + NOVEL: 小说改

            + GAME: 游戏改

            + DYNAMIC: 动态漫

            + BUDAIXI: 布袋戏

            + WARM: 热血

            + IMAGING: 奇幻

            + FANTASY: 玄幻

            + WAR: 战斗

            + FUNNY: 搞笑

            + WUXIA: 武侠

            + DAILY: 日常

            + SCIENCE_FICTION: 科幻

            + MOE: 萌系

            + HEAL: 治愈

            + SUSPENSE: 悬疑

            + SCHOOL: 校园

            + CHILDREN: 少儿

            + NOODLES: 泡面

            + LOVE: 恋爱

            + GIRLISH: 少女

            + MAGIC: 魔法

            + HISTORY: 历史

            + MACHINE_BATTLE: 机战

            + GODS_DEMONS: 神魔

            + VOICE: 声控

            + SPORT: 运动

            + INSPIRATION: 励志

            + MUSIC: 音乐

            + ILLATION: 推理

            + SOCIEITES: 社团

            + OUTWIT: 智斗

            + TEAR: 催泪

            + FOOD: 美食

            + IDOL: 偶像

            + OTOME: 乙女

            + WORK: 职场

            + ANCIENT: 古风

            """

            ALL = -1
            ORIGINAL = 10010
            COMIC = 10011
            NOVEL = 10012
            GAME = 10013
            DYNAMIC = 10014
            BUDAIXI = 10015
            WARM = 10016
            IMAGING = 10018
            FANTASY = 10019
            WAR = 10020
            FUNNY = 10021
            WUXIA = 10078
            DAILY = 10022
            SCIENCE_FICTION = 10023
            MOE = 10024
            HEAL = 10025
            SUSPENSE = 10057
            SCHOOL = 10026
            CHILDREN = 10027
            NOODLES = 10028
            LOVE = 10029
            GIRLISH = 10030
            MAGIC = 10031
            HISTORY = 10033
            MACHINE_BATTLE = 10035
            GODS_DEMONS = 10036
            VOICE = 10037
            SPORTS = 10038
            INSPIRATIONAL = 10039
            MUSIC = 10040
            ILLATION = 10041
            SOCIETIES = 10042
            OUTWIT = 10043
            TEAR = 10044
            FOODS = 10045
            IDOL = 10046
            OTOME = 10047
            WORK = 10048
            ANCIENT = 10049

        class TV(Enum):
            """

            电视剧风格



            + ALL: 全部

            + FUNNY: 搞笑

            + IMAGING: 奇幻

            + WAR: 战争

            + WUXIA: 武侠

            + YOUTH: 青春

            + SKETCH: 短剧

            + CITY: 都市

            + ANCIENT: 古装

            + SPY: 谍战

            + CLASSIC: 经典

            + EMOTION: 情感

            + SUSPENSE: 悬疑

            + INSPIRATION: 励志

            + MYTH: 神话

            + TIMEBACK: 穿越

            + YEAR: 年代

            + COUNTRYSIDE: 乡村

            + INVESTIGATION: 刑侦

            + PLOT: 剧情

            + FAMILY: 家庭

            + HISTORY: 历史

            + ARMY: 军旅

            """

            ALL = -1
            FUNNY = 10021
            IMAGING = 10018
            WAR = 10058
            WUXIA = 10078
            YOUTH = 10079
            SKETCH = 10103
            CITY = 10080
            COSTUME = 10081
            SPY = 10082
            CLASSIC = 10083
            EMOTION = 10084
            SUSPENSE = 10057
            INSPIRATIONAL = 10039
            MYTH = 10085
            TIMEBACK = 10017
            YEAR = 10086
            COUNTRYSIDE = 10087
            INVESTIGATION = 10088
            PLOT = 10050
            FAMILY = 10061
            HISTORY = 10033
            ARMY = 10089

        class Documentary(Enum):
            """

            纪录片风格



            + ALL: 全部

            + HISTORY: 历史

            + FOODS: 美食

            + HUMANITIES: 人文

            + TECHNOLOGY: 科技

            + DISCOVER: 探险

            + UNIVERSE: 宇宙

            + PETS: 萌宠

            + SOCIAL: 社会

            + ANIMALS: 动物

            + NATURE: 自然

            + MEDICAL: 医疗

            + WAR: 战争

            + DISATER: 灾难

            + INVESTIGATIONS: 罪案

            + MYSTERIOUS: 神秘

            + TRAVEL: 旅行

            + SPORTS: 运动

            + MOVIES: 电影

            """

            ALL = -1
            HISTORY = 10033
            FOODS = 10045
            HUMANITIES = 10065
            TECHNOLOGY = 10066
            DISCOVER = 10067
            UNIVERSE = 10068
            PETS = 10069
            SOCIAL = 10070
            ANIMALS = 10071
            NATURE = 10072
            MEDICAL = 10073
            WAR = 10074
            DISATER = 10064
            INVESTIGATIONS = 10075
            MYSTERIOUS = 10076
            TRAVEL = 10077
            SPORTS = 10038
            MOVIES = -10

        class Variety(Enum):
            """

            综艺风格



            + ALL: 全部

            + MUSIC: 音乐

            + TALK: 访谈

            + TALK_SHOW: 脱口秀

            + REALITY_SHOW: 真人秀

            + TALENT_SHOW: 选秀

            + FOOD: 美食

            + TRAVEL: 旅行

            + SOIREE: 晚会

            + CONCERT: 演唱会

            + EMOTION: 情感

            + COMEDY: 喜剧

            + PARENT_CHILD: 亲子

            + CULTURE: 文化

            + OFFICE: 职场

            + PET: 萌宠

            + CULTIVATE: 养成



            """

            ALL = -1
            MUSIC = 10040
            TALK = 10091
            TALK_SHOW = 10081
            REALITY_SHOW = 10092
            TALENT_SHOW = 10094
            FOOD = 10045
            TRAVEL = 10095
            SOIREE = 10098
            CONCERT = 10096
            EMOTION = 10084
            COMEDY = 10051
            PARENT_CHILD = 10097
            CULTURE = 10100
            OFFICE = 10048
            PET = 10069
            CULTIVATE = 10099

    class Sort(Enum):
        """

        排序方式



        + DESC: 降序

        + ASC: 升序

        """

        DESC = "0"
        ASC = "1"

    class Order(Enum):
        """

        排序字段



        + UPDATE: 更新时间

        + DANMAKU: 弹幕数量

        + PLAY: 播放数量

        + FOLLOWER: 追番人数

        + SOCRE: 最高评分

        + ANIME_RELEASE: 番剧开播日期

        + MOVIE_RELEASE: 电影上映日期

        """

        UPDATE = "0"
        DANMAKU = "1"
        PLAY = "2"
        FOLLOWER = "3"
        SCORE = "4"
        ANIME_RELEASE = "5"
        MOVIE_RELEASE = "6"


class IndexFilterMeta:
    """

    IndexFilter 元数据



    用于传入 get_index_info 方法

    """

    class Anime:
        def __init__(

            self,

            version: IndexFilter.Version = IndexFilter.Version.ALL,

            spoken_language: IndexFilter.Spoken_Language = IndexFilter.Spoken_Language.ALL,

            area: IndexFilter.Area = IndexFilter.Area.ALL,

            finish_status: IndexFilter.Finish_Status = IndexFilter.Finish_Status.ALL,

            copyright: IndexFilter.Copyright = IndexFilter.Copyright.ALL,

            payment: IndexFilter.Payment = IndexFilter.Payment.ALL,

            season: IndexFilter.Season = IndexFilter.Season.ALL,

            year: str = -1,

            style: IndexFilter.Style.Anime = IndexFilter.Style.Anime.ALL,

        ) -> None:
            """

            Anime Meta

            Args:

                version (Index_Filter.Version): 类型,如正片、电影等



                spoken_language (Index_Filter.Spoken_Language): 配音



                area (Index_Filter.Area): 地区



                finish_status (Index_Filter.Finish_Status): 是否完结



                copyright (Index_Filter.Copryright): 版权



                payment (Index_Filter.Payment): 付费门槛



                season (Index_Filter.Season): 季度



                year (str): 年份,调用 Index_Filter.make_time_filter() 传入年份 (int, str) 获取



                style (Index_Filter.Style.Anime): 风格

            """
            self.season_type = IndexFilter.Type.ANIME
            self.season_version = version
            self.spoken_language_type = spoken_language
            self.area = area
            self.is_finish = finish_status
            self.copyright = copyright
            self.season_status = payment
            self.season_month = season
            self.year = year
            self.style_id = style

    class Movie:
        def __init__(

            self,

            area: IndexFilter.Area = IndexFilter.Area.ALL,

            release_date: str = -1,

            style: IndexFilter.Style.Movie = IndexFilter.Style.Movie.ALL,

            payment: IndexFilter.Payment = IndexFilter.Payment.ALL,

        ) -> None:
            """

            Movie Meta

            Args:

                area (Index_Filter.Area): 地区



                payment (Index_Filter.Payment): 付费门槛



                season (Index_Filter.Season): 季度



                release_date (str): 上映时间,调用 Index_Filter.make_time_filter() 传入年份 (datetime.datetime) 获取



                style (Index_Filter.Style.Movie): 风格

            """
            self.season_type = IndexFilter.Type.MOVIE
            self.area = area
            self.release_date = release_date
            self.style_id = style
            self.season_status = payment

    class Documentary:
        def __init__(

            self,

            release_date: str = -1,

            style: IndexFilter.Style.Documentary = IndexFilter.Style.Documentary.ALL,

            payment: IndexFilter.Payment = IndexFilter.Payment.ALL,

            producer: IndexFilter.Producer = IndexFilter.Producer.ALL,

        ) -> None:
            """

            Documentary Meta

            Args:

                area (Index_Filter.Area): 地区



                release_date (str): 上映时间,调用 Index_Filter.make_time_filter() 传入年份 (datetime.datetime) 获取



                style (Index_Filter.Style.Documentary): 风格



                producer (Index_Filter.Producer): 制作方

            """
            self.season_type = IndexFilter.Type.DOCUMENTARY
            self.release_date = release_date
            self.style_id = style
            self.season_status = payment
            self.producer_id = producer

    class TV:
        def __init__(

            self,

            area: IndexFilter.Area = IndexFilter.Area.ALL,

            release_date: str = -1,

            style: IndexFilter.Style.TV = IndexFilter.Style.TV.ALL,

            payment: IndexFilter.Payment = IndexFilter.Payment.ALL,

        ) -> None:
            """

            TV Meta

            Args:

                area (Index_Filter.Area): 地区



                payment (Index_Filter.Payment): 付费门槛



                release_date (str): 上映时间,调用 Index_Filter.make_time_filter() 传入年份 (datetime.datetime) 获取



                style (Index_Filter.Style.TV): 风格

            """
            self.season_type = IndexFilter.Type.TV
            self.area = area
            self.release_date = release_date
            self.style_id = style
            self.season_status = payment

    class GuoChuang:
        def __init__(

            self,

            version: IndexFilter.Version = IndexFilter.Version.ALL,

            finish_status: IndexFilter.Finish_Status = IndexFilter.Finish_Status.ALL,

            copyright: IndexFilter.Copyright = IndexFilter.Copyright.ALL,

            payment: IndexFilter.Payment = IndexFilter.Payment.ALL,

            year: str = -1,

            style: IndexFilter.Style.GuoChuang = IndexFilter.Style.GuoChuang.ALL,

        ) -> None:
            """

            Guochuang Meta

            Args:

                version (Index_Filter.VERSION): 类型,如正片、电影等



                finish_status (Index_Filter.Finish_Status): 是否完结



                copyright (Index_Filter.Copyright): 版权



                payment (Index_Filter.Payment): 付费门槛



                year (str): 年份,调用 Index_Filter.make_time_filter() 传入年份 (int, str) 获取



                style (Index_Filter.Style.GuoChuang): 风格

            """
            self.season_type = IndexFilter.Type.GUOCHUANG
            self.season_version = version
            self.is_finish = finish_status
            self.copyright = copyright
            self.season_status = payment
            self.year = year
            self.style_id = style

    class Variety:
        def __init__(

            self,

            style: IndexFilter.Style.Variety = IndexFilter.Style.Variety.ALL,

            payment: IndexFilter.Payment = IndexFilter.Payment.ALL,

        ) -> None:
            """

            Variety Meta

            Args:

                payment (Index_Filter.Payment): 付费门槛



                style (Index_Filter.Style.Variety): 风格

            """
            self.season_type = IndexFilter.Type.VARIETY
            self.season_status = payment
            self.style_id = style


async def get_index_info(

    filters: IndexFilterMeta = IndexFilterMeta.Anime(),

    order: IndexFilter.Order = IndexFilter.Order.SCORE,

    sort: IndexFilter.Sort = IndexFilter.Sort.DESC,

    pn: int = 1,

    ps: int = 20,

) -> dict:
    """

    查询番剧索引,索引的详细参数信息见 `IndexFilterMeta`



    请先通过 `IndexFilterMeta` 构造 filters



    Args:

        filters (Index_Filter_Meta, optional): 筛选条件元数据. Defaults to Anime.



        order (BANGUMI_INDEX.ORDER, optional): 排序字段. Defaults to SCORE.



        sort (BANGUMI_INDEX.SORT, optional): 排序方式. Defaults to DESC.



        pn (int, optional): 页数. Defaults to 1.



        ps (int, optional): 每页数量. Defaults to 20.



    Returns:

        dict: 调用 API 返回的结果

    """
    api = API["info"]["index"]
    params = {}

    for key, value in filters.__dict__.items():
        if value is not None:
            if isinstance(value, Enum):
                params[key] = value.value
            else:
                params[key] = value

    if order in params:
        if (
            order == IndexFilter.Order.SCORE.value
            and sort == IndexFilter.Sort.ASC.value
        ):
            raise ValueError(
                "order 为 Index_Filter.ORDER.SCORE 时,sort 不能为 Index_Filter.SORT.ASC"
            )

    # 必要参数 season_type、type
    # 常规参数
    params["order"] = order.value
    params["sort"] = sort.value
    params["page"] = pn
    params["pagesize"] = ps

    # params["st"] 未知参数,暂时不传
    # params["type"] 未知参数,为 1
    params["type"] = 1

    return await Api(**api).update_params(**params).result


class Bangumi:
    """

    番剧类



    Attributes:

        credential (Credential): 凭据类

    """

    def __init__(

        self,

        media_id: int = -1,

        ssid: int = -1,

        epid: int = -1,

        oversea: bool = False,

        credential: Union[Credential, None] = None,

    ) -> None:
        """

        Args:

            media_id   (int, optional)              : 番剧本身的 ID. Defaults to -1.



            ssid       (int, optional)              : 每季度的 ID. Defaults to -1.



            epid       (int, optional)              : 每集的 ID. Defaults to -1.



            oversea    (bool, optional)             : 是否要采用兼容的港澳台Api,用于仅限港澳台地区番剧的信息请求. Defaults to False.



            credential (Credential | None, optional): 凭据类. Defaults to None.

        """
        if media_id == -1 and ssid == -1 and epid == -1:
            raise ValueError("需要 Media_id 或 Season_id 或 epid 中的一个 !")
        self.credential = credential if credential else Credential()
        # 处理极端情况
        params = {}
        self.__ssid = ssid
        if self.__ssid == -1 and epid == -1:
            api = API["info"]["meta"]
            params = {"media_id": media_id}
            meta = Api(**api, credential=credential).update_params(**params).result_sync
            self.__ssid = meta["media"]["season_id"]
            params["media_id"] = media_id
        # 处理正常情况
        if self.__ssid != -1:
            params["season_id"] = self.__ssid
        if epid != -1:
            params["ep_id"] = epid
        self.oversea = oversea
        if oversea:
            api = API["info"]["collective_info_oversea"]
        else:
            api = API["info"]["collective_info"]
        resp = Api(**api, credential=credential).update_params(**params).result_sync
        self.__raw = resp
        self.__epid = epid
        # 确认有结果后,取出数据
        self.__ssid = resp["season_id"]
        self.__media_id = resp["media_id"]
        if "up_info" in resp:
            self.__up_info = resp["up_info"]
        else:
            self.__up_info = {}
        # 获取剧集相关
        self.ep_list = resp.get("episodes")
        self.ep_item = [{}]
        # 出海 Api 和国内的字段有些不同
        if self.ep_list:
            if self.oversea:
                self.ep_item = [
                    item for item in self.ep_list if item["ep_id"] == self.__epid
                ]
            else:
                self.ep_item = [
                    item for item in self.ep_list if item["id"] == self.__epid
                ]

    def get_media_id(self) -> int:
        return self.__media_id

    def get_season_id(self) -> int:
        return self.__ssid

    def get_up_info(self) -> dict:
        """

        番剧上传者信息 出差或者原版



        Returns:

            Api 相关字段

        """
        return self.__up_info

    def get_raw(self) -> Tuple[dict, bool]:
        """

        原始初始化数据



        Returns:

            Api 相关字段

        """
        return self.__raw, self.oversea

    def set_media_id(self, media_id: int) -> None:
        self.__init__(media_id=media_id, credential=self.credential)

    def set_ssid(self, ssid: int) -> None:
        self.__init__(ssid=ssid, credential=self.credential)

    async def get_meta(self) -> dict:
        """

        获取番剧元数据信息(评分,封面 URL,标题等)



        Returns:

            dict: 调用 API 返回的结果

        """
        credential = self.credential if self.credential is not None else Credential()

        api = API["info"]["meta"]
        params = {"media_id": self.__media_id}
        return await Api(**api, credential=credential).update_params(**params).result

    async def get_short_comment_list(

        self,

        order: BangumiCommentOrder = BangumiCommentOrder.DEFAULT,

        next: Union[str, None] = None,

    ) -> dict:
        """

        获取短评列表



        Args:

            order      (BangumiCommentOrder, optional): 排序方式。Defaults to BangumiCommentOrder.DEFAULT



            next       (str | None, optional)         : 调用返回结果中的 next 键值,用于获取下一页数据。Defaults to None



        Returns:

            dict: 调用 API 返回的结果

        """
        credential = self.credential if self.credential is not None else Credential()

        api = API["info"]["short_comment"]
        params = {"media_id": self.__media_id, "ps": 20, "sort": order.value}
        if next is not None:
            params["cursor"] = next

        return await Api(**api, credential=credential).update_params(**params).result

    async def get_long_comment_list(

        self,

        order: BangumiCommentOrder = BangumiCommentOrder.DEFAULT,

        next: Union[str, None] = None,

    ) -> dict:
        """

        获取长评列表



        Args:

            order      (BangumiCommentOrder, optional): 排序方式。Defaults to BangumiCommentOrder.DEFAULT



            next       (str | None, optional)         : 调用返回结果中的 next 键值,用于获取下一页数据。Defaults to None



        Returns:

            dict: 调用 API 返回的结果

        """
        credential = self.credential if self.credential is not None else Credential()

        api = API["info"]["long_comment"]
        params = {"media_id": self.__media_id, "ps": 20, "sort": order.value}
        if next is not None:
            params["cursor"] = next

        return await Api(**api, credential=credential).update_params(**params).result

    async def get_episode_list(self) -> dict:
        """

        获取季度分集列表,自动转换出海Api的字段,适配部分,但是键还是有不同



        Returns:

            dict: 调用 API 返回的结果

        """
        if self.oversea:
            # 转换 ep_id->id ,index_title->longtitle ,index->title
            fix_ep_list = []
            for item in self.ep_list:
                item["id"] = item.get("ep_id")
                item["longtitle"] = item.get("index_title")
                item["title"] = item.get("index")
                fix_ep_list.append(item)
            return {"main_section": {"episodes": fix_ep_list}}
        else:
            credential = (
                self.credential if self.credential is not None else Credential()
            )
            api = API["info"]["episodes_list"]
            params = {"season_id": self.__ssid}
            return (
                await Api(**api, credential=credential).update_params(**params).result
            )

    async def get_episodes(self) -> List["Episode"]:
        """

        获取番剧所有的剧集,自动生成类。

        """
        global episode_data_cache
        episode_list = await self.get_episode_list()
        if len(episode_list["main_section"]["episodes"]) == 0:
            return []
        first_epid = episode_list["main_section"]["episodes"][0]["id"]
        credential = self.credential if self.credential else Credential()
        content_type = None
        while content_type != InitialDataType.NEXT_DATA:
            bangumi_meta, content_type = await get_initial_state(
                url=f"https://www.bilibili.com/bangumi/play/ep{first_epid}",
                credential=credential,
            )
        bangumi_meta["media_id"] = self.get_media_id()

        episodes = []
        for ep in episode_list["main_section"]["episodes"]:
            episode_data_cache[ep["id"]] = {
                "bangumi_meta": bangumi_meta,
                "bangumi_class": self,
            }
            episodes.append(Episode(epid=ep["id"], credential=self.credential))
        return episodes

    async def get_stat(self) -> dict:
        """

        获取番剧播放量,追番等信息



        Returns:

            dict: 调用 API 返回的结果

        """
        credential = self.credential if self.credential is not None else Credential()

        api = API["info"]["season_status"]
        params = {"season_id": self.__ssid}
        return await Api(**api, credential=credential).update_params(**params).result

    async def get_overview(self) -> dict:
        """

        获取番剧全面概括信息,包括发布时间、剧集情况、stat 等情况



        Returns:

            dict: 调用 API 返回的结果

        """
        credential = self.credential if self.credential is not None else Credential()
        if self.oversea:
            api = API["info"]["collective_info_oversea"]
        else:
            api = API["info"]["collective_info"]
        params = {"season_id": self.__ssid}
        return await Api(**api, credential=credential).update_params(**params).result


async def set_follow(

    bangumi: Bangumi, status: bool = True, credential: Union[Credential, None] = None

) -> dict:
    """

    追番状态设置



    Args:

        bangumi    (Bangumi)                    : 番剧类



        status     (bool, optional)             : 追番状态. Defaults to True.



        credential (Credential | None, optional): 凭据. Defaults to None.



    Returns:

        dict: 调用 API 返回的结果

    """
    credential = credential if credential is not None else Credential()
    credential.raise_for_no_sessdata()

    api = API["operate"]["follow_add"] if status else API["operate"]["follow_del"]
    data = {"season_id": bangumi.get_season_id()}
    return await Api(**api, credential=credential).update_data(**data).result


async def update_follow_status(

    bangumi: Bangumi, status: int, credential: Union[Credential, None] = None

) -> dict:
    """

    更新追番状态



    Args:

        bangumi    (Bangumi)                    : 番剧类



        credential (Credential | None, optional): 凭据. Defaults to None.



        status     (int)                        : 追番状态 1 想看 2 在看 3 已看

    Returns:

        dict: 调用 API 返回的结果

    """
    credential = credential if credential is not None else Credential()
    credential.raise_for_no_sessdata()

    api = API["operate"]["follow_status"]
    data = {"season_id": bangumi.get_season_id(), "status": status}
    return await Api(**api, credential=credential).update_data(**data).result


class Episode(Video):
    """

    番剧剧集类



    Attributes:

        credential  (Credential): 凭据类



        video_class (Video)     : 视频类



        bangumi     (Bangumi)   : 所属番剧

    """

    def __init__(self, epid: int, credential: Union[Credential, None] = None):
        """

        Args:

            epid       (int)                 : 番剧 epid



            credential (Credential, optional): 凭据. Defaults to None.

        """
        global episode_data_cache
        self.credential: Credential = credential if credential else Credential()
        self.__epid: int = epid

        if not epid in episode_data_cache.keys():
            res, content_type = get_initial_state_sync(
                url=f"https://www.bilibili.com/bangumi/play/ep{self.__epid}",
                credential=self.credential,
            )  # 随机 __NEXT_DATA__ 见 https://github.com/Nemo2011/bilibili-api/issues/433
            if content_type == InitialDataType.NEXT_DATA:
                content = res["props"]["pageProps"]["dehydratedState"]["queries"][0][
                    "state"
                ]["data"]["seasonInfo"]["mediaInfo"]
                self.bangumi = (
                    Bangumi(ssid=content["season_id"])
                    if not epid in episode_data_cache.keys()
                    else episode_data_cache[epid]["bangumi_class"]
                )
                for ep_info in content["episodes"]:
                    if int(
                        ep_info["id"] if "id" in ep_info else ep_info["ep_id"]
                    ) == int(epid):
                        bvid = ep_info["bvid"]
                        self.__ep_info: dict = ep_info
                        break
            else:  # InitialDataType.INITIAL_STATE
                self.__ep_info: dict = res["epInfo"]
                self.bangumi = (
                    Bangumi(ssid=res["mediaInfo"]["season_id"])
                    if not epid in episode_data_cache.keys()
                    else episode_data_cache[epid]["bangumi_class"]
                )
                bvid = res["epInfo"]["bvid"]
        else:
            content = episode_data_cache[epid]["bangumi_meta"]
            bvid = None
            for einfo in content["props"]["pageProps"]["dehydratedState"]["queries"][0][
                "state"
            ]["data"]["seasonInfo"]["mediaInfo"]["episodes"]:
                if einfo["ep_id"] == epid:
                    bvid = einfo["bvid"]
            self.bangumi = episode_data_cache[epid]["bangumi_class"]
            self.__ep_info: dict = episode_data_cache[epid]

        self.video_class = Video(bvid=bvid, credential=self.credential)
        super().__init__(bvid=bvid, credential=self.credential)
        self.set_aid = self.set_aid_e
        self.set_bvid = self.set_bvid_e

    def get_epid(self) -> int:
        """

        获取 epid

        """
        return self.__epid

    def set_aid_e(self, aid: int) -> None:
        print("Set aid is not allowed in Episode")

    def set_bvid_e(self, bvid: str) -> None:
        print("Set bvid is not allowed in Episode")

    async def get_cid(self) -> int:
        """

        获取稿件 cid



        Returns:

            int: cid

        """
        return (await self.get_episode_info())["epInfo"]["cid"]

    def get_bangumi(self) -> "Bangumi":
        """

        获取对应的番剧



        Returns:

            Bangumi: 番剧类

        """
        return self.bangumi  # type: ignore

    def set_epid(self, epid: int) -> None:
        self.__init__(epid, self.credential)

    async def get_episode_info(self) -> dict:
        """

        获取番剧单集信息



        Returns:

            HTML 中的数据

        """
        if self.__ep_info is None:
            res, content_type = get_initial_state(
                url=f"https://www.bilibili.com/bangumi/play/ep{self.__epid}",
                credential=self.credential,
            )
            if content_type == InitialDataType.NEXT_DATA:
                content = res["props"]["pageProps"]["dehydratedState"]["queries"][0][
                    "state"
                ]["data"]["mediaInfo"]
                for ep_info in content["episodes"]:
                    if int(
                        ep_info["id"] if "id" in ep_info else ep_info["ep_id"]
                    ) == int(self.get_epid()):
                        return ep_info
            else:
                return res["epInfo"]
        else:
            return self.__ep_info

    async def get_bangumi_from_episode(self) -> "Bangumi":
        """

        获取剧集对应的番剧



        Returns:

            Bangumi: 输入的集对应的番剧类

        """
        info = await self.get_episode_info()
        ssid = info["mediaInfo"]["season_id"]
        return Bangumi(ssid=ssid)

    async def get_download_url(self) -> dict:
        """

        获取番剧剧集下载信息。



        Returns:

            dict: 调用 API 返回的结果。

        """
        api = API["info"]["playurl"]
        if True:
            params = {
                "avid": self.get_aid(),
                "ep_id": self.get_epid(),
                "qn": "127",
                "otype": "json",
                "fnval": 4048,
                "fourk": 1,
            }
        return (
            await Api(**api, credential=self.credential).update_params(**params).result
        )

    async def get_danmaku_xml(self) -> str:
        """

        获取所有弹幕的 xml 源文件(非装填)



        Returns:

            str: 文件源

        """
        cid = await self.get_cid()
        url = f"https://comment.bilibili.com/{cid}.xml"
        sess = get_session()
        config: dict[str, Any] = {"url": url}
        # 代理
        if settings.proxy:
            config["proxies"] = {"all://", settings.proxy}
        resp = await sess.get(**config)
        return resp.content.decode("utf-8")

    async def get_danmaku_view(self) -> dict:
        """

        获取弹幕设置、特殊弹幕、弹幕数量、弹幕分段等信息。



        Returns:

            dict: 二进制流解析结果

        """
        return await self.video_class.get_danmaku_view(0)

    async def get_danmakus(

        self, date: Union[datetime.date, None] = None

    ) -> List["Danmaku"]:
        """

        获取弹幕



        Args:

            date (datetime.date | None, optional): 指定某一天查询弹幕. Defaults to None. (不指定某一天)



        Returns:

            dict[Danmaku]: 弹幕列表

        """
        return await self.video_class.get_danmakus(0, date)

    async def get_history_danmaku_index(

        self, date: Union[datetime.date, None] = None

    ) -> Union[None, List[str]]:
        """

        获取特定月份存在历史弹幕的日期。



        Args:

            date (datetime.date | None, optional): 精确到年月. Defaults to None。



        Returns:

            None | List[str]: 调用 API 返回的结果。不存在时为 None。

        """
        return await self.video_class.get_history_danmaku_index(0, date)