rsshub
Version:
Make RSS Great Again!
137 lines (136 loc) • 3.93 kB
JavaScript
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs";
import { t as config } from "./config-CCmw1BNE.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as NotFoundError } from "./not-found-BvVU2U31.mjs";
import { t as getPlaywrightPage } from "./playwright-o20DiLNh.mjs";
import { t as renderUserEmbed } from "./user-C1ehbvl0.mjs";
import { load } from "cheerio";
//#region lib/routes/picuki/profile.ts
const route = {
path: "/profile/:id/:type?/:functionalFlag?",
categories: ["social-media"],
example: "/picuki/profile/linustech",
parameters: {
id: "Tiktok user id (without @)",
type: {
description: "Type of profile page",
options: [{
value: "profile",
label: "Profile Page"
}, {
value: "story",
label: "Story Page"
}],
default: "profile"
},
functionalFlag: {
description: "Functional flag for video embedding",
options: [{
value: "0",
label: "Off, only show video poster as an image"
}, {
value: "1",
label: "On"
}],
default: "1"
}
},
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["www.picuki.com/profile/:id"],
target: "/profile/:id"
}, {
source: ["www.picuki.com/story/:id"],
target: "/profile/:id/story"
}],
name: "User Profile - Picuki",
maintainers: [
"hoilc",
"Rongronggg9",
"devinmugen",
"NekoAria"
],
handler
};
async function handler(ctx) {
const id = ctx.req.param("id");
const type = ctx.req.param("type") ?? "profile";
const useIframe = (ctx.req.param("functionalFlag") ?? "1") !== "0";
const baseUrl = "https://www.picuki.com";
const profileUrl = `${baseUrl}/${type === "story" ? "story" : "profile"}/${id}`;
const data = await cache_default.tryGet(`picuki:${type}:${id}`, async () => {
let response;
try {
response = await rofetch(profileUrl, { headers: { "User-Agent": config.trueUA } });
} catch (error) {
if (error.status === 403) {
const { page, destroy } = await getPlaywrightPage(profileUrl, { onBeforeLoad: async (page) => {
const expectResourceTypes = /* @__PURE__ */ new Set([
"document",
"script",
"xhr",
"fetch"
]);
await page.route("**/*", (route) => {
const request = route.request();
expectResourceTypes.has(request.resourceType()) ? route.continue() : route.abort();
});
} });
await page.waitForSelector(".content");
response = await page.content();
await destroy();
} else throw new NotFoundError(error.message);
}
const $ = load(response);
if ($(".posts-empty").length) throw new Error($(".posts-empty").text().trim() || "No posts found");
if ($(".error-p").length) throw new Error($(".error-p span").text().trim() || "Profile not found");
const username = $(".profile-info .username").text().trim();
const items = $(".posts-video .posts__video-item .posts__video-item-a").toArray().map((item) => {
const $item = $(item);
const videoId = $item.attr("href")?.split("/").pop();
const img = $item.find("img");
return {
title: img.attr("alt") || "",
author: username,
renderData: {
poster: img.attr("src"),
source: `${baseUrl}/player/${videoId}`,
id: videoId
},
link: `${baseUrl}/media/${videoId}`,
guid: `https://www.tiktok.com/@${id}/video/${videoId}`
};
});
return {
title: $("head title").text(),
description: $(".posts-current").text().trim(),
image: $(".profile-image").attr("src"),
items
};
});
const items = data.items.map((item) => ({
...item,
description: renderUserEmbed({
poster: item.renderData.poster,
source: item.renderData.source,
useIframe,
id: item.renderData.id
})
}));
return {
title: data.title,
link: profileUrl,
image: data.image,
description: data.description,
item: items
};
}
//#endregion
export { route };