rsshub
Version:
Make RSS Great Again!
152 lines (150 loc) • 5.33 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { r as getSubPath } from "./common-utils-vrWQFAEk.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as config_not_found_default } from "./config-not-found-Dyp3RlZZ.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/javbus/index.ts
init_esm_shims();
const toSize = (raw) => {
const matches = raw.match(/(\d+(\.\d+)?)(\w+)/);
return matches[3] === "GB" ? matches[1] * 1024 : matches[1];
};
const allowDomain = new Set([
"javbus.com",
"javbus.org",
"javsee.icu",
"javsee.one"
]);
const route = {
path: "/:path{.+}?",
radar: [{
source: ["www.javbus.com/:path*"],
target: "/:path"
}],
name: "Works",
maintainers: [
"MegrezZhu",
"CoderTonyChan",
"nczitzk",
"Felix2yu"
],
categories: ["multimedia"],
view: ViewType.Videos,
handler,
url: "www.javbus.com",
example: "/javbus/star/rwt",
parameters: { path: { description: "Any path of list page on javbus" } },
features: { nsfw: true }
};
async function handler(ctx) {
const isWestern = /^\/western/.test(getSubPath(ctx));
const domain = ctx.req.query("domain") ?? "javbus.com";
const westernDomain = ctx.req.query("western_domain") ?? "javbus.org";
const rootUrl = `https://www.${domain}`;
const westernUrl = `https://www.${westernDomain}`;
if (!config.feature.allow_user_supply_unsafe_domain && (!allowDomain.has(new URL(`https://${domain}/`).hostname) || !allowDomain.has(new URL(`https://${westernDomain}/`).hostname))) throw new config_not_found_default(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`);
const currentUrl = `${isWestern ? westernUrl : rootUrl}${getSubPath(ctx).replace(/^\/western/, "").replace(/\/home/, "")}`;
const headers = { "accept-language": "zh-CN" };
const $ = load((await got_default({
method: "get",
url: currentUrl,
headers
})).data);
let items = $(".movie-box").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 50).toArray().map((item) => {
item = $(item);
return {
link: item.attr("href"),
guid: item.find("date").first().text(),
pubDate: parseDate(item.find("date").last().text())
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const detailResponse = await got_default({
method: "get",
url: item.link,
headers
});
const content = load(detailResponse.data);
content(".genre").last().parent().remove();
content("input[type=\"checkbox\"], button").remove();
const stars = content(".avatar-box span").toArray().map((s) => content(s).text());
const cacheIn = {
author: stars.join(", "),
title: content("h3").text(),
category: [...content(".genre label").toArray().map((c) => content(c).text()), ...stars],
info: content(".row.movie").html(),
thumbs: content(".sample-box").toArray().map((i) => {
const thumbSrc = content(i).attr("href");
return thumbSrc.startsWith("http") ? thumbSrc : `${rootUrl}${thumbSrc}`;
})
};
let magnets, videoSrc, videoPreview;
try {
const matches = detailResponse.data.match(/var gid = (\d+);[\S\s]*var uc = (\d+);[\S\s]*var img = '(.*)';/);
const content$1 = load(`<table>${(await got_default({
method: "get",
url: `${rootUrl}/ajax/uncledatoolsbyajax.php`,
searchParams: {
gid: matches[1],
lang: "zh",
img: matches[3],
uc: matches[2],
floor: 800
},
headers: { Referer: item.link }
})).data}</table>`);
magnets = content$1("tr").toArray().map((tr) => {
const td = content$1(tr).find("a[href]");
return {
title: td.first().text().trim(),
link: td.first().attr("href"),
size: td.eq(1).text().trim(),
date: td.last().text().trim(),
score: content$1(tr).find("a").length ** 8 * toSize(td.eq(1).text().trim())
};
});
if (magnets) {
item.enclosure_url = magnets.toSorted((a, b) => b.score - a.score)[0].link;
item.enclosure_type = "application/x-bittorrent";
}
} catch {}
if (!isWestern) try {
const avgleResponse = await got_default({
method: "get",
url: `https://api.avgle.com/v1/jav/${item.guid}/0`
});
videoSrc = avgleResponse.data.response.videos[0]?.embedded_url ?? "";
videoPreview = avgleResponse.data.response.videos[0]?.preview_video_url ?? "";
} catch {}
item.author = cacheIn.author;
item.title = cacheIn.title;
item.category = cacheIn.category;
item.description = art(path.join(__dirname, "templates/description-a817012c.art"), {
info: cacheIn.info,
thumbs: cacheIn.thumbs,
magnets,
videoSrc,
videoPreview
});
return item;
})));
const title = $("head title").text();
return {
title: `${title.startsWith("JavBus") ? "" : "JavBus - "}${title.replace(/ - AV磁力連結分享/, "")}`,
link: currentUrl,
item: items,
allowEmpty: true
};
}
//#endregion
export { route };