Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=""

Expand Down
7 changes: 7 additions & 0 deletions src/nonebot_plugin_parser/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""代理"""
Expand Down
7 changes: 6 additions & 1 deletion src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -21,6 +21,7 @@ def __init__(self):
)
}
self.headers.update(explore_headers)

discovery_headers = {
"origin": "https://www.xiaohongshu.com",
"x-requested-with": "XMLHttpRequest",
Expand All @@ -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)}"
Expand Down
Loading