api/xiaohongshu: add support for new share links

This commit is contained in:
KwiatekMiki 2025-07-12 15:10:08 +02:00
parent 60f02b18e4
commit 9dafd8c8c8
No known key found for this signature in database
GPG Key ID: 91449EB0BBE1F17B
4 changed files with 21 additions and 5 deletions

View File

@ -263,6 +263,7 @@ export default async function({ host, patternMatch, params, authType }) {
case "xiaohongshu": case "xiaohongshu":
r = await xiaohongshu({ r = await xiaohongshu({
...patternMatch, ...patternMatch,
shareType: url.pathname.split("/")[1],
h265: params.allowH265, h265: params.allowH265,
isAudioOnly, isAudioOnly,
dispatcher, dispatcher,

View File

@ -207,7 +207,8 @@ export const services = {
patterns: [ patterns: [
"explore/:id?xsec_token=:token", "explore/:id?xsec_token=:token",
"discovery/item/:id?xsec_token=:token", "discovery/item/:id?xsec_token=:token",
"a/:shareId" "a/:shareId",
"m/:shareId"
], ],
altDomains: ["xhslink.com"], altDomains: ["xhslink.com"],
}, },

View File

@ -1,21 +1,35 @@
import { resolveRedirectingURL } from "../url.js"; import { resolveRedirectingURL, extract, normalizeURL } from "../url.js";
import { genericUserAgent } from "../../config.js"; import { genericUserAgent } from "../../config.js";
import { createStream } from "../../stream/manage.js"; import { createStream } from "../../stream/manage.js";
import { request } from "undici";
const https = (url) => { const https = (url) => {
return url.replace(/^http:/i, 'https:'); return url.replace(/^http:/i, 'https:');
} }
export default async function ({ id, token, shareId, h265, isAudioOnly, dispatcher }) { export default async function ({ id, token, shareType, shareId, h265, isAudioOnly, dispatcher }) {
let noteId = id; let noteId = id;
let xsecToken = token; let xsecToken = token;
if (!noteId) { if (!noteId && shareType === "a") {
const patternMatch = await resolveRedirectingURL( const patternMatch = await resolveRedirectingURL(
`https://xhslink.com/a/${shareId}`, `https://xhslink.com/a/${shareId}`,
dispatcher dispatcher
); );
noteId = patternMatch?.id;
xsecToken = patternMatch?.token;
} else if (!noteId && shareType === "m") {
const location = await request(`https://xhslink.com/m/${shareId}`, {
dispatcher,
redirect: 'manual'
}).then(r => {
if (r.statusCode === 302 && r.headers['location']) {
return r.headers['location'];
}
}).catch(() => null);
const { patternMatch } = extract(normalizeURL(location));
noteId = patternMatch?.id; noteId = patternMatch?.id;
xsecToken = patternMatch?.token; xsecToken = patternMatch?.token;
} }

View File

@ -99,7 +99,7 @@ function aliasURL(url) {
case "xhslink": case "xhslink":
if (url.hostname === 'xhslink.com' && parts.length === 3) { if (url.hostname === 'xhslink.com' && parts.length === 3) {
url = new URL(`https://www.xiaohongshu.com/a/${parts[2]}`); url = new URL(`https://www.xiaohongshu.com/${parts[1]}/${parts[2]}`);
} }
break; break;