From 91775af1f471b3cfece79945ef44d622914b3a2d Mon Sep 17 00:00:00 2001 From: Jinkin Date: Thu, 13 Oct 2022 22:15:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=E8=9C=BB=E8=9C=93FM=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=92=AD=E5=AE=A2=E6=BA=90=20(#11061)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 为蜻蜓FM输出播客源 Signed-off-by: huyyi * Update time process impl Signed-off-by: huyyi * refactor: migrate to v2 Signed-off-by: huyyi --- docs/multimedia.md | 9 +++ lib/router.js | 2 +- lib/{routes => v2}/qingting/channel.js | 16 ++---- lib/v2/qingting/maintainer.js | 4 ++ lib/v2/qingting/podcast.js | 77 ++++++++++++++++++++++++++ lib/v2/qingting/radar.js | 19 +++++++ lib/v2/qingting/router.js | 4 ++ 7 files changed, 120 insertions(+), 11 deletions(-) rename lib/{routes => v2}/qingting/channel.js (76%) create mode 100644 lib/v2/qingting/maintainer.js create mode 100644 lib/v2/qingting/podcast.js create mode 100644 lib/v2/qingting/radar.js create mode 100644 lib/v2/qingting/router.js diff --git a/docs/multimedia.md b/docs/multimedia.md index 67d194b71..0b140903c 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -1469,6 +1469,15 @@ JavDB 有多个备用域名,本路由默认使用永久域名 +### 播客 + + + +获取的播放URL有效期只有1天,需要开启播客APP的自动下载功能。 + + + + ## 秋爸日字 ### 分类 diff --git a/lib/router.js b/lib/router.js index 5de116898..b11275943 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2747,7 +2747,7 @@ router.get('/qlwb/news', lazyloadRouteHandler('./routes/qlwb/news')); router.get('/qlwb/city/:city', lazyloadRouteHandler('./routes/qlwb/city')); // 蜻蜓FM -router.get('/qingting/channel/:id', lazyloadRouteHandler('./routes/qingting/channel')); +// router.get('/qingting/channel/:id', lazyloadRouteHandler('./routes/qingting/channel')); // 金色财经 router.get('/jinse/lives', lazyloadRouteHandler('./routes/jinse/lives')); diff --git a/lib/routes/qingting/channel.js b/lib/v2/qingting/channel.js similarity index 76% rename from lib/routes/qingting/channel.js rename to lib/v2/qingting/channel.js index fcb84f453..d7d48962b 100644 --- a/lib/routes/qingting/channel.js +++ b/lib/v2/qingting/channel.js @@ -1,22 +1,18 @@ const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const channelUrl = `https://i.qingting.fm/capi/v3/channel/${ctx.params.id}`; - let response = await got({ - method: 'get', - url: channelUrl, - }); + let response = await got(channelUrl); const title = response.data.data.title; const programUrl = `https://i.qingting.fm/capi/channel/${ctx.params.id}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`; - response = await got({ - method: 'get', - url: programUrl, - }); + response = await got(programUrl); const items = response.data.data.programs.map((item) => ({ title: item.title, link: `https://www.qingting.fm/channels/${ctx.params.id}/programs/${item.id}/`, - pubDate: new Date(item.update_time).toUTCString(), + pubDate: timezone(parseDate(item.update_time), +8), })); ctx.state.data = { @@ -25,7 +21,7 @@ module.exports = async (ctx) => { item: await Promise.all( items.map((item) => ctx.cache.tryGet(item.link, async () => { - response = await got({ method: 'get', url: item.link }); + response = await got(item.link); const data = JSON.parse(response.data.match(/},"program":(.*?),"plist":/)[1]); item.description = data.richtext; return item; diff --git a/lib/v2/qingting/maintainer.js b/lib/v2/qingting/maintainer.js new file mode 100644 index 000000000..fc3c33053 --- /dev/null +++ b/lib/v2/qingting/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/channel/:id': ['nczitzk'], + '/podcast/:id': ['RookieZoe', 'huyyi'], +}; diff --git a/lib/v2/qingting/podcast.js b/lib/v2/qingting/podcast.js new file mode 100644 index 000000000..ff395d06f --- /dev/null +++ b/lib/v2/qingting/podcast.js @@ -0,0 +1,77 @@ +const crypto = require('crypto'); +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const channelUrl = `https://i.qingting.fm/capi/v3/channel/${ctx.params.id}`; + let response = await got({ + method: 'get', + url: channelUrl, + headers: { + Referer: 'https://www.qingting.fm/', + }, + }); + const title = response.data.data.title; + const channel_img = response.data.data.thumbs['400_thumb']; + const authors = response.data.data.podcasters.map((author) => author.nick_name).join(','); + const desc = response.data.data.description; + const programUrl = `https://i.qingting.fm/capi/channel/${ctx.params.id}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`; + response = await got({ + method: 'get', + url: programUrl, + headers: { + Referer: 'https://www.qingting.fm/', + }, + }); + + const resultItems = await Promise.all( + response.data.data.programs.map((item) => + ctx.cache.tryGet(`qingting:podcast:${ctx.params.id}:${item.id}`, async () => { + const link = `https://www.qingting.fm/channels/${ctx.params.id}/programs/${item.id}/`; + + const path = `/audiostream/redirect/${ctx.params.id}/${item.id}?access_token=&device_id=MOBILESITE&qingting_id=&t=${new Date().getTime()}`; + const sign = crypto.createHmac('md5', 'fpMn12&38f_2e').update(path).digest('hex').toString(); + + const [detailRes, mediaRes] = await Promise.all([ + got({ + method: 'get', + url: link, + headers: { + Referer: 'https://www.qingting.fm/', + }, + }), + got({ + method: 'get', + url: `https://audio.qingting.fm${path}&sign=${sign}`, + headers: { + Referer: 'https://www.qingting.fm/', + }, + }), + ]); + + const detail = JSON.parse(detailRes.data.match(/},"program":(.*?),"plist":/)[1]); + + return { + title: item.title, + link, + itunes_item_image: item.cover, + itunes_duration: item.duration, + pubDate: timezone(parseDate(item.update_time), +8), + description: detail.richtext, + enclosure_url: mediaRes.url, + enclosure_type: 'audio/x-m4a', + }; + }) + ) + ); + + ctx.state.data = { + title: `${title} - 蜻蜓FM`, + description: desc, + itunes_author: authors, + image: channel_img, + link: `https://www.qingting.fm/channels/${ctx.params.id}`, + item: resultItems, + }; +}; diff --git a/lib/v2/qingting/radar.js b/lib/v2/qingting/radar.js new file mode 100644 index 000000000..40da6f98d --- /dev/null +++ b/lib/v2/qingting/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'qingting.fm': { + _name: '蜻蜓 FM', + '.': [ + { + title: '专辑', + docs: 'https://docs.rsshub.app/multimedia.html#qing-ting-fm', + source: '/channels/:id', + target: '/qingting/channels/:id', + }, + { + title: '播客', + docs: 'https://docs.rsshub.app/multimedia.html#qing-ting-fm', + source: '/channels/:id', + target: '/qingting/podcast/:id', + }, + ], + }, +}; diff --git a/lib/v2/qingting/router.js b/lib/v2/qingting/router.js new file mode 100644 index 000000000..ace2d8874 --- /dev/null +++ b/lib/v2/qingting/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/channel/:id', require('./channel')); + router.get('/podcast/:id', require('./podcast')); +};