mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2025-12-26 04:48:05 +08:00
perf(cleaner.py): 优化文件名称非法字符处理
BREAKING CHANGE: 移除内置延时机制
This commit is contained in:
parent
2c9ca72f4d
commit
81b88711d8
@ -1,10 +1,14 @@
|
||||
from platform import system
|
||||
from re import compile
|
||||
from string import whitespace
|
||||
from emoji import replace_emoji
|
||||
from warnings import warn
|
||||
|
||||
from emoji import replace_emoji
|
||||
|
||||
|
||||
class Cleaner:
|
||||
CONTROL_CHARACTERS = compile(r"[\x00-\x1F\x7F]")
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
替换字符串中包含的非法字符,默认根据系统类型生成对应的非法字符字典,也可以自行设置非法字符字典
|
||||
@ -67,6 +71,8 @@ class Cleaner:
|
||||
"""过滤文件夹名称中的非法字符"""
|
||||
text = text.replace(":", ".")
|
||||
|
||||
text = self.remove_control_characters(text)
|
||||
|
||||
text = self.filter(text)
|
||||
|
||||
text = replace_emoji(text, replace, )
|
||||
@ -82,8 +88,14 @@ class Cleaner:
|
||||
"""将连续的空格转换为单个空格"""
|
||||
return " ".join(string.split())
|
||||
|
||||
@classmethod
|
||||
def remove_control_characters(cls, text, replace="", ):
|
||||
# 使用正则表达式匹配所有控制字符
|
||||
return cls.CONTROL_CHARACTERS.sub(replace, text, )
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo = Cleaner()
|
||||
print(demo.rule)
|
||||
print(demo.filter_name(""))
|
||||
print(demo.remove_control_characters("hello \x08world"))
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
from pathlib import Path
|
||||
|
||||
VERSION_MAJOR = 2
|
||||
VERSION_MINOR = 3
|
||||
VERSION_BETA = False
|
||||
VERSION_MINOR = 4
|
||||
VERSION_BETA = True
|
||||
ROOT = Path(__file__).resolve().parent.parent.parent
|
||||
PROJECT = f"XHS-Downloader V{VERSION_MAJOR}.{
|
||||
VERSION_MINOR}{" Beta" if VERSION_BETA else ""}"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from asyncio import sleep
|
||||
from random import uniform
|
||||
# from asyncio import sleep
|
||||
# from random import uniform
|
||||
|
||||
from rich import print
|
||||
from rich.text import Text
|
||||
@ -31,4 +31,5 @@ async def sleep_time(
|
||||
min_time: int | float = 1,
|
||||
max_time: int | float = 3,
|
||||
):
|
||||
await sleep(uniform(min_time, max_time))
|
||||
pass
|
||||
# await sleep(uniform(min_time, max_time))
|
||||
|
||||
@ -1,28 +1,4 @@
|
||||
**项目更新内容:**
|
||||
|
||||
1. 修复下载文件频繁提示失败的问题
|
||||
2. 更新从浏览器读取 Cookie 功能
|
||||
3. 修复文件名称过长报错的问题
|
||||
4. 优化已下载文件判断逻辑
|
||||
5. 新增文件名称长度限制
|
||||
6. 优化文件后缀处理逻辑
|
||||
7. 优化代理测试逻辑
|
||||
8. 修复其他已知问题
|
||||
9. 优化代码运行逻辑
|
||||
|
||||
<p><strong>旧版本升级后首次运行请删除配置文件 <code>settings.json</code>,删除后重新运行程序会自动生成新的默认配置文件!</strong></p>
|
||||
|
||||
<p><strong>Windows 系统需要以管理员身份运行程序才能读取 Chromium、Chrome、Edge 浏览器 Cookie!</strong></p>
|
||||
|
||||
<hr>
|
||||
|
||||
**用户脚本更新内容:**
|
||||
|
||||
1. 重构作品链接提取功能
|
||||
2. 禁用自动滚动屏幕功能
|
||||
|
||||
<hr>
|
||||
|
||||
<p><strong>⚠️ 由于小红书规则更新,使用版本号低于 <code>1.7.1</code> 的用户脚本有封号风险,请及时更新用户脚本后再使用!</strong></p>
|
||||
|
||||
<p><strong>⚠️ 由于作品链接携带日期信息,使用先前日期获取的作品链接可能会被风控,建议下载作品文件时使用最新获取的作品链接!</strong></p>
|
||||
1. 优化文件名称非法字符处理
|
||||
2. 移除内置延时机制
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user