rsshub
Version:
Make RSS Great Again!
145 lines (143 loc) • 4.7 kB
JavaScript
import { t as config } from "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./logger-Czu8UMNd.mjs";
import { n as parseRelativeDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.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$1 = await job;
htmlList.push(html$1);
}
} finally {
await conn.browser.close();
conn = null;
}
else htmlList = await Promise.all(jobs);
const newDescription = htmlList.map((html$1) => {
if (!html$1) return "";
const $$1 = load(html$1);
if ($$1(".video_img").length > 0) return `<video src="${$$1(".video_img a").attr("href")}" poster="${$$1(".video_img img").attr("data-src")}"></video><br />${$$1(".sum_full").text()}`;
else {
let description = "";
for (const pic of $$1(".pic img").toArray()) {
const dataSrc = $$1(pic).attr("data-src");
if (dataSrc) description += `<img src="${dataSrc}" /><br />`;
}
description += $$1(".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 };