rsshub
Version:
Make RSS Great Again!
104 lines (102 loc) • 3.95 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 { 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 { t as timezone } from "./timezone-D8cuwzTY.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/hebtv/nong-bo-shi-zai-xing-dong.ts
init_esm_shims();
const baseUrl = "https://web.cmc.hebtv.com/cms/rmt0336/19/19js/st/ds/nmpd/nbszxd/index.shtml";
const route = {
path: "/nbszxd",
categories: ["traditional-media"],
example: "/hebtv/nbszxd",
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: true,
supportPodcast: true,
supportScihub: false
},
radar: [{ source: ["web.cmc.hebtv.com/cms/rmt0336/19/19js/st/ds/nmpd/nbszxd/index.shtml"] }],
name: "农博士在行动",
maintainers: ["iamqiz", "nczitzk"],
handler,
url: "web.cmc.hebtv.com/cms/rmt0336/19/19js/st/ds/nmpd/nbszxd/index.shtml"
};
async function handler(ctx) {
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 40;
const apiUrl = new URL("cmsback/api/article/getMyArticleDetail", "http://api.cmc.hebtv.com").href;
const $ = load((await got_default(baseUrl)).data);
const list = $(".video_box .tv_items").first().children().toArray().map((item) => {
item = $(item);
const a = item.find("a").first();
const timeMatch = a.text().match(/\d+/);
const timestr = timeMatch ? timeMatch[0] : "";
return {
title: a.text(),
link: `${baseUrl}/../${a.attr("href")}`,
pubDate: timestr ? timezone(parseDate(timestr, "YYYYMMDD"), 8) : null,
author: "时间|" + timestr
};
});
const items = await Promise.all(list.slice(0, limit).map((item) => cache_default.tryGet(item.link, async () => {
const { data: detailResponse } = await got_default(item.link);
const tenantId = detailResponse.match(/tenantid = '(\w+)';/)[1];
const articleId = item.link.match(/\/nbszxd\/(\d+)/)[1];
const { data: apiResponse } = await got_default(apiUrl, { searchParams: {
tenantId,
articleId
} });
const data = apiResponse.data;
let videoData;
if (data.articleContentDto?.videoDtoList?.length > 0) videoData = data.articleContentDto?.videoDtoList[0];
item.title = data.title;
item.author = data.source;
item.guid = `hebtv-nbszxd-${articleId}`;
item.pubDate = timezone(parseDate(data.publishDate), 8);
item.updated = timezone(parseDate(data.modifyTime), 8);
if (videoData) {
item.itunes_item_image = videoData.poster;
item.itunes_duration = data.articleContentDto?.videoEditDtoList[0]?.sourceMediaInfo?.duration;
item.enclosure_url = videoData.formats[0]?.url;
item.enclosure_length = data.articleContentDto?.videoEditDtoList[0].sourceMediaInfo?.fileSize;
item.enclosure_type = item.enclosure_url ? `video/${item.enclosure_url?.split(/\./)?.pop()}` : void 0;
}
item.description = art(path.join(__dirname, "templates/description-676d5a69.art"), { video: videoData ? {
src: item.enclosure_url,
type: item.enclosure_type,
poster: item.itunes_item_image
} : void 0 });
return item;
})));
const description = $("meta[name=\"description\"]").prop("content");
const author = description.split(/,/)[0];
const icon = $("link[rel=\"shortcut icon\"]").prop("href");
return {
item: items,
title: $("title").text(),
link: baseUrl,
description,
language: $("html").prop("lang"),
image: $("div.logo a img").prop("src"),
icon,
logo: icon,
subtitle: $("meta[name=\"keywords\"]").prop("content"),
author,
itunes_author: author,
itunes_category: "News",
allowEmpty: true
};
}
//#endregion
export { route };