mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2025-12-26 04:48:05 +08:00
1. 更新 Cookie 参数处理 2. 优化作品数据返回格式 3. 更新用户脚本链接提取功能 4. 优化项目运行信息提示 5. 修复 record_data 参数无效的问题 6. 新增作品下载记录开关 7. 适配小红书平台规则 8. 默认开启局域网访问 9. 格式化项目代码 10. 更新英语翻译 Closes #127 Closes #128 Closes #130 Closes #132
68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
from datetime import datetime
|
|
|
|
from source.expansion import Namespace
|
|
|
|
__all__ = ['Explore']
|
|
|
|
|
|
class Explore:
|
|
time_format = "%Y-%m-%d_%H:%M:%S"
|
|
explore_type = {"video": "视频", "normal": "图文"}
|
|
|
|
def run(self, data: Namespace) -> dict:
|
|
return self.__extract_data(data)
|
|
|
|
def __extract_data(self, data: Namespace) -> dict:
|
|
result = {}
|
|
if data:
|
|
self.__extract_interact_info(result, data)
|
|
self.__extract_tags(result, data)
|
|
self.__extract_info(result, data)
|
|
self.__extract_time(result, data)
|
|
self.__extract_user(result, data)
|
|
return result
|
|
|
|
@staticmethod
|
|
def __extract_interact_info(container: dict, data: Namespace) -> None:
|
|
container["收藏数量"] = data.safe_extract(
|
|
"interactInfo.collectedCount", "-1")
|
|
container["评论数量"] = data.safe_extract(
|
|
"interactInfo.commentCount", "-1")
|
|
container["分享数量"] = data.safe_extract("interactInfo.shareCount", "-1")
|
|
container["点赞数量"] = data.safe_extract("interactInfo.likedCount", "-1")
|
|
|
|
@staticmethod
|
|
def __extract_tags(container: dict, data: Namespace):
|
|
tags = data.safe_extract("tagList", [])
|
|
container["作品标签"] = " ".join(
|
|
Namespace.object_extract(
|
|
i, "name") for i in tags)
|
|
|
|
def __extract_info(self, container: dict, data: Namespace):
|
|
container["作品ID"] = data.safe_extract("noteId")
|
|
container["作品链接"] = f"https://www.xiaohongshu.com/explore/{container["作品ID"]}"
|
|
container["作品标题"] = data.safe_extract("title")
|
|
container["作品描述"] = data.safe_extract("desc")
|
|
container["作品类型"] = self.explore_type.get(
|
|
data.safe_extract("type"), "未知")
|
|
# container["IP归属地"] = data.safe_extract("ipLocation")
|
|
|
|
def __extract_time(self, container: dict, data: Namespace):
|
|
container["发布时间"] = datetime.fromtimestamp(
|
|
time /
|
|
1000).strftime(
|
|
self.time_format) if (
|
|
time := data.safe_extract("time")) else "未知"
|
|
container["最后更新时间"] = datetime.fromtimestamp(
|
|
last /
|
|
1000).strftime(
|
|
self.time_format) if (
|
|
last := data.safe_extract("lastUpdateTime")) else "未知"
|
|
|
|
@staticmethod
|
|
def __extract_user(container: dict, data: Namespace):
|
|
container["作者昵称"] = data.safe_extract("user.nickname")
|
|
container["作者ID"] = data.safe_extract("user.userId")
|
|
container["作者链接"] = f"https://www.xiaohongshu.com/user/profile/{
|
|
container["作者ID"]}"
|