rsshub
Version:
Make RSS Great Again!
75 lines (73 loc) • 2.31 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 cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
import { load } from "cheerio";
import iconv from "iconv-lite";
//#region lib/routes/cartoonmad/comic.ts
init_esm_shims();
const baseUrl = "https://www.cartoonmad.com";
const KEY = "5e585";
const loadContent = (id, { chapter, pages }) => {
let description = "";
for (let page = 1; page <= pages; page++) {
const url = `${baseUrl}/${KEY}/${id}/${chapter}/${String(page).padStart(3, "0")}.jpg`;
description += art(path.join(__dirname, "templates/chapter-d81f608f.art"), { url });
}
return description;
};
const getChapters = (id, list, tryGet) => Promise.all(list.map((item) => tryGet(item.link, () => {
item.description = loadContent(id, item);
return item;
})));
const route = {
path: "/comic/:id",
categories: ["anime"],
example: "/cartoonmad/comic/5827",
parameters: { id: "漫画ID" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["cartoonmad.com/comic/:id"] }],
name: "漫画更新",
maintainers: ["KellyHwong"],
handler
};
async function handler(ctx) {
const id = ctx.req.param("id");
const link = `${baseUrl}/comic/${id}`;
const { data } = await got_default(link, {
responseType: "buffer",
headers: { Referer: "https://www.cartoonmad.com/" }
});
const $ = load(iconv.decode(data, "big5"));
const bookIntro = $("#info").eq(0).find("td").text().trim();
const chapters = await getChapters(id, $("#info").eq(1).find("a").toArray().map((item) => {
item = $(item);
return {
title: item.text(),
link: `${baseUrl}${item.attr("href")}`,
chapter: item.text().match(/\d+/)[0],
pages: item.next("font").text().match(/\d+/)[0]
};
}).toReversed(), cache_default.tryGet);
return {
title: $("head title").text(),
link,
description: bookIntro,
item: chapters
};
}
//#endregion
export { route };