rsshub
Version:
Make RSS Great Again!
132 lines (129 loc) • 4.88 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.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 timezone } from "./timezone-D8cuwzTY.mjs";
import path from "node:path";
import dayjs from "dayjs";
import { load } from "cheerio";
//#region lib/routes/dlsite/utils.ts
init_esm_shims();
const rootUrl = "https://www.dlsite.com";
const defaultFilters = {
show_type: 1,
show_layout: 1,
per_page: 100
};
const formatDate = (date, format) => dayjs(date).format(format);
const addFilters = (url, filters) => {
const keys = Object.keys(filters);
const filterStr = keys.map((k) => `/${k}/${filters[k]}`).join("");
const newUrl = url.replaceAll(new RegExp(String.raw`(/${keys.join(String.raw`/\w+|/`)}/\w+)`, "g"), "");
return `${newUrl}${/=/.test(newUrl) ? "" : "/="}${filterStr}`;
};
const getPubDate = (raw) => {
const dateMatches = raw.match(/(\d{4}).*(\d{2}).*(\d{2})/);
if (dateMatches) return parseDate(`${dateMatches[1]}-${dateMatches[2]}-${dateMatches[3]}`, "YYYY-MM-DD");
return parseDate(raw.split(":").pop().trim(), "MMM/DD/YYYY");
};
const getDetails = async (works) => {
return (await got_default({
method: "get",
url: `${rootUrl}/home-touch/product/info/ajax?product_id=${works}`
})).data;
};
const ProcessItems = async (ctx) => {
art.defaults.imports.formatDate = formatDate;
const subPath = getSubPath(ctx) === "/" ? "/home/new" : getSubPath(ctx);
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 100;
const currentUrl = `${rootUrl}${addFilters(subPath, defaultFilters)}`;
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
const works = $("dt.work_name").slice(0, limit);
const updatedDate = $(".work_update").length === 0 ? void 0 : getPubDate($(".work_update").text());
const details = await getDetails(works.toArray().map((item) => $(item).find("a").attr("href").match(/_id\/(.*?)\.html/)[1]).join(","));
const items = works.toArray().map((item) => {
item = $(item).parentsUntil("tbody, ul");
const a = item.find(".work_name a");
const title = a.text();
const link = a.attr("href");
const guid = link.match(/_id\/(.*?)\.html/)[1];
const description = item.find(".work_text").text();
const authors = item.find(".maker_name a").toArray().map((a$1) => ({
name: $(a$1).text(),
link: $(a$1).attr("href")
}));
let images = item.find("div[data-samples]").length === 0 ? [] : JSON.parse(item.find("div[data-samples]").attr("data-samples").replaceAll("'", "\"")).map((s) => s.thumb);
const workCategories = item.find(".work_category").find("a").toArray().map((i) => ({
text: $(i).text(),
link: $(i).attr("href")
}));
const workGenres = item.find(".work_genre").find("span[title]").toArray().map((i) => ({ text: $(i).text() }));
const searchTags = item.find(".search_tag").find("a").toArray().map((i) => ({
text: $(i).text(),
link: $(i).attr("href")
}));
const nameTags = item.find(".icon_wrap").find("span[title]").toArray().map((i) => ({ text: $(i).text() }));
const detail = details[guid];
const pubDate = timezone(parseDate(detail.regist_date), 9);
const discountRate = detail.discount_rate;
const discountEndDate = detail.discount_end_date ? timezone(parseDate(detail.discount_end_date, "MM/DD HH:mm"), 9) : void 0;
images = images.length === 0 ? [detail.work_image] : images;
return {
title: `${discountRate ? `${discountRate}% OFF
${` ${discountEndDate ? `${dayjs(discountEndDate).format("YYYY-MM-DD HH:mm")} まで` : ""}`}` : " "}${title}`,
link,
pubDate,
author: authors.map((a$1) => a$1.name).join(" / "),
category: [
...workCategories.map((i) => i.text),
...workGenres.map((i) => i.text),
...searchTags.map((i) => i.text),
...nameTags.map((i) => i.text)
],
guid: `dlsite-${guid}`,
description: art(path.join(__dirname, "templates/description-3ff6e827.art"), {
detail,
images,
authors,
discountRate,
discountEndDate,
updatedDate,
pubDate,
workCategories,
workGenres,
searchTags,
description
})
};
});
return {
title: $("title").text(),
description: $("meta[name=\"description\"]").attr("content"),
link: currentUrl,
item: items,
allowEmpty: true
};
};
//#endregion
//#region lib/routes/dlsite/z-index/index.ts
const route = {
path: "*",
name: "Unknown",
maintainers: [],
handler,
features: { nsfw: true }
};
async function handler(ctx) {
return await ProcessItems(ctx);
}
//#endregion
export { route };