forked from yinian0406/Fanqie-novel-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
80 lines (68 loc) · 2.21 KB
/
Copy pathconfig.py
File metadata and controls
80 lines (68 loc) · 2.21 KB
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
"""
全局配置文件
"""
# 默认窗口几何信息
DEFAULT_WINDOW_GEOMETRY = "800x600"
# 请求配置
REQUEST_CONFIG = {
"max_workers": 5,
"max_retries": 3,
"request_timeout": 15,
"user_agents": [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
]
}
# 阅读器默认配置
READER_CONFIG = {
"default_font": "Arial",
"default_size": 12,
"default_fg": "#000000",
"default_bg": "#FFFFFF",
"default_width": 800,
"default_height": 750, # Increased default height
"padding": 10
}
# 文件配置
FILE_CONFIG = {
"status_file": "chapter.json",
"cookie_file": "cookie.json",
"default_save_path": "downloads"
}
# 加载用户配置
def load_user_config():
import os
import json
user_config_path = "user_config.json"
config = {
"request": REQUEST_CONFIG.copy(),
"reader": READER_CONFIG.copy(),
"file": FILE_CONFIG.copy()
}
if os.path.exists(user_config_path):
try:
with open(user_config_path, 'r', encoding='utf-8') as f:
user_config = json.load(f)
# 更新配置
if "request" in user_config:
config["request"].update(user_config["request"])
if "reader" in user_config:
config["reader"].update(user_config["reader"])
if "file" in user_config:
config["file"].update(user_config["file"])
except Exception as e:
print(f"加载用户配置失败: {str(e)}")
return config
# 保存用户配置
def save_user_config(config):
import json
try:
with open("user_config.json", 'w', encoding='utf-8') as f:
json.dump(config, f, ensure_ascii=False, indent=4)
return True
except Exception as e:
print(f"保存用户配置失败: {str(e)}")
return False
# 获取配置
CONFIG = load_user_config()