diff --git a/README.md b/README.md index 1cf1b3aa..cd9c0f42 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,9 @@ parser_bili_video_codes='["avc", "av01", "hev"]' # 360p(16), 480p(32), 720p(64), 1080p(80), 1080p+(112), 1080p_60(116), 4k(120) parser_bili_video_quality=80 +# [可选] 小红书 Cookie, 部分链接解析有水印,可填 +parser_xhs_ck="" + # [可选] Youtube Cookie, Youtube 视频因人机检测下载失败,需填 parser_ytb_ck="" diff --git a/src/nonebot_plugin_parser/config.py b/src/nonebot_plugin_parser/config.py index 76b47d5f..4d9f75cf 100644 --- a/src/nonebot_plugin_parser/config.py +++ b/src/nonebot_plugin_parser/config.py @@ -20,6 +20,8 @@ class Config(BaseModel): """bilibili cookies""" parser_ytb_ck: str | None = None """youtube cookies""" + parser_xhs_ck: str | None = None + """小红书 cookies""" parser_proxy: str | None = None """代理""" parser_need_upload: bool = False @@ -113,6 +115,11 @@ def ytb_ck(self) -> str | None: """youtube cookies""" return self.parser_ytb_ck + @property + def xhs_ck(self) -> str | None: + """小红书 cookies""" + return self.parser_xhs_ck + @property def proxy(self) -> str | None: """代理""" diff --git a/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py b/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py index 1b920891..6961e874 100644 --- a/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py +++ b/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py @@ -4,7 +4,7 @@ from httpx import Cookies, AsyncClient from nonebot import logger -from ..base import Platform, BaseParser, PlatformEnum, ParseException, handle +from ..base import Platform, BaseParser, PlatformEnum, ParseException, handle, pconfig from ..data import MediaContent @@ -21,6 +21,7 @@ def __init__(self): ) } self.headers.update(explore_headers) + discovery_headers = { "origin": "https://www.xiaohongshu.com", "x-requested-with": "XMLHttpRequest", @@ -30,6 +31,10 @@ def __init__(self): } self.ios_headers.update(discovery_headers) + if pconfig.xhs_ck: + self.headers["cookie"] = pconfig.xhs_ck + self.ios_headers["cookie"] = pconfig.xhs_ck + @handle("xhslink.com", r"xhslink\.com/[A-Za-z0-9._?%&+=/#@-]+") async def _parse_short_link(self, searched: re.Match[str]): url = f"https://{searched.group(0)}"