-
Notifications
You must be signed in to change notification settings - Fork 6
/
__init__.py
1088 lines (1016 loc) · 44.3 KB
/
__init__.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
import inspect
import os
from typing import Any, List, Dict, Tuple
from app.core.event import eventmanager, Event
from app.core.plugin import PluginManager
from app.db.site_oper import SiteOper
from app.db.systemconfig_oper import SystemConfigOper
from app.log import logger
from app.plugins import _PluginBase
from app.scheduler import Scheduler
from app.schemas.types import SystemConfigKey, EventType
class MergeSiteSwitch(_PluginBase):
# 插件名称
plugin_name = "聚合站点开关"
# 插件描述
plugin_desc = "统一管理所有与站点相关的开关。"
# 插件图标
plugin_icon = "world.png"
# 插件版本
plugin_version = "1.2"
# 插件作者
plugin_author = "hotlcc"
# 作者主页
author_url = "https://github.com/hotlcc"
# 插件配置项ID前缀
plugin_config_prefix = "com.hotlcc.mergesiteswitch."
# 加载顺序
plugin_order = 66
# 可使用的用户级别
auth_level = 2
# 依赖组件
# 站点操作
__site_oper: SiteOper = SiteOper()
# 系统配置操作
__system_config_oper: SystemConfigOper = SystemConfigOper()
# 其它插件ID
# 自定义站点
__plugin_id_custom_sites: str = 'CustomSites'
# 站点自动签到
__plugin_id_auto_signin: str = 'AutoSignIn'
# 站点数据统计
__plugin_id_site_statistic: str = 'SiteStatistic'
# IYUU自动辅种
__plugin_id_iyuu_auto_seed: str = 'IYUUAutoSeed'
# 站点刷流
__plugin_id_brush_flow: str = 'BrushFlow'
# 青蛙辅种助手
__plugin_id_cross_seed: str = 'CrossSeed'
# 配置相关
# 插件缺省配置
__config_default: Dict[str, Any] = {}
# 插件用户配置
__config: Dict[str, Any] = {}
def init_plugin(self, config: dict = None):
"""
初始化插件
"""
# 加载配置
self.__config = config
# 当页面通过调用接口保存配置时保存其它各项配置
if self.__check_stack_is_save_config_request():
self.__set_config(config=config)
def get_state(self) -> bool:
"""
获取插件状态
"""
return self.__check_any_follow_enable_sites()
@staticmethod
def get_command() -> List[Dict[str, Any]]:
"""
定义远程控制命令
:return: 命令关键字、事件、描述、附带数据
"""
pass
def get_api(self) -> List[Dict[str, Any]]:
"""
获取插件API
"""
pass
def get_service(self) -> List[Dict[str, Any]]:
"""
注册插件公共服务
"""
pass
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
"""
拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构
"""
# 站点选项
site_options = self.__get_site_options()
# 自定义站点选项
custom_site_options = self.__get_custom_site_options(suffix=" [自定义]")
# 全部站点选项
all_site_options = site_options + custom_site_options
# 已安装的插件IDs
installed_plugin_ids = self.__get_installed_plugin_ids()
# 建议的配置
config_suggest = {}
# 表单内容
form_content = [{
'component': 'VRow',
'content': [{
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 12, 'xl': 12, 'lg': 12, 'md': 12, 'sm': 12, 'xs': 12
},
'content': [{
'component': 'VSelect',
'props': {
'model': 'enable_sites',
'label': '启用的站点',
'multiple': True,
'chips': True,
'items': site_options,
'hint': '对应功能【站点管理 / 添加编辑站点 / 启用】,仅支持系统站点。'
}
}]
}]
}, {
'component': 'VRow',
'content': [{
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 9, 'xl': 9, 'lg': 9, 'md': 9, 'sm': 8, 'xs': 12
},
'content': [{
'component': 'VSelect',
'props': {
'model': 'search_sites',
'label': '设定 / 搜索 / 搜索站点',
'multiple': True,
'chips': True,
'items': site_options,
'hint': '只有选中的站点才会在搜索中使用,仅支持系统站点。'
}
}]
}, {
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 3, 'xl': 3, 'lg': 3, 'md': 3, 'sm': 4, 'xs': 12
},
'content': [{
'component': 'VSwitch',
'props': {
'model': 'search_follow_enable_sites',
'label': '跟随启用的站点',
'hint': '与站点的启用状态保持一致,保存时会立即生效,并在后台监听站点状态变化实时生效。'
}
}]
}]
}, {
'component': 'VRow',
'content': [{
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 9, 'xl': 9, 'lg': 9, 'md': 9, 'sm': 8, 'xs': 12
},
'content': [{
'component': 'VSelect',
'props': {
'model': 'rss_sites',
'label': '设定 / 订阅 / 订阅站点',
'multiple': True,
'chips': True,
'items': site_options,
'hint': '只有选中的站点才会在订阅中使用,仅支持系统站点。'
}
}]
}, {
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 3, 'xl': 3, 'lg': 3, 'md': 3, 'sm': 4, 'xs': 12
},
'content': [{
'component': 'VSwitch',
'props': {
'model': 'rss_follow_enable_sites',
'label': '跟随启用的站点',
'hint': '与站点的启用状态保持一致,保存时会立即生效,并在后台监听站点状态变化实时生效。'
}
}]
}]
}]
# 站点自动签到
if self.__plugin_id_auto_signin in installed_plugin_ids:
form_content.append({
'component': 'VRow',
'content': [{
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 9, 'xl': 9, 'lg': 9, 'md': 9, 'sm': 8, 'xs': 12
},
'content': [{
'component': 'VSelect',
'props': {
'model': 'signin_sites',
'label': '插件 / 站点自动签到 / 签到站点',
'multiple': True,
'chips': True,
'items': all_site_options,
'hint': '只有选中的站点才会在签到中使用,支持系统站点和自定义站点。'
}
}]
}, {
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 3, 'xl': 3, 'lg': 3, 'md': 3, 'sm': 4, 'xs': 12
},
'content': [{
'component': 'VSwitch',
'props': {
'model': 'signin_follow_enable_sites',
'label': '跟随启用的站点',
'hint': '与站点的启用状态保持一致,保存时会立即生效,并在后台监听站点状态变化实时生效。'
}
}]
}, {
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 9, 'xl': 9, 'lg': 9, 'md': 9, 'sm': 8, 'xs': 12
},
'content': [{
'component': 'VSelect',
'props': {
'model': 'login_sites',
'label': '插件 / 站点自动签到 / 登录站点',
'multiple': True,
'chips': True,
'items': all_site_options,
'hint': '只有选中的站点才会在登录中使用,支持系统站点和自定义站点。'
}
}]
}, {
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 3, 'xl': 3, 'lg': 3, 'md': 3, 'sm': 4, 'xs': 12
},
'content': [{
'component': 'VSwitch',
'props': {
'model': 'login_follow_enable_sites',
'label': '跟随启用的站点',
'hint': '与站点的启用状态保持一致,保存时会立即生效,并在后台监听站点状态变化实时生效。'
}
}]
}]
})
# 站点数据统计
if self.__plugin_id_site_statistic in installed_plugin_ids:
form_content.append({
'component': 'VRow',
'content': [{
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 9, 'xl': 9, 'lg': 9, 'md': 9, 'sm': 8, 'xs': 12
},
'content': [{
'component': 'VSelect',
'props': {
'model': 'statistic_sites',
'label': '插件 / 站点数据统计 / 统计站点',
'multiple': True,
'chips': True,
'items': all_site_options,
'hint': '缺省时默认全部站点,支持系统站点和自定义站点。'
}
}]
}, {
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 3, 'xl': 3, 'lg': 3, 'md': 3, 'sm': 4, 'xs': 12
},
'content': [{
'component': 'VSwitch',
'props': {
'model': 'statistic_follow_enable_sites',
'label': '跟随启用的站点',
'hint': '与站点的启用状态保持一致,保存时会立即生效,并在后台监听站点状态变化实时生效。'
}
}]
}]
})
# IYUU自动辅种
if self.__plugin_id_iyuu_auto_seed in installed_plugin_ids:
form_content.append({
'component': 'VRow',
'content': [{
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 9, 'xl': 9, 'lg': 9, 'md': 9, 'sm': 8, 'xs': 12
},
'content': [{
'component': 'VSelect',
'props': {
'model': 'iyuu_seed_sites',
'label': '插件 / IYUU自动辅种 / 辅种站点',
'multiple': True,
'chips': True,
'items': all_site_options,
'hint': '缺省时默认全部站点,支持系统站点和自定义站点。'
}
}]
}, {
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 3, 'xl': 3, 'lg': 3, 'md': 3, 'sm': 4, 'xs': 12
},
'content': [{
'component': 'VSwitch',
'props': {
'model': 'iyuu_seed_follow_enable_sites',
'label': '跟随启用的站点',
'hint': '与站点的启用状态保持一致,保存时会立即生效,并在后台监听站点状态变化实时生效。'
}
}]
}]
})
# 站点刷流
if self.__plugin_id_brush_flow in installed_plugin_ids:
form_content.append({
'component': 'VRow',
'content': [{
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 9, 'xl': 9, 'lg': 9, 'md': 9, 'sm': 8, 'xs': 12
},
'content': [{
'component': 'VSelect',
'props': {
'model': 'brush_flow_sites',
'label': '插件 / 站点刷流 / 刷流站点',
'multiple': True,
'chips': True,
'items': site_options,
'hint': '只有选中的站点才会在刷流中使用,仅支持系统站点。'
}
}]
}, {
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 3, 'xl': 3, 'lg': 3, 'md': 3, 'sm': 4, 'xs': 12
},
'content': [{
'component': 'VSwitch',
'props': {
'model': 'brush_flow_follow_enable_sites',
'label': '跟随启用的站点',
'hint': '与站点的启用状态保持一致,保存时会立即生效,并在后台监听站点状态变化实时生效。'
}
}]
}]
})
# 青蛙辅种助手
if self.__plugin_id_cross_seed in installed_plugin_ids:
form_content.append({
'component': 'VRow',
'content': [{
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 9, 'xl': 9, 'lg': 9, 'md': 9, 'sm': 8, 'xs': 12
},
'content': [{
'component': 'VSelect',
'props': {
'model': 'cross_seed_sites',
'label': '插件 / 青蛙辅种助手 / 辅种站点',
'multiple': True,
'chips': True,
'items': all_site_options,
'hint': '只有选中的站点才会在辅种中使用,支持系统站点和自定义站点。'
}
}]
}, {
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 3, 'xl': 3, 'lg': 3, 'md': 3, 'sm': 4, 'xs': 12
},
'content': [{
'component': 'VSwitch',
'props': {
'model': 'cross_seed_follow_enable_sites',
'label': '跟随启用的站点',
'hint': '与站点的启用状态保持一致,保存时会立即生效,并在后台监听站点状态变化实时生效。'
}
}]
}]
})
# 提示信息
form_content.append({
'component': 'VRow',
'content': [{
'component': 'VCol',
'props': {
'cols': 12,
'xxl': 12, 'xl': 12, 'lg': 12, 'md': 12, 'sm': 12, 'xs': 12
},
'content': [{
'component': 'VAlert',
'props': {
'type': 'warning',
'variant': 'tonal'
},
'text': '点击保存后会立即生效,各项站点开关配置即会更新!'
}]
}]
})
# 表单
form = [{
'component': 'VForm',
'content': form_content
}]
# 重载配置
self.__get_config()
return form, config_suggest
def get_page(self) -> List[dict]:
pass
def stop_service(self):
"""
退出插件
"""
pass
@classmethod
def __check_stack_exist_function(cls, package_name: str, function_name: str) -> bool:
"""
判断当前调用栈是否存在指定的函数
"""
if not package_name or not function_name:
return False
for stack in inspect.stack():
if stack.function != 'set_plugin_config':
continue
package_path = package_name.replace('.', os.sep)
if stack.filename.endswith(f"{package_path}.py") or stack.filename.endswith(f"{package_path}{os.sep}__init__.py"):
return True
return False
@classmethod
def __check_stack_is_save_config_request(cls) -> bool:
"""
判断当前调用栈是否来源于“插件配置保存”接口
"""
return cls.__check_stack_exist_function('app.api.endpoints.plugin', 'set_plugin_config')
def __get_config_value(self, config_key: str, use_default: bool = True) -> Any:
"""
获取插件配置值
:param config_key: 配置键
:param use_default: 是否使用缺省值
:return: 配置值
"""
if not config_key:
return None
config = self.__config if self.__config else {}
config_value = config.get(config_key)
if config_value is None and use_default:
config_default = self.__config_default if self.__config_default else {}
config_value = config_default.get(config_key)
return config_value
def __check_follow_enable_sites(self, config_key: str, plugin_id: str = None, installed_plugin_ids: List[str] = None) -> bool:
"""
判断某个跟随按钮是否打开
:param plugin_id: 传插件ID时还要同时根据插件是否安装进行判断
"""
if not self.__get_config_value(config_key=config_key):
return False
if not plugin_id:
return True
if not installed_plugin_ids:
installed_plugin_ids = self.__get_installed_plugin_ids()
return plugin_id in installed_plugin_ids
def __check_search_follow_enable_sites(self) -> bool:
"""
判断搜索站点的跟随按钮是否打开
"""
return self.__check_follow_enable_sites(config_key='search_follow_enable_sites')
def __check_rss_follow_enable_sites(self) -> bool:
"""
判断订阅站点的跟随按钮是否打开
"""
return self.__check_follow_enable_sites(config_key='rss_follow_enable_sites')
def __check_signin_follow_enable_sites(self, installed_plugin_ids: List[str] = None) -> bool:
"""
判断签到站点的跟随按钮是否打开
"""
return self.__check_follow_enable_sites(config_key='signin_follow_enable_sites', plugin_id=self.__plugin_id_auto_signin, installed_plugin_ids=installed_plugin_ids)
def __check_login_follow_enable_sites(self, installed_plugin_ids: List[str] = None) -> bool:
"""
判断登录站点的跟随按钮是否打开
"""
return self.__check_follow_enable_sites(config_key='login_follow_enable_sites', plugin_id=self.__plugin_id_auto_signin, installed_plugin_ids=installed_plugin_ids)
def __check_statistic_follow_enable_sites(self, installed_plugin_ids: List[str] = None) -> bool:
"""
判断统计站点的跟随按钮是否打开
"""
return self.__check_follow_enable_sites(config_key='statistic_follow_enable_sites', plugin_id=self.__plugin_id_site_statistic, installed_plugin_ids=installed_plugin_ids)
def __check_iyuu_seed_follow_enable_sites(self, installed_plugin_ids: List[str] = None) -> bool:
"""
判断iyuu辅种站点的跟随按钮是否打开
"""
return self.__check_follow_enable_sites(config_key='iyuu_seed_follow_enable_sites', plugin_id=self.__plugin_id_iyuu_auto_seed, installed_plugin_ids=installed_plugin_ids)
def __check_brush_flow_follow_enable_sites(self, installed_plugin_ids: List[str] = None) -> bool:
"""
判断刷流站点的跟随按钮是否打开
"""
return self.__check_follow_enable_sites(config_key='brush_flow_follow_enable_sites', plugin_id=self.__plugin_id_brush_flow, installed_plugin_ids=installed_plugin_ids)
def __check_cross_seed_follow_enable_sites(self, installed_plugin_ids: List[str] = None) -> bool:
"""
判断青蛙辅种站点的跟随按钮是否打开
"""
return self.__check_follow_enable_sites(config_key='cross_seed_follow_enable_sites', plugin_id=self.__plugin_id_cross_seed, installed_plugin_ids=installed_plugin_ids)
def __check_any_follow_enable_sites(self) -> bool:
"""
判断是否开启任意跟随按钮
"""
# 已安装的插件IDs
installed_plugin_ids = self.__get_installed_plugin_ids()
return True if self.__check_search_follow_enable_sites() \
or self.__check_rss_follow_enable_sites() \
or self.__check_signin_follow_enable_sites(installed_plugin_ids=installed_plugin_ids) \
or self.__check_login_follow_enable_sites(installed_plugin_ids=installed_plugin_ids) \
or self.__check_statistic_follow_enable_sites(installed_plugin_ids=installed_plugin_ids) \
or self.__check_iyuu_seed_follow_enable_sites(installed_plugin_ids=installed_plugin_ids) \
or self.__check_brush_flow_follow_enable_sites(installed_plugin_ids=installed_plugin_ids) else False
def __get_site_options(self) -> List[Dict[str, Any]]:
"""
获取站点选项
"""
sites = self.__site_oper.list_order_by_pri()
if not sites:
return []
return [{
'title': site.name,
'value': site.id
} for site in sites if site]
def __get_site_ids(self) -> List[str]:
"""
获取站点IDs
"""
sites = self.__site_oper.list_order_by_pri()
if not sites:
return []
return [site.id for site in sites if site]
def __get_installed_plugin_ids(self):
"""
获取已安装的插件IDs
"""
installed_plugin_ids = self.__system_config_oper.get(SystemConfigKey.UserInstalledPlugins)
return installed_plugin_ids if installed_plugin_ids else []
def __get_config(self):
"""
获取配置,包含聚合外部配置
"""
config = self.get_config()
if not config:
config = {}
config.update({
'enable_sites': self.__get_enable_site_ids(),
'search_sites': self.__get_search_site_ids(),
'rss_sites': self.__get_rss_site_ids(),
})
# 已安装的插件IDs
installed_plugin_ids = self.__get_installed_plugin_ids()
# 站点IDs
#site_ids = self.__get_site_ids()
#custom_site_ids = self.__get_custom_site_ids()
#all_site_ids = site_ids + custom_site_ids
if self.__plugin_id_auto_signin in installed_plugin_ids:
config.update({
'signin_sites': self.__get_signin_site_ids(),
#'signin_sites': [site_id for site_id in self.__get_signin_site_ids() if site_id in all_site_ids],
'login_sites': self.__get_login_site_ids(),
#'login_sites': [site_id for site_id in self.__get_login_site_ids() if site_id in all_site_ids],
})
if self.__plugin_id_site_statistic in installed_plugin_ids:
config.update({
'statistic_sites': self.__get_statistic_site_ids(),
#'statistic_sites': [site_id for site_id in self.__get_statistic_site_ids() if site_id in all_site_ids],
})
if self.__plugin_id_iyuu_auto_seed in installed_plugin_ids:
config.update({
'iyuu_seed_sites': self.__get_iyuu_seed_site_ids(),
#'iyuu_seed_sites': [site_id for site_id in self.__get_iyuu_seed_site_ids() if site_id in all_site_ids],
})
if self.__plugin_id_brush_flow in installed_plugin_ids:
config.update({
'brush_flow_sites': self.__get_brush_flow_site_ids(),
})
if self.__plugin_id_cross_seed in installed_plugin_ids:
config.update({
'cross_seed_sites': self.__get_cross_seed_site_ids(),
#'cross_seed_sites': [site_id for site_id in self.__get_cross_seed_site_ids() if site_id in all_site_ids],
})
self.update_config(config=config)
return config
def __pre_config_follow_enable_sites(self, config: dict) -> dict:
"""
处理跟随站点
"""
if not config:
config = {}
enable_sites = config.get('enable_sites') or []
custom_site_ids = self.__get_custom_site_ids()
if config.get('search_follow_enable_sites'):
config.update({"search_sites": enable_sites.copy()})
if config.get('rss_follow_enable_sites'):
config.update({"rss_sites": enable_sites.copy()})
if config.get('signin_follow_enable_sites'):
signin_sites = config.get('signin_sites') or []
signin_sites = enable_sites.copy() + [site for site in signin_sites if site and site in custom_site_ids]
config.update({"signin_sites": signin_sites})
if config.get('login_follow_enable_sites'):
login_sites = config.get('login_sites') or []
login_sites = enable_sites.copy() + [site for site in login_sites if site and site in custom_site_ids]
config.update({"login_sites": login_sites})
if config.get('statistic_follow_enable_sites'):
statistic_sites = config.get('statistic_sites') or []
statistic_sites = enable_sites.copy() + [site for site in statistic_sites if site and site in custom_site_ids]
config.update({"statistic_sites": statistic_sites})
if config.get('iyuu_seed_follow_enable_sites'):
iyuu_seed_sites = config.get('iyuu_seed_sites') or []
iyuu_seed_sites = enable_sites.copy() + [site for site in iyuu_seed_sites if site and site in custom_site_ids]
config.update({"iyuu_seed_sites": iyuu_seed_sites})
if config.get('brush_flow_follow_enable_sites'):
config.update({"brush_flow_sites": enable_sites.copy()})
if config.get('cross_seed_follow_enable_sites'):
cross_seed_sites = config.get('cross_seed_sites') or []
cross_seed_sites = enable_sites.copy() + [site for site in cross_seed_sites if site and site in custom_site_ids]
config.update({"cross_seed_sites": cross_seed_sites})
return config
def __pre_config(self, config: dict) -> dict:
"""
预处理配置
"""
config = self.__pre_config_follow_enable_sites(config=config)
logger.debug(f"配置预处理完成: {config}")
return config
def __set_config(self, config: dict):
"""
保存配置,包含保存外部配置到各自表
"""
# 预处理配置
config = self.__pre_config(config=config)
# 更新各项配置
self.update_config(config=config)
logger.info("插件配置更新完成")
self.__set_enable_site_ids(config.get('enable_sites'))
self.__set_search_site_ids(config.get('search_sites'))
self.__set_rss_site_ids(config.get('rss_sites'))
# 已安装的插件IDs
installed_plugin_ids = self.__get_installed_plugin_ids()
if self.__plugin_id_auto_signin in installed_plugin_ids:
self.__set_signin_site_ids(config.get('signin_sites'))
self.__set_login_site_ids(config.get('login_sites'))
if self.__plugin_id_site_statistic in installed_plugin_ids:
self.__set_statistic_site_ids(config.get('statistic_sites'))
if self.__plugin_id_iyuu_auto_seed in installed_plugin_ids:
self.__set_iyuu_seed_site_ids(config.get('iyuu_seed_sites'))
if self.__plugin_id_brush_flow in installed_plugin_ids:
self.__set_brush_flow_site_ids(config.get('brush_flow_sites'))
if self.__plugin_id_cross_seed in installed_plugin_ids:
self.__set_cross_seed_site_ids(config.get('cross_seed_sites'))
return config
def __get_enable_site_ids(self) -> List[int]:
"""
获取启用的站点IDs
"""
sites = self.__site_oper.list_order_by_pri()
if not sites:
return []
return [site.id for site in sites if site and site.is_active]
def __set_enable_site_ids(self, site_ids: List[int]):
"""
设置启用的站点IDs
"""
sites = self.__site_oper.list_order_by_pri()
if not sites:
return
for site in sites:
if not site_ids or site.id not in site_ids:
if site.is_active:
self.__site_oper.update(site.id, {'is_active': False})
else:
if not site.is_active:
self.__site_oper.update(site.id, {'is_active': True})
logger.info("启用的站点配置完成")
def __get_search_site_ids(self) -> List[int]:
"""
获取搜索站点IDs
"""
sites = self.__system_config_oper.get(SystemConfigKey.IndexerSites)
return sites if sites else []
def __set_search_site_ids(self, site_ids: List[int]):
"""
设置搜索站点IDs
"""
self.__system_config_oper.set(SystemConfigKey.IndexerSites, site_ids)
logger.info("搜索站点配置完成")
def __get_rss_site_ids(self) -> List[int]:
"""
获取订阅站点IDs
"""
sites = self.__system_config_oper.get(SystemConfigKey.RssSites)
return sites if sites else []
def __set_rss_site_ids(self, site_ids: List[int]):
"""
设置订阅站点IDs
"""
self.__system_config_oper.set(SystemConfigKey.RssSites, site_ids)
logger.info("订阅站点配置完成")
def __get_plugin_config_value(self, plugin_id: str, config_key: str) -> Any:
"""
获取插件配置值
"""
if not plugin_id or not config_key:
return None
config = self.get_config(plugin_id)
if not config:
return None
return config.get(config_key)
def __reload_plugin_config(self, plugin_id: str, config: dict = None):
"""
重载插件配置
"""
if not plugin_id:
return
if not config:
config = self.get_config(plugin_id)
# 重新生效插件
PluginManager().init_plugin(plugin_id, config)
# 注册插件服务
Scheduler().update_plugin_job(plugin_id)
def __set_plugin_config_value(self, plugin_id: str, config_key: str, config_value: Any) -> Any:
"""
设置插件配置值
"""
if not plugin_id or not config_key:
return
config = self.get_config(plugin_id)
if not config:
config = {}
config.update({config_key: config_value})
self.update_config(plugin_id=plugin_id, config=config)
self.__reload_plugin_config(plugin_id=plugin_id, config=config)
def __get_signin_site_ids(self) -> List[int]:
"""
获取签到站点IDs
"""
sites = self.__get_plugin_config_value(self.__plugin_id_auto_signin, 'sign_sites')
return sites if sites else []
def __set_signin_site_ids(self, site_ids: List[int]):
"""
设置签到站点IDs
"""
self.__set_plugin_config_value(self.__plugin_id_auto_signin, 'sign_sites', site_ids)
logger.info("签到站点配置完成")
def __get_login_site_ids(self) -> List[int]:
"""
获取登录站点IDs
"""
sites = self.__get_plugin_config_value(self.__plugin_id_auto_signin, 'login_sites')
return sites if sites else []
def __set_login_site_ids(self, site_ids: List[int]):
"""
设置登录站点IDs
"""
self.__set_plugin_config_value(self.__plugin_id_auto_signin, 'login_sites', site_ids)
logger.info("登录站点配置完成")
def __get_statistic_site_ids(self) -> List[int]:
"""
获取统计站点IDs
"""
sites = self.__get_plugin_config_value(self.__plugin_id_site_statistic, 'statistic_sites')
return sites if sites else []
def __set_statistic_site_ids(self, site_ids: List[int]):
"""
设置统计站点IDs
"""
self.__set_plugin_config_value(self.__plugin_id_site_statistic, 'statistic_sites', site_ids)
logger.info("统计站点配置完成")
def __get_iyuu_seed_site_ids(self) -> List[int]:
"""
获取iyuu自动辅种站点IDs
"""
sites = self.__get_plugin_config_value(self.__plugin_id_iyuu_auto_seed, 'sites')
return sites if sites else []
def __set_iyuu_seed_site_ids(self, site_ids: List[int]):
"""
设置iyuu自动辅种站点IDs
"""
self.__set_plugin_config_value(self.__plugin_id_iyuu_auto_seed, 'sites', site_ids)
logger.info("IYUU辅种站点配置完成")
def __get_brush_flow_site_ids(self) -> List[int]:
"""
获取刷流站点IDs
"""
sites = self.__get_plugin_config_value(self.__plugin_id_brush_flow, 'brushsites')
return sites if sites else []
def __set_brush_flow_site_ids(self, site_ids: List[int]):
"""
设置刷流站点IDs
"""
self.__set_plugin_config_value(self.__plugin_id_brush_flow, 'brushsites', site_ids)
logger.info("刷流站点配置完成")
def __get_cross_seed_site_ids(self) -> List[int]:
"""
获取青蛙辅种站点IDs
"""
sites = self.__get_plugin_config_value(self.__plugin_id_cross_seed, 'sites')
return sites if sites else []
def __set_cross_seed_site_ids(self, site_ids: List[int]):
"""
设置青蛙辅种站点IDs
"""
self.__set_plugin_config_value(self.__plugin_id_cross_seed, 'sites', site_ids)
logger.info("青蛙辅种站点配置完成")
def __update_search_site_ids_by_site(self, site_id: int, site_status: bool):
if site_id == None:
return
site_ids = self.__get_search_site_ids() or []
if site_id not in site_ids and site_status:
site_ids.append(site_id)
self.__set_search_site_ids(site_ids=site_ids)
elif site_id in site_ids and not site_status:
site_ids.remove(site_id)
self.__set_search_site_ids(site_ids=site_ids)
def __update_rss_site_ids_by_site(self, site_id: int, site_status: bool):
if site_id == None:
return
site_ids = self.__get_rss_site_ids() or []
if site_id not in site_ids and site_status:
site_ids.append(site_id)
self.__set_rss_site_ids(site_ids=site_ids)
elif site_id in site_ids and not site_status:
site_ids.remove(site_id)
self.__set_rss_site_ids(site_ids=site_ids)
def __update_signin_site_ids_by_site(self, site_id: int, site_status: bool):
if site_id == None:
return
site_ids = self.__get_signin_site_ids() or []
if site_id not in site_ids and site_status:
site_ids.append(site_id)
self.__set_signin_site_ids(site_ids=site_ids)
elif site_id in site_ids and not site_status:
site_ids.remove(site_id)
self.__set_signin_site_ids(site_ids=site_ids)
def __update_login_site_ids_by_site(self, site_id: int, site_status: bool):
if site_id == None:
return
site_ids = self.__get_login_site_ids() or []
if site_id not in site_ids and site_status:
site_ids.append(site_id)
self.__set_login_site_ids(site_ids=site_ids)
elif site_id in site_ids and not site_status:
site_ids.remove(site_id)
self.__set_login_site_ids(site_ids=site_ids)
def __update_statistic_site_ids_by_site(self, site_id: int, site_status: bool):
if site_id == None:
return
site_ids = self.__get_statistic_site_ids() or []
if site_id not in site_ids and site_status:
site_ids.append(site_id)
self.__set_statistic_site_ids(site_ids=site_ids)
elif site_id in site_ids and not site_status:
site_ids.remove(site_id)
self.__set_statistic_site_ids(site_ids=site_ids)
def __update_iyuu_seed_site_ids_by_site(self, site_id: int, site_status: bool):
if site_id == None:
return
site_ids = self.__get_iyuu_seed_site_ids() or []
if site_id not in site_ids and site_status:
site_ids.append(site_id)
self.__set_iyuu_seed_site_ids(site_ids=site_ids)
elif site_id in site_ids and not site_status:
site_ids.remove(site_id)
self.__set_iyuu_seed_site_ids(site_ids=site_ids)
def __update_brush_flow_site_ids_by_site(self, site_id: int, site_status: bool):
if site_id == None:
return
site_ids = self.__get_brush_flow_site_ids() or []
if site_id not in site_ids and site_status:
site_ids.append(site_id)
self.__set_brush_flow_site_ids(site_ids=site_ids)
elif site_id in site_ids and not site_status:
site_ids.remove(site_id)
self.__set_brush_flow_site_ids(site_ids=site_ids)
def __update_cross_seed_site_ids_by_site(self, site_id: int, site_status: bool):
if site_id == None:
return
site_ids = self.__get_cross_seed_site_ids() or []
if site_id not in site_ids and site_status:
site_ids.append(site_id)
self.__set_cross_seed_site_ids(site_ids=site_ids)
elif site_id in site_ids and not site_status:
site_ids.remove(site_id)
self.__set_cross_seed_site_ids(site_ids=site_ids)
def __update_site_ids_for_site_event(self, site_id: int, site_status: bool):
"""
针对站点事件更新各项配置
"""
if site_id == None:
return
if self.__check_search_follow_enable_sites():
self.__update_search_site_ids_by_site(site_id=site_id, site_status=site_status)
if self.__check_rss_follow_enable_sites():
self.__update_rss_site_ids_by_site(site_id=site_id, site_status=site_status)
# 已安装的插件IDs
installed_plugin_ids = self.__get_installed_plugin_ids()
if self.__check_signin_follow_enable_sites(installed_plugin_ids=installed_plugin_ids):
self.__update_signin_site_ids_by_site(site_id=site_id, site_status=site_status)
if self.__check_login_follow_enable_sites(installed_plugin_ids=installed_plugin_ids):
self.__update_login_site_ids_by_site(site_id=site_id, site_status=site_status)
if self.__check_statistic_follow_enable_sites(installed_plugin_ids=installed_plugin_ids):
self.__update_statistic_site_ids_by_site(site_id=site_id, site_status=site_status)
if self.__check_iyuu_seed_follow_enable_sites(installed_plugin_ids=installed_plugin_ids):
self.__update_iyuu_seed_site_ids_by_site(site_id=site_id, site_status=site_status)
if self.__check_brush_flow_follow_enable_sites(installed_plugin_ids=installed_plugin_ids):
self.__update_brush_flow_site_ids_by_site(site_id=site_id, site_status=site_status)
if self.__check_cross_seed_follow_enable_sites(installed_plugin_ids=installed_plugin_ids):
self.__update_cross_seed_site_ids_by_site(site_id=site_id, site_status=site_status)