UNPKG

rsshub

Version:
146 lines (144 loc) • 4.71 kB
import { t as config } from "./config-MQ-7ebJ_.mjs"; import { t as ViewType } from "./types-gOySfSXJ.mjs"; import "./logger-C4avouvV.mjs"; import { n as parseRelativeDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import { load } from "cheerio"; import { connect } from "puppeteer-real-browser"; //#region lib/routes/picnob/user.ts const realBrowserOption = { args: ["--start-maximized"], turnstile: true, headless: false, customConfig: { chromePath: config.chromiumExecutablePath }, connectOption: { defaultViewport: null }, plugins: [] }; async function getPageWithRealBrowser(url, selector, conn) { try { if (conn) { const page = conn.page; await page.goto(url, { timeout: 3e4 }); let verify = null; const startDate = Date.now(); while (!verify && Date.now() - startDate < 3e4) { verify = await page.evaluate((sel) => document.querySelector(sel) ? true : null, selector).catch(() => null); await new Promise((r) => setTimeout(r, 1e3)); } return await page.content(); } else return (await (await fetch(`${config.puppeteerRealBrowserService}?url=${encodeURIComponent(url)}&selector=${encodeURIComponent(selector)}`)).json()).data?.at(0) || ""; } catch { return ""; } } const route = { path: "/user/:id/:type?", categories: ["social-media"], example: "/picnob/user/xlisa_olivex", parameters: { id: "Instagram id", type: "Type of profile page (profile or tagged)" }, features: { requireConfig: false, requirePuppeteer: true, antiCrawler: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.pixnoy.com/profile/:id"], target: "/user/:id" }, { source: ["www.pixnoy.com/profile/:id/tagged"], target: "/user/:id/tagged" }], name: "User Profile - Pixnoy", maintainers: [ "TonyRL", "micheal-death", "AiraNadih", "DIYgod", "hyoban", "Rongronggg9" ], handler, view: ViewType.Pictures }; async function handler(ctx) { if (!config.puppeteerRealBrowserService && !config.chromiumExecutablePath) throw new Error("PUPPETEER_REAL_BROWSER_SERVICE or CHROMIUM_EXECUTABLE_PATH is required to use this route."); const baseUrl = "https://www.pixnoy.com"; const id = ctx.req.param("id"); const type = ctx.req.param("type") ?? "profile"; const profileUrl = `${baseUrl}/profile/${id}/${type === "tagged" ? "tagged/" : ""}`; let conn = null; if (!config.puppeteerRealBrowserService) { conn = await connect(realBrowserOption); setTimeout(async () => { if (conn) await conn.browser.close(); }, 6e4); } const html = await getPageWithRealBrowser(profileUrl, ".post_box", conn); if (!html) { if (conn) { await conn.browser.close(); conn = null; } throw new Error("Failed to fetch user profile page. User may not exist or there are no posts available."); } const $ = load(html); const list = $(".post_box").toArray().map((item) => { const $item = $(item); const coverLink = $item.find(".cover_link").attr("href"); const shortcode = coverLink?.split("/")?.[2]; const image = $item.find(".cover .cover_link img"); const title = image.attr("alt") || ""; return { title, description: `<img src="${image.attr("data-src")}" /><br />${title}`, link: `${baseUrl}${coverLink}`, guid: shortcode, pubDate: parseRelativeDate($item.find(".time .txt").text()) }; }); const jobs = list.map((item) => cache_default.tryGet(`picnob:user:${id}:${item.guid}:html`, async () => await getPageWithRealBrowser(item.link, ".view", conn))); let htmlList = []; if (conn) try { for (const job of jobs) { const html = await job; htmlList.push(html); } } finally { await conn.browser.close(); conn = null; } else htmlList = await Promise.all(jobs); const newDescription = htmlList.map((html) => { if (!html) return ""; const $ = load(html); if ($(".video_img").length > 0) return `<video src="${$(".video_img a").attr("href")}" poster="${$(".video_img img").attr("data-src")}"></video><br />${$(".sum_full").text()}`; else { let description = ""; for (const pic of $(".pic img").toArray()) { const dataSrc = $(pic).attr("data-src"); if (dataSrc) description += `<img src="${dataSrc}" /><br />`; } description += $(".sum_full").text(); return description; } }); return { title: `${$("h1.fullname").text()} (@${id}) ${type === "tagged" ? "tagged" : "public"} posts - Picnob`, description: $(".info .sum").text(), link: profileUrl, image: $(".ava .pic img").attr("src"), item: list.map((item, index) => ({ ...item, description: newDescription[index] || item.description })) }; } //#endregion export { route };