mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2025-12-26 12:56:22 +08:00
1. 移除 sec_ch_ua_platform 参数 2. 移除 sec_ch_ua 参数 3. 优化请求延时间隔 4. 优化并发下载功能 5. 修正英语翻译错误 6. 新增并发下载限制 7. 修正命令行模式错误 8. 简化数据请求头 Closes #86 Closes #87 Closes #93 Closes #98 Closes #105 Closes #109 Closes #110 Closes #140 Closes #152 Closes #154 Closes #157 Closes #159 Closes #160 Closes #162 Closes #164 Closes #165
72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
from json import dump
|
|
from json import load
|
|
from pathlib import Path
|
|
from platform import system
|
|
|
|
from .static import ROOT
|
|
# from .static import SEC_CH_UA
|
|
# from .static import SEC_CH_UA_PLATFORM
|
|
from .static import USERAGENT
|
|
|
|
__all__ = ['Settings']
|
|
|
|
|
|
class Settings:
|
|
default = {
|
|
"work_path": "",
|
|
"folder_name": "Download",
|
|
"name_format": "发布时间 作者昵称 作品标题",
|
|
# "sec_ch_ua": SEC_CH_UA,
|
|
# "sec_ch_ua_platform": SEC_CH_UA_PLATFORM,
|
|
"user_agent": USERAGENT,
|
|
"cookie": "",
|
|
"proxy": None,
|
|
"timeout": 10,
|
|
"chunk": 1024 * 1024 * 2,
|
|
"max_retry": 5,
|
|
"record_data": False,
|
|
"image_format": "PNG",
|
|
"image_download": True,
|
|
"video_download": True,
|
|
"live_download": False,
|
|
"folder_mode": False,
|
|
"download_record": True,
|
|
"language": "zh_CN",
|
|
# "server": False,
|
|
}
|
|
encode = "UTF-8-SIG" if system() == "Windows" else "UTF-8"
|
|
|
|
def __init__(self, root: Path = ROOT):
|
|
self.file = root.joinpath("./settings.json")
|
|
|
|
def run(self):
|
|
return self.read() if self.file.is_file() else self.create()
|
|
|
|
def read(self) -> dict:
|
|
with self.file.open("r", encoding=self.encode) as f:
|
|
return load(f)
|
|
|
|
def create(self) -> dict:
|
|
with self.file.open("w", encoding=self.encode) as f:
|
|
dump(self.default, f, indent=4, ensure_ascii=False)
|
|
return self.default
|
|
|
|
def update(self, data: dict):
|
|
with self.file.open("w", encoding=self.encode) as f:
|
|
dump(data, f, indent=4, ensure_ascii=False)
|
|
|
|
@classmethod
|
|
def check_keys(
|
|
cls,
|
|
data: dict,
|
|
callback: callable,
|
|
*args,
|
|
**kwargs,
|
|
) -> dict:
|
|
needful_keys = set(cls.default.keys())
|
|
given_keys = set(data.keys())
|
|
if not needful_keys.issubset(given_keys):
|
|
callback(*args, **kwargs)
|
|
return cls.default
|
|
return data
|