rsshub
Version:
Make RSS Great Again!
95 lines (93 loc) • 3.13 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./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 path from "node:path";
//#region lib/routes/163/music/djradio.ts
init_esm_shims();
const route = {
path: "/music/djradio/:id/:info?",
categories: ["multimedia"],
example: "/163/music/djradio/347317067",
parameters: {
id: "节目 id, 可在电台节目页 URL 中找到",
info: "默认在正文尾部显示节目相关信息,任意值为不显示"
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: true,
supportScihub: false
},
name: "电台节目",
maintainers: ["magic-akari"],
handler
};
const ProcessFeed = (id, limit, offset) => cache_default.tryGet(`163:music:djradio:${id}:${limit}:${offset}`, async () => await got_default.post("https://music.163.com/api/dj/program/byradio", {
headers: { Referer: "https://music.163.com/" },
form: {
radioId: id,
limit,
offset
}
}), config.cache.routeExpire, false);
async function handler(ctx) {
const id = ctx.req.param("id");
const info = !ctx.req.param("info");
const response = await ProcessFeed(id, 1, 0);
const { radio, dj } = (response.data.programs || [])[0] || {
radio: {},
dj: {}
};
const count = response.data.count || 0;
const countPage = Array.from({ length: Math.ceil(count / 500) }, (_, i) => i);
const items = await Promise.all(countPage.map(async (item) => {
return ((await ProcessFeed(id, 500, item * 500)).data.programs || []).map((pg) => {
const description = (pg.description || "").split("\n").map((p) => p);
const duration = Math.trunc(pg.duration / 1e3);
const mm_ss_duration = `${(duration / 60).toFixed(0).padStart(2, "0")}:${(duration % 60).toFixed(0).padStart(2, "0")}`;
const html = art(path.join(__dirname, "templates/djradio-content-def0dea8.art"), {
pg,
description,
itunes_duration: mm_ss_duration,
info
});
return {
title: pg.name,
link: "https://music.163.com/program/" + pg.id,
pubDate: parseDate(pg.createTime),
published: parseDate(pg.createTime),
author: pg.dj.nickname,
description: html,
content: { html },
itunes_item_image: pg.coverUrl,
enclosure_url: `https://music.163.com/song/media/outer/url?id=${pg.mainTrackId}.mp3`,
enclosure_type: "audio/mpeg",
itunes_duration: duration
};
});
}));
return {
title: radio.name,
link: `https://music.163.com/djradio?id=${id}`,
subtitle: radio.desc,
description: radio.desc,
author: dj.nickname,
updated: radio.lastProgramCreateTime,
icon: radio.picUrl,
image: radio.picUrl,
itunes_author: dj.nickname,
itunes_category: radio.category,
item: items.flat()
};
}
//#endregion
export { route };