From a9aa467093e31f53ee652ff3eef31a0a9ea396e6 Mon Sep 17 00:00:00 2001 From: marcosteam Date: Tue, 12 Aug 2025 20:29:04 +0800 Subject: [PATCH] feat(route/nio): add NIO Radio route (#19782) * feat(route/nio): add NIO Radio support * fix(nioradio): update pubDate to use onlineTime instead of updateTime refactor(namespace): remove unnecessary field * fix(nioradio): improve formatting and adjust podcast fetching parameters * fix(nioradio): convert podcast duration from milliseconds to seconds --- lib/routes/nio/namespace.ts | 9 +++++ lib/routes/nio/nioradio.ts | 75 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 lib/routes/nio/namespace.ts create mode 100644 lib/routes/nio/nioradio.ts diff --git a/lib/routes/nio/namespace.ts b/lib/routes/nio/namespace.ts new file mode 100644 index 000000000..eb40a7fcb --- /dev/null +++ b/lib/routes/nio/namespace.ts @@ -0,0 +1,9 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'NIO', + url: 'nio.com', + zh: { + name: '蔚来', + }, +}; diff --git a/lib/routes/nio/nioradio.ts b/lib/routes/nio/nioradio.ts new file mode 100644 index 000000000..f48bc57d1 --- /dev/null +++ b/lib/routes/nio/nioradio.ts @@ -0,0 +1,75 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; +import { URLSearchParams } from 'node:url'; + +export const route: Route = { + path: '/nioradio/:albumid', + categories: ['multimedia'], + description: ` +:::tip +**如何获取电台 ID?** +打开蔚来 APP 后,点击“此地”→“NIO Radio”,找到自己想要转换为播客的专辑,分享后在生成的链接中找到\`container_id=\`后方的数字即可。 +常见电台 ID: +| 电台名称 | 电台 ID | +| :------------ | :---- | +| 资讯充电站(早间版) | 5 | +| 资讯充电站(晚间版) | 23 | +| E 次元财经报 | 148 | +| 塞萌不塞车 | 661 | +| 乐行记 | 11 | +| Weekend Dance | 547 | +:::`, + example: '/nio/nioradio/5', + parameters: { albumid: '电台专辑 ID' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: true, + supportScihub: false, + }, + name: 'NIO Radio', + maintainers: ['marcosteam'], + handler: async (ctx) => { + const { albumid } = ctx.req.param(); + const req = new URLSearchParams({ + albumId: albumid, + sorttype: '2', + pagenum: '1', + pagesize: '10', + }).toString(); + const data = await ofetch('https://gateway-front-external.nio.com/moat/100914/v2/audio/list', { + method: 'POST', + body: req, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }); + + const podcasts = data.result.dataList; + const podcastName = podcasts[0].albumName; + const podcastImage = podcasts[0].albumPic; + + const items = podcasts.map((podcast) => ({ + title: podcast.audioName, + link: `https://app.nio.com/app/radio/share/?item_type=1&item_id=${String(podcast.audioId).slice(1)}&container_id=${albumid}`, + pubDate: parseDate(podcast.onlineTime), + description: podcast.albumDesc, + author: podcast.host.join(', '), + itunes_item_image: podcast.albumPic, + itunes_duration: podcast.duration / 1000, + enclosure_url: podcast.aacPlayUrl192, + enclosure_length: podcast.aacFileSize192, + enclosure_type: 'audio/x-m4a', + })); + return { + title: `NIO Radio - ${podcastName}`, + link: 'https://www.nio.com', + itunes_author: podcasts[0].host.join(', '), + image: podcastImage, + item: items, + }; + }, +};