UNPKG

rsshub

Version:
72 lines (70 loc) 2.34 kB
import "./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 { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/subhd/index.ts const config = { sub: { title: "字幕", category: "new" }, zu: { title: "字幕组", category: "14" }, newest: { category: "for backwards compatibility" } }; const route = { path: "/:type?/:category?", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const type = ctx.req.param("type") ?? "sub"; const category = ctx.req.param("category") ?? config[type].category; const rootUrl = "https://subhd.tv"; const currentUrl = `${rootUrl}/${type === "newest" ? "sub/new" : `${type}/${category}${type === "zu" ? "/l" : ""}`}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); $(".align-middle").each(function() { $(this).removeClass("link-dark"); }); let items = $(".link-dark").toArray().map((item) => { item = $(item); const pubDate = item.parent().parent().find(".align-text-top").last().text(); const today = `${(/* @__PURE__ */ new Date()).getFullYear()}-${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @__PURE__ */ new Date()).getDate()}`; return { link: `${rootUrl}${item.attr("href")}`, author: item.parent().parent().find(".text-dark").last().text(), pubDate: timezone(parseDate(pubDate.includes("-") ? pubDate : `${today} ${pubDate}`), 8), title: `${item.parent().parent().find(".align-middle").text()} ${item.text().replace(/ - SubHD/, "")}` }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); content(".rounded-circle").remove(); content(".view-text").last().remove(); item.description = content(".view-text").html() + content(".bg-white").first().html(); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };