rsshub
Version:
Make RSS Great Again!
82 lines (77 loc) • 2.97 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 { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
//#region lib/routes/radio/index.ts
init_esm_shims();
const route = {
path: "/:id",
categories: ["multimedia"],
example: "/radio/1552135",
parameters: { id: "专辑 id,可在对应专辑页面的 URL 中找到" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: true,
supportScihub: false
},
name: "节目",
maintainers: ["kt286", "nczitzk"],
handler,
description: `如果订阅 [共和国追梦人](http://www.radio.cn/pc-portal/sanji/detail.html?columnId=1552135),其 URL 为 \`https://www.radio.cn/pc-portal/sanji/detail.html?columnId=1552135\`,可以得到 \`columnId\` 为 \`1552135\`
所以对应路由为 [\`/radio/1552135\`](https://rsshub.app/radio/1552135)
::: tip
该路由仅适用于更新时间较早的电台节目,如 [共和国追梦人](http://www.radio.cn/pc-portal/sanji/detail.html?columnId=1552135)
与适用于 [专辑](#yun-ting-zhuan-ji) 路由的专辑其 \`columnId\` 长度相比,它们的 \`columnId\` 长度较短
:::`
};
async function handler(ctx) {
const id = ctx.req.param("id");
const size = ctx.req.query("limit") ?? "100";
const rootUrl = "https://www.radio.cn";
const apiUrl = `http://tacc.radio.cn/pcpages/odchannelpages?od_id=${id}&start=1&rows=${size}`;
const currentUrl = `${rootUrl}/pc-portal/sanji/detail.html?columnId=${id}`;
const response = await got_default({
method: "get",
url: apiUrl
});
if (/^\(.*\)$/.test(response.data)) response.data = JSON.parse(response.data.match(/^\((.*)\)$/)[1]);
const data = response.data.data;
const items = data.program.map((item) => {
const enclosure_url = item.streams[0].url;
const enclosure_type = `audio/${enclosure_url.match(/\.(\w+)$/)[1]}`;
return {
guid: item.id,
title: item.name,
link: item.streams[0].url,
description: art(path.join(__dirname, "templates/description-2b297c34.art"), {
description: item.description,
enclosure_url,
enclosure_type
}),
pubDate: parseDate(item.onlinetime),
enclosure_url,
enclosure_type,
itunes_duration: item.duration,
itunes_item_image: data.odchannel.imageUrl[0].url
};
});
return {
title: `云听 - ${data.odchannel.name}`,
link: currentUrl,
item: items,
image: data.odchannel.imageUrl[0].url,
itunes_author: data.odchannel.commissioningEditorName || data.odchannel.editorName || data.odchannel.source || "radio.cn",
description: data.odchannel.description || data.odchannel.sub_title || ""
};
}
//#endregion
export { route };