diff --git a/pyproject.toml b/pyproject.toml index 7818d92..9e7786c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,13 +13,13 @@ dependencies = [ "aiosqlite>=0.21.0", "click>=8.1.8", "emoji>=2.14.1", - "fastapi>=0.115.8", + "fastapi>=0.115.9", "httpx[socks]>=0.28.1", "lxml>=5.3.1", "pyperclip>=1.9.0", "pyyaml>=6.0.2", "rookiepy>=0.5.6", - "textual>=1.0.0", + "textual>=2.1.2", "uvicorn>=0.34.0", ] diff --git a/requirements.txt b/requirements.txt index f6db69b..e61b468 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ click==8.1.8 # via xhs-downloader (pyproject.toml) emoji==2.14.1 # via xhs-downloader (pyproject.toml) -fastapi==0.115.8 +fastapi==0.115.9 # via xhs-downloader (pyproject.toml) httpx[socks]==0.28.1 # via xhs-downloader (pyproject.toml) @@ -20,7 +20,7 @@ pyyaml==6.0.2 # via xhs-downloader (pyproject.toml) rookiepy==0.5.6 # via xhs-downloader (pyproject.toml) -textual==2.0.4 +textual==2.1.2 # via xhs-downloader (pyproject.toml) uvicorn==0.34.0 # via xhs-downloader (pyproject.toml) diff --git a/source/application/request.py b/source/application/request.py index 62f9213..b5c5765 100644 --- a/source/application/request.py +++ b/source/application/request.py @@ -18,7 +18,6 @@ class Html: self.retry = manager.retry self.client = manager.request_client self.headers = manager.headers - self.blank_headers = manager.blank_headers @retry async def request_url( @@ -29,8 +28,7 @@ class Html: cookie: str = None, **kwargs, ) -> str: - headers = self.select_headers( - url, + headers = self.update_cookie( cookie, ) try: @@ -52,6 +50,8 @@ class Html: ) await sleep_time() return str(response.url) + case _: + raise ValueError except HTTPError as error: logging( log, _("网络异常,{0} 请求失败: {1}").format(url, repr(error)), ERROR @@ -62,14 +62,11 @@ class Html: def format_url(url: str) -> str: return bytes(url, "utf-8").decode("unicode_escape") - def select_headers( + def update_cookie( self, - url: str, cookie: str = None, ) -> dict: - if "explore" not in url: - return self.blank_headers - return self.headers | {"Cookie": cookie} if cookie else self.headers + return self.headers | {"Cookie": cookie} if cookie else self.headers.copy() async def __request_url_head( self, diff --git a/static/Release_Notes.md b/static/Release_Notes.md index d93a92a..8a25078 100644 --- a/static/Release_Notes.md +++ b/static/Release_Notes.md @@ -1,7 +1,8 @@ **项目更新内容:** 1. 增加对 `JPEG` 和 `HEIC` 图片格式的支持 -2. 支持 `SOCKS` 代理 +2. 优化 `headers` 处理逻辑 +3. 支持 `SOCKS` 代理 *****