fix(XHS-Downloader.js): 重构作品链接提取功能

Closes #179
This commit is contained in:
JoeanAmier 2024-09-24 20:10:28 +08:00
parent 2042afcd1e
commit 1698e1c792
5 changed files with 13 additions and 9 deletions

View File

@ -14,6 +14,7 @@
</div>
<br>
<p>🔥 <b>小红书链接提取/作品采集工具</b>:提取账号发布、收藏、点赞、专辑作品链接;提取搜索结果作品链接、用户链接;采集小红书作品信息;提取小红书作品下载地址;下载小红书无水印作品文件!</p>
<p><strong>⚠️⚠️⚠️由于小红书规则更新,使用版本号低于 <code>1.7.0</code> 的用户脚本有封号风险,请及时更新用户脚本后再使用!⚠️⚠️⚠️</strong></p>
<p>⭐ 本项目完全免费开源,无任何收费功能,请勿上当受骗!</p>
<h1>📑 项目功能</h1>
<ul><b>程序功能</b>

View File

@ -14,6 +14,7 @@
</div>
<br>
<p>🔥 <b>Xiaohongshu Link Extraction/Content Collection Tool</b>Extract account-published, favorited, and liked content links; extract search result content links and user links; collect Xiaohongshu content information; extract Xiaohongshu content download addresses; download Xiaohongshu watermark-free content files!</p>
<p><strong>Due to rule updates on Xiaohongshu, there is a risk of account suspension for user scripts with version numbers lower than <code>1.7.0</code> Please update the user scripts in a timely manner before using them! ⚠️⚠️⚠️</strong></p>
<p>⭐ This project is completely free and open-source, with no paid features. Please do not be deceived!</p>
<p>⭐ Due to the author's limited energy, I was unable to update the English document in a timely manner, and the content may have become outdated, partial translation is machine translation, the translation result may be incorrect, Suggest referring to Chinese documentation. If you want to contribute to translation, we warmly welcome you.</p>
<h1>📑 Project Features</h1>

View File

@ -1,7 +1,7 @@
from asyncio import Semaphore
from asyncio import gather
from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any
from aiofiles import open
from httpx import HTTPError
@ -60,7 +60,7 @@ class Download:
type_: str,
log,
bar,
) -> tuple[Path, tuple[bool, ...]]:
) -> tuple[Path, list[Any]]:
path = self.__generate_path(name)
match type_:
case "视频":

View File

@ -12,4 +12,6 @@
**用户脚本更新内容:**
1. 优化作品链接提取功能
1. 重构作品链接提取功能
<p><strong>⚠️⚠️⚠️由于小红书规则更新,使用版本号低于 <code>1.7.0</code> 的用户脚本有封号风险,请及时更新用户脚本后再使用!⚠️⚠️⚠️</strong></p>

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name XHS-Downloader
// @namespace https://github.com/JoeanAmier/XHS-Downloader
// @version 1.6.3
// @version 1.7.0
// @description 提取小红书作品/用户链接,下载小红书无水印图文/视频作品文件
// @author JoeanAmier
// @match http*://xhslink.com/*
@ -304,7 +304,7 @@
const extractNotesInfo = order => {
const notesRawValue = unsafeWindow.__INITIAL_STATE__.user.notes._rawValue[order];
return notesRawValue.map(item => [item.id, item.xsecToken]);
return notesRawValue.map(item => [item.id, item.xsecToken, "pc_user", "",]);
};
const extractBoardInfo = order => {
@ -320,7 +320,7 @@
const id = match[1]; // match[0] 是整个匹配的字符串match[1] 是第一个括号内的匹配
const notesRawValue = unsafeWindow.__INITIAL_STATE__.board.boardFeedsMap._rawValue[id].notes;
return notesRawValue.map(item => [item.noteId, item.xsecToken]);
return notesRawValue.map(item => [item.noteId, item.xsecToken, "pc_user", "&source=web_user_page",]);
} else {
console.error("从链接提取专辑 ID 失败", currentUrl,);
return [];
@ -329,12 +329,12 @@
const extractFeedInfo = () => {
const notesRawValue = unsafeWindow.__INITIAL_STATE__.feed.feeds._rawValue;
return notesRawValue.map(item => [item.id, item.xsecToken]);
return notesRawValue.map(item => [item.id, item.xsecToken, "pc_feed", "",]);
};
const extractSearchNotes = () => {
const notesRawValue = unsafeWindow.__INITIAL_STATE__.search.feeds._rawValue;
return notesRawValue.map(item => [item.id, item.xsecToken]);
return notesRawValue.map(item => [item.id, item.xsecToken, "pc_search", "&source=web_explore_feed",]);
}
const extractSearchUsers = () => {
@ -342,7 +342,7 @@
return notesRawValue.map(item => item.id);
}
const generateNoteUrls = data => data.map(([id, token]) => `https://www.xiaohongshu.com/explore/${id}?xsec_token=${token}&xsec_source=pc_user`).join(" ");
const generateNoteUrls = data => data.map(([id, token, source, other]) => `https://www.xiaohongshu.com/explore/${id}?xsec_token=${token}&xsec_source=${source}${other}`).join(" ");
const generateUserUrls = data => data.map(id => `https://www.xiaohongshu.com/user/profile/${id}`).join(" ");