mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2026-03-22 06:57:16 +08:00
perf: 优化提取链接的正则表达式
This commit is contained in:
@@ -73,7 +73,7 @@ class XHS:
|
|||||||
VERSION_BETA = VERSION_BETA
|
VERSION_BETA = VERSION_BETA
|
||||||
LINK = compile(r"https?://www\.xiaohongshu\.com/explore/\S+")
|
LINK = compile(r"https?://www\.xiaohongshu\.com/explore/\S+")
|
||||||
SHARE = compile(r"https?://www\.xiaohongshu\.com/discovery/item/\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+)?\?")
|
ID = compile(r"(?:explore|item)/(\S+)?\?")
|
||||||
__INSTANCE = None
|
__INSTANCE = None
|
||||||
CLEANER = Cleaner()
|
CLEANER = Cleaner()
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ class Html:
|
|||||||
cookie,
|
cookie,
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
match (content, bool(proxy)):
|
match bool(proxy):
|
||||||
case (True, False):
|
case False:
|
||||||
response = await self.__request_url_get(
|
response = await self.__request_url_get(
|
||||||
url,
|
url,
|
||||||
headers,
|
headers,
|
||||||
@@ -45,8 +45,8 @@ class Html:
|
|||||||
)
|
)
|
||||||
await sleep_time()
|
await sleep_time()
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.text
|
return response.text if content else str(response.url)
|
||||||
case (True, True):
|
case True:
|
||||||
response = await self.__request_url_get_proxy(
|
response = await self.__request_url_get_proxy(
|
||||||
url,
|
url,
|
||||||
headers,
|
headers,
|
||||||
@@ -55,24 +55,7 @@ class Html:
|
|||||||
)
|
)
|
||||||
await sleep_time()
|
await sleep_time()
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.text
|
return response.text if content else str(response.url)
|
||||||
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)
|
|
||||||
case _:
|
case _:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
except HTTPError as error:
|
except HTTPError as error:
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
**项目更新内容:**
|
**项目更新内容:**
|
||||||
|
|
||||||
1. 修改 API 模式默认端口为 `5556`
|
1. 修改 API 模式默认端口为 `5556`
|
||||||
2. 支持音乐图集作品下载
|
2. 优化提取链接的正则表达式
|
||||||
|
3. 支持音乐图集作品下载
|
||||||
|
|
||||||
*****
|
*****
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user