-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_setting.py
111 lines (75 loc) · 2.5 KB
/
global_setting.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
"""
全局变量
"""
import os
from enum import Enum
from bilibili_api import Credential
import initial
import iosetting as ios
from funcs import file_func, login_func, launch_func
# 版本控制
version = 'v1.2-alpha'
proj_name = 'Danmaku Reader'
"""背景变量"""
settings: file_func.SettingsParser | None = None # 设置
INITIAL: file_func.InitialParser | None = None # INITIAL文件解释器
user_info: login_func.UserInfoParser | None = None # 登陆用户信息解释器
offline = False # 是否离线登录标记,后续优化如settings
credential: str | None | Credential = None # 登陆证书
ban_word: file_func.BanWordParser | None = None # 屏蔽词文件解释器
""" 讲述人初始化 """
narrator: launch_func.Narrator | None = None
volume_ctrl : launch_func.VolumeCtrl|None = None
""" 操作变量 """
read_pause = False
""" 进程锁定 """
thread_locked = False
""" print 重定向; 初始化位于/logging/file_func.py """
_origin_print = None
redirect_print = None
class FileState(Enum):
right = 0
notFound = 1
dictKeyLost = 2
def load_setting():
global settings, INITIAL, user_info, credential, ban_word
try:
settings = file_func.SettingsParser()
except FileNotFoundError:
settings = FileState.notFound
except TypeError:
settings = FileState.dictKeyLost
try:
INITIAL = file_func.InitialParser()
except FileNotFoundError:
INITIAL = FileState.notFound
except TypeError:
INITIAL = FileState.dictKeyLost
try:
ban_word = file_func.BanWordParser()
except FileNotFoundError:
ban_word = FileState.notFound
except TypeError:
ban_word = FileState.dictKeyLost
if isinstance(settings, FileState):
initial.settings_initial()
settings = file_func.SettingsParser()
if isinstance(INITIAL, FileState):
initial.INITIAL_initial()
INITIAL = file_func.InitialParser()
if isinstance(ban_word, FileState):
initial.ban_word_initial()
ban_word = file_func.BanWordParser()
credential = INITIAL.get_credential()
if credential is not None:
user_info = login_func.UserInfoParser(credential)
def other_init():
global narrator, volume_ctrl
pid = os.getpid()
narrator = launch_func.Narrator()
for i in range(3):
narrator.txt2audio('正在执行初始化,请稍后')
volume_ctrl = launch_func.VolumeCtrl(pid)
if volume_ctrl.check is True:
return True
return False