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
a916180284
commit
1eea31d5bc
@ -73,7 +73,7 @@ class XHS:
|
||||
VERSION_BETA = VERSION_BETA
|
||||
LINK = compile(r"https?://www\.xiaohongshu\.com/explore/\S+")
|
||||
SHARE = compile(r"https?://www\.xiaohongshu\.com/discovery/item/\S+")
|
||||
SHORT = compile(r"https?://xhslink\.com/\S+")
|
||||
SHORT = compile(r"https?://xhslink\.com/[^\s\"<>\\^`{|},。;!?、【】《》]+")
|
||||
ID = compile(r"(?:explore|item)/(\S+)?\?")
|
||||
__INSTANCE = None
|
||||
CLEANER = Cleaner()
|
||||
|
||||
@ -36,8 +36,8 @@ class Html:
|
||||
cookie,
|
||||
)
|
||||
try:
|
||||
match (content, bool(proxy)):
|
||||
case (True, False):
|
||||
match bool(proxy):
|
||||
case False:
|
||||
response = await self.__request_url_get(
|
||||
url,
|
||||
headers,
|
||||
@ -45,8 +45,8 @@ class Html:
|
||||
)
|
||||
await sleep_time()
|
||||
response.raise_for_status()
|
||||
return response.text
|
||||
case (True, True):
|
||||
return response.text if content else str(response.url)
|
||||
case True:
|
||||
response = await self.__request_url_get_proxy(
|
||||
url,
|
||||
headers,
|
||||
@ -55,24 +55,7 @@ class Html:
|
||||
)
|
||||
await sleep_time()
|
||||
response.raise_for_status()
|
||||
return response.text
|
||||
case (False, False):
|
||||
response = await self.__request_url_head(
|
||||
url,
|
||||
headers,
|
||||
**kwargs,
|
||||
)
|
||||
await sleep_time()
|
||||
return str(response.url)
|
||||
case (False, True):
|
||||
response = await self.__request_url_head_proxy(
|
||||
url,
|
||||
headers,
|
||||
proxy,
|
||||
**kwargs,
|
||||
)
|
||||
await sleep_time()
|
||||
return str(response.url)
|
||||
return response.text if content else str(response.url)
|
||||
case _:
|
||||
raise ValueError
|
||||
except HTTPError as error:
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
**项目更新内容:**
|
||||
|
||||
1. 修改 API 模式默认端口为 `5556`
|
||||
2. 支持音乐图集作品下载
|
||||
2. 优化提取链接的正则表达式
|
||||
3. 支持音乐图集作品下载
|
||||
|
||||
*****
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user