UNPKG

rsshub

Version:
69 lines (68 loc) 2.5 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { r as getSubPath } from "./common-utils-DtQojudb.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { t as timezone } from "./timezone-BBvDwS_3.mjs"; import { load } from "cheerio"; //#region lib/routes/subhd/index.ts const defaultCategories = { sub: "new", zu: "14" }; const route = { path: "/sub/:category?", categories: ["multimedia"], example: "/subhd/sub/new", parameters: { category: "分类,见下表,默认为最新" }, radar: [{ source: ["subhd.tv/sub/:category", "subhd.tv/"], target: "/sub/:category?" }], name: "字幕", description: `| 最新字幕 | 热门字幕 | 剧集字幕 | 电影字幕 | | -------- | -------- | -------- | -------- | | new | top | tv | movie |`, maintainers: ["laampui", "nczitzk"], handler }; async function handler(ctx) { const type = getSubPath(ctx).split("/", 2)[1]; const category = ctx.req.param("category") ?? defaultCategories[type]; const rootUrl = "https://subhd.tv"; const currentUrl = `${rootUrl}/${type}/${category}${type === "zu" ? "/l" : ""}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); $(".align-middle").each((_, el) => { $(el).removeClass("link-dark"); }); let items = $(".link-dark").toArray().map((item) => { const $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 as n, handler as t };