mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2025-12-26 04:48:05 +08:00
perf: 优化配置文件参数容错机制
This commit is contained in:
parent
e5d628ba93
commit
0a9f2f3059
@ -19,13 +19,12 @@
|
|||||||
<br>
|
<br>
|
||||||
<p>🔥 <b>小红书链接提取/作品采集工具</b>:提取账号发布、收藏、点赞、专辑作品链接;提取搜索结果作品链接、用户链接;采集小红书作品信息;提取小红书作品下载地址;下载小红书无水印作品文件!</p>
|
<p>🔥 <b>小红书链接提取/作品采集工具</b>:提取账号发布、收藏、点赞、专辑作品链接;提取搜索结果作品链接、用户链接;采集小红书作品信息;提取小红书作品下载地址;下载小红书无水印作品文件!</p>
|
||||||
<p>🔥 “小红书”、“XiaoHongShu”、“RedNote” 含义相同,本项目统称为 “小红书”</p>
|
<p>🔥 “小红书”、“XiaoHongShu”、“RedNote” 含义相同,本项目统称为 “小红书”</p>
|
||||||
<p>⭐ 本项目完全免费开源,无任何收费功能,请勿上当受骗!</p>
|
|
||||||
<h1>📑 项目功能</h1>
|
<h1>📑 项目功能</h1>
|
||||||
<ul><b>程序功能</b>
|
<ul><b>程序功能</b>
|
||||||
<li>✅ 采集小红书作品信息</li>
|
<li>✅ 采集小红书作品信息</li>
|
||||||
<li>✅ 提取小红书作品下载地址</li>
|
<li>✅ 提取小红书作品下载地址</li>
|
||||||
<li>✅ 下载小红书无水印作品文件</li>
|
<li>✅ 下载小红书无水印作品文件</li>
|
||||||
<li>✅ 下载小红书 livePhoto 文件(非无水印)</li>
|
<li>✅ 下载小红书 livePhoto 文件(含水印)</li>
|
||||||
<li>✅ 自动跳过已下载的作品文件</li>
|
<li>✅ 自动跳过已下载的作品文件</li>
|
||||||
<li>✅ 作品文件完整性处理机制</li>
|
<li>✅ 作品文件完整性处理机制</li>
|
||||||
<li>✅ 自定义图文作品文件下载格式</li>
|
<li>✅ 自定义图文作品文件下载格式</li>
|
||||||
@ -265,7 +264,7 @@ async def example():
|
|||||||
record_data = False # 是否保存作品数据至文件
|
record_data = False # 是否保存作品数据至文件
|
||||||
image_format = "WEBP" # 图文作品文件下载格式,支持:AUTO、PNG、WEBP、JPEG、HEIC
|
image_format = "WEBP" # 图文作品文件下载格式,支持:AUTO、PNG、WEBP、JPEG、HEIC
|
||||||
folder_mode = False # 是否将每个作品的文件储存至单独的文件夹
|
folder_mode = False # 是否将每个作品的文件储存至单独的文件夹
|
||||||
image_download = True # 图文作品文件下载开关
|
image_download = True # 图文、图集作品文件下载开关
|
||||||
video_download = True # 视频作品文件下载开关
|
video_download = True # 视频作品文件下载开关
|
||||||
live_download = False # 图文动图文件下载开关
|
live_download = False # 图文动图文件下载开关
|
||||||
download_record = True # 是否记录下载成功的作品 ID
|
download_record = True # 是否记录下载成功的作品 ID
|
||||||
@ -406,7 +405,7 @@ async def example():
|
|||||||
<tr>
|
<tr>
|
||||||
<td align="center">image_download</td>
|
<td align="center">image_download</td>
|
||||||
<td align="center">bool</td>
|
<td align="center">bool</td>
|
||||||
<td align="center">图文作品文件下载开关</td>
|
<td align="center">图文、图集作品文件下载开关</td>
|
||||||
<td align="center">true</td>
|
<td align="center">true</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@ -19,14 +19,13 @@
|
|||||||
<br>
|
<br>
|
||||||
<p>🔥 <b>RedNote Link Extraction/Content Collection Tool</b>:Extract account-published, favorites, and liked works links; extract search result works links and user links; collect RedNote works information; extract RedNote works download addresses; download RedNote watermark-free works files!</p>
|
<p>🔥 <b>RedNote Link Extraction/Content Collection Tool</b>:Extract account-published, favorites, and liked works links; extract search result works links and user links; collect RedNote works information; extract RedNote works download addresses; download RedNote watermark-free works files!</p>
|
||||||
<p>🔥 "RedNote", "XiaoHongShu" and "小红书" have the same meaning, and this project is collectively referred to as "RedNote".</p>
|
<p>🔥 "RedNote", "XiaoHongShu" and "小红书" have the same meaning, and this project is collectively referred to as "RedNote".</p>
|
||||||
<p>⭐ This project is completely free and open-source, with no paid features. Please do not be deceived!</p>
|
|
||||||
<p>⭐ Due to the author's limited energy, I was unable to update the English document in a timely manner, and the content may have become outdated, partial translation is machine translation, the translation result may be incorrect, Suggest referring to Chinese documentation. If you want to contribute to translation, we warmly welcome you.</p>
|
<p>⭐ Due to the author's limited energy, I was unable to update the English document in a timely manner, and the content may have become outdated, partial translation is machine translation, the translation result may be incorrect, Suggest referring to Chinese documentation. If you want to contribute to translation, we warmly welcome you.</p>
|
||||||
<h1>📑 Project Features</h1>
|
<h1>📑 Project Features</h1>
|
||||||
<ul><b>Program Features</b>
|
<ul><b>Program Features</b>
|
||||||
<li>✅ Collect RedNote works information</li>
|
<li>✅ Collect RedNote works information</li>
|
||||||
<li>✅ Extract RedNote works download addresses</li>
|
<li>✅ Extract RedNote works download addresses</li>
|
||||||
<li>✅ Download RedNote watermark-free works files</li>
|
<li>✅ Download RedNote watermark-free works files</li>
|
||||||
<li>✅ Download RedNote livePhoto files (non-watermark-free)</li>
|
<li>✅ Download RedNote livePhoto files (watermark)</li>
|
||||||
<li>✅ Automatically skip already downloaded works files</li>
|
<li>✅ Automatically skip already downloaded works files</li>
|
||||||
<li>✅ works file integrity handling mechanism</li>
|
<li>✅ works file integrity handling mechanism</li>
|
||||||
<li>✅ Customizable image works file download format</li>
|
<li>✅ Customizable image works file download format</li>
|
||||||
@ -271,7 +270,7 @@ async def example():
|
|||||||
record_data = False # 是否保存作品数据至文件
|
record_data = False # 是否保存作品数据至文件
|
||||||
image_format = "WEBP" # 图文作品文件下载格式,支持:AUTO、PNG、WEBP、JPEG、HEIC
|
image_format = "WEBP" # 图文作品文件下载格式,支持:AUTO、PNG、WEBP、JPEG、HEIC
|
||||||
folder_mode = False # 是否将每个作品的文件储存至单独的文件夹
|
folder_mode = False # 是否将每个作品的文件储存至单独的文件夹
|
||||||
image_download = True # 图文作品文件下载开关
|
image_download = True # 图文、图集作品文件下载开关
|
||||||
video_download = True # 视频作品文件下载开关
|
video_download = True # 视频作品文件下载开关
|
||||||
live_download = False # 图文动图文件下载开关
|
live_download = False # 图文动图文件下载开关
|
||||||
download_record = True # 是否记录下载成功的作品 ID
|
download_record = True # 是否记录下载成功的作品 ID
|
||||||
@ -412,7 +411,7 @@ async def example():
|
|||||||
<tr>
|
<tr>
|
||||||
<td align="center">image_download</td>
|
<td align="center">image_download</td>
|
||||||
<td align="center">bool</td>
|
<td align="center">bool</td>
|
||||||
<td align="center">Switch for downloading image works files</td>
|
<td align="center">Switch for downloading image and atlas works files</td>
|
||||||
<td align="center">true</td>
|
<td align="center">true</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ async def example():
|
|||||||
record_data = False # 是否保存作品数据至文件
|
record_data = False # 是否保存作品数据至文件
|
||||||
image_format = "WEBP" # 图文作品文件下载格式,支持:AUTO、PNG、WEBP、JPEG、HEIC
|
image_format = "WEBP" # 图文作品文件下载格式,支持:AUTO、PNG、WEBP、JPEG、HEIC
|
||||||
folder_mode = False # 是否将每个作品的文件储存至单独的文件夹
|
folder_mode = False # 是否将每个作品的文件储存至单独的文件夹
|
||||||
image_download = True # 图文作品文件下载开关
|
image_download = True # 图文、图集作品文件下载开关
|
||||||
video_download = True # 视频作品文件下载开关
|
video_download = True # 视频作品文件下载开关
|
||||||
live_download = False # 图文动图文件下载开关
|
live_download = False # 图文动图文件下载开关
|
||||||
download_record = True # 是否记录下载成功的作品 ID
|
download_record = True # 是否记录下载成功的作品 ID
|
||||||
|
|||||||
@ -1,14 +1,10 @@
|
|||||||
from textual.app import App
|
from textual.app import App
|
||||||
from textual.widgets import RichLog
|
|
||||||
|
|
||||||
from ..application import XHS
|
from ..application import XHS
|
||||||
from ..module import (
|
from ..module import (
|
||||||
ERROR,
|
|
||||||
ROOT,
|
ROOT,
|
||||||
Settings,
|
Settings,
|
||||||
logging,
|
|
||||||
)
|
)
|
||||||
from ..translation import _
|
|
||||||
from .about import About
|
from .about import About
|
||||||
from .index import Index
|
from .index import Index
|
||||||
from .loading import Loading
|
from .loading import Loading
|
||||||
@ -66,16 +62,6 @@ class XHSDownloader(App):
|
|||||||
name="record",
|
name="record",
|
||||||
)
|
)
|
||||||
await self.push_screen("index")
|
await self.push_screen("index")
|
||||||
self.SETTINGS.check_keys(
|
|
||||||
self.parameter,
|
|
||||||
logging,
|
|
||||||
self.screen.query_one(RichLog),
|
|
||||||
_(
|
|
||||||
"配置文件 settings.json 缺少必要的参数,请删除该文件,然后重新运行程序,自动生成默认配置文件!"
|
|
||||||
)
|
|
||||||
+ f"\n{'>' * 50}",
|
|
||||||
ERROR,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def action_settings(self):
|
async def action_settings(self):
|
||||||
async def save_settings(data: dict) -> None:
|
async def save_settings(data: dict) -> None:
|
||||||
|
|||||||
@ -8,60 +8,66 @@ __all__ = ["Settings"]
|
|||||||
|
|
||||||
|
|
||||||
class Settings:
|
class Settings:
|
||||||
|
# 默认配置参数
|
||||||
default = {
|
default = {
|
||||||
"mapping_data": {},
|
"mapping_data": {}, # 账号备注映射数据
|
||||||
"work_path": "",
|
"work_path": "", # 工作目录路径
|
||||||
"folder_name": "Download",
|
"folder_name": "Download", # 下载文件夹名称
|
||||||
"name_format": "发布时间 作者昵称 作品标题",
|
"name_format": "发布时间 作者昵称 作品标题", # 文件命名格式
|
||||||
"user_agent": USERAGENT,
|
"user_agent": USERAGENT, # 请求头
|
||||||
"cookie": "",
|
"cookie": "", # Cookie
|
||||||
"proxy": None,
|
"proxy": None, # 代理设置
|
||||||
"timeout": 10,
|
"timeout": 10, # 超时时间(秒)
|
||||||
"chunk": 1024 * 1024 * 2,
|
"chunk": 1024 * 1024 * 2, # 下载块大小(字节)
|
||||||
"max_retry": 5,
|
"max_retry": 5, # 最大重试次数
|
||||||
"record_data": False,
|
"record_data": False, # 是否记录作品数据
|
||||||
"image_format": "PNG",
|
"image_format": "PNG", # 图文作品格式
|
||||||
"image_download": True,
|
"image_download": True, # 是否下载图文
|
||||||
"video_download": True,
|
"video_download": True, # 是否下载视频
|
||||||
"live_download": False,
|
"live_download": False, # 是否下载动图
|
||||||
"folder_mode": False,
|
"folder_mode": False, # 文件夹归档模式
|
||||||
"download_record": True,
|
"download_record": True, # 是否记录下载历史
|
||||||
"author_archive": False,
|
"author_archive": False, # 是否按作者归档
|
||||||
"write_mtime": False,
|
"write_mtime": False, # 是否写入修改时间
|
||||||
"language": "zh_CN",
|
"language": "zh_CN", # 语言设置
|
||||||
}
|
}
|
||||||
|
# 根据操作系统设置编码格式
|
||||||
encode = "UTF-8-SIG" if system() == "Windows" else "UTF-8"
|
encode = "UTF-8-SIG" if system() == "Windows" else "UTF-8"
|
||||||
|
|
||||||
def __init__(self, root: Path = ROOT):
|
def __init__(self, root: Path = ROOT):
|
||||||
|
# 设置文件路径
|
||||||
self.file = root.joinpath("./settings.json")
|
self.file = root.joinpath("./settings.json")
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
# 如果文件存在则读取,否则创建新文件
|
||||||
return self.read() if self.file.is_file() else self.create()
|
return self.read() if self.file.is_file() else self.create()
|
||||||
|
|
||||||
def read(self) -> dict:
|
def read(self) -> dict:
|
||||||
|
# 读取设置文件
|
||||||
with self.file.open("r", encoding=self.encode) as f:
|
with self.file.open("r", encoding=self.encode) as f:
|
||||||
return load(f)
|
return self.compatible(load(f))
|
||||||
|
|
||||||
def create(self) -> dict:
|
def create(self) -> dict:
|
||||||
|
# 创建新的设置文件
|
||||||
with self.file.open("w", encoding=self.encode) as f:
|
with self.file.open("w", encoding=self.encode) as f:
|
||||||
dump(self.default, f, indent=4, ensure_ascii=False)
|
dump(self.default, f, indent=4, ensure_ascii=False)
|
||||||
return self.default
|
return self.default
|
||||||
|
|
||||||
def update(self, data: dict):
|
def update(self, data: dict):
|
||||||
|
# 更新设置文件
|
||||||
with self.file.open("w", encoding=self.encode) as f:
|
with self.file.open("w", encoding=self.encode) as f:
|
||||||
dump(data, f, indent=4, ensure_ascii=False)
|
dump(data, f, indent=4, ensure_ascii=False)
|
||||||
|
|
||||||
@classmethod
|
def compatible(
|
||||||
def check_keys(
|
self,
|
||||||
cls,
|
|
||||||
data: dict,
|
data: dict,
|
||||||
callback: callable,
|
|
||||||
*args,
|
|
||||||
**kwargs,
|
|
||||||
) -> dict:
|
) -> dict:
|
||||||
needful_keys = set(cls.default.keys())
|
# 兼容性检查: 确保所有默认配置都存在
|
||||||
given_keys = set(data.keys())
|
update = False
|
||||||
if not needful_keys.issubset(given_keys):
|
for i, j in self.default.items():
|
||||||
callback(*args, **kwargs)
|
if i not in data:
|
||||||
return cls.default
|
data[i] = j
|
||||||
|
update = True
|
||||||
|
if update:
|
||||||
|
self.update(data)
|
||||||
return data
|
return data
|
||||||
|
|||||||
@ -15,10 +15,7 @@ RELEASES = "https://github.com/JoeanAmier/XHS-Downloader/releases/latest"
|
|||||||
|
|
||||||
USERSCRIPT = "https://raw.githubusercontent.com/JoeanAmier/XHS-Downloader/master/static/XHS-Downloader.js"
|
USERSCRIPT = "https://raw.githubusercontent.com/JoeanAmier/XHS-Downloader/master/static/XHS-Downloader.js"
|
||||||
|
|
||||||
USERAGENT = (
|
USERAGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 "
|
|
||||||
"Safari/537.36"
|
|
||||||
)
|
|
||||||
|
|
||||||
HEADERS = {
|
HEADERS = {
|
||||||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,"
|
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,"
|
||||||
|
|||||||
@ -4,11 +4,12 @@
|
|||||||
2. 修改服务器模式请求路径为 `/xhs/detail`
|
2. 修改服务器模式请求路径为 `/xhs/detail`
|
||||||
3. 修改服务器模式默认端口为 `5556`
|
3. 修改服务器模式默认端口为 `5556`
|
||||||
4. 服务器模式新增 MCP 模式
|
4. 服务器模式新增 MCP 模式
|
||||||
5. 优化提取链接的正则表达式
|
5. 优化配置文件参数容错机制
|
||||||
6. 修改服务器模式启动命令
|
6. 优化提取链接的正则表达式
|
||||||
7. 支持更多作品链接格式
|
7. 修改服务器模式启动命令
|
||||||
8. 支持音乐图集作品下载
|
8. 支持更多作品链接格式
|
||||||
9. 其他细节优化
|
9. 支持音乐图集作品下载
|
||||||
|
10. 其他细节优化
|
||||||
|
|
||||||
*****
|
*****
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user