UNPKG

rsshub

Version:
73 lines (71 loc) 2.35 kB
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 "./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/userplayrecords.ts init_esm_shims(); const headers = { cookie: config.ncm.cookies, Referer: "https://music.163.com/" }; function getItem(records) { if (!records || records.length === 0) return [{ title: "暂无听歌排行" }]; return records.map((record, index) => { const song = record.song; const artists_paintext = song.ar.map((a) => a.name).join("/"); const html = art(path.join(__dirname, "templates/userplayrecords-c3ae0a67.art"), { index, record, song }); return { title: `[${index + 1}] ${song.name} - ${artists_paintext}`, link: `http://music.163.com/song?id=${song.id}`, author: artists_paintext, description: html }; }); } const route = { path: "/music/user/playrecords/:uid/:type?", categories: ["multimedia"], example: "/163/music/user/playrecords/45441555/1", parameters: { uid: "用户 uid, 可在用户主页 URL 中找到", type: "排行榜类型,0所有时间(默认),1最近一周" }, features: { requireConfig: [{ name: "NCM_COOKIES", optional: true, description: "网易云音乐登陆后的 cookie 值,可在浏览器控制台通过`document.cookie`获取。" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "用户听歌排行", maintainers: ["alfredcai"], handler }; async function handler(ctx) { const uid = ctx.req.param("uid"); const type = Number.parseInt(ctx.req.param("type")) || 0; const response = await got_default(`https://music.163.com/api/v1/play/record?uid=${uid}&type=${type}`, { headers }); const records = type === 1 ? response.data.weekData : response.data.allData; return { title: `${type === 1 ? "听歌榜单(最近一周)" : "听歌榜单(所有时间}"} - ${uid}}`, link: `https://music.163.com/user/home?id=${uid}`, updated: response.headers.date, item: getItem(records) }; } //#endregion export { route };