UNPKG

rsshub

Version:
144 lines (142 loc) 4.2 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as not_found_default } from "./not-found-Z_3JX2qs.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import "./proxy-Db7uGcYb.mjs"; import { t as getPuppeteerPage } from "./puppeteer-DGmvuGvT.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/picuki/profile.ts init_esm_shims(); 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 ofetch_default(profileUrl, { headers: { "User-Agent": config.trueUA } }); } catch (error) { if (error.status === 403) { const { page, destory } = await getPuppeteerPage(profileUrl, { onBeforeLoad: async (page$1) => { const expectResourceTypes = new Set([ "document", "script", "xhr", "fetch" ]); await page$1.setRequestInterception(true); page$1.on("request", (request) => { expectResourceTypes.has(request.resourceType()) ? request.continue() : request.abort(); }); } }); await page.waitForSelector(".content"); response = await page.content(); await destory(); } else throw new not_found_default(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$1 = $(".posts-video .posts__video-item").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: $item.find(".popup-open").data("source"), 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: items$1 }; }); const items = data.items.map((item) => ({ ...item, description: art(path.join(__dirname, "templates/user-3df0b995.art"), { 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 };