From e5484a75bd5169d48f7155c0ff1f4bbf9090d853 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Sun, 1 May 2022 06:13:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=BA=91=E5=90=AC=20(#966?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 云听 * fix typo * fix: wrong data --- docs/multimedia.md | 12 +++---- lib/router.js | 2 +- lib/v2/radio/index.js | 48 ++++++++++++++++++++++++++ lib/v2/radio/maintainer.js | 3 ++ lib/v2/radio/radar.js | 13 +++++++ lib/{routes => v2}/radio/radio.js | 0 lib/v2/radio/router.js | 3 ++ lib/v2/radio/templates/description.art | 5 +++ 8 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 lib/v2/radio/index.js create mode 100644 lib/v2/radio/maintainer.js create mode 100644 lib/v2/radio/radar.js rename lib/{routes => v2}/radio/radio.js (100%) create mode 100644 lib/v2/radio/router.js create mode 100644 lib/v2/radio/templates/description.art diff --git a/docs/multimedia.md b/docs/multimedia.md index c8c6ecbef..06f6b6dbb 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -1461,6 +1461,12 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性 +## 云听 + +### 电台节目 + + + ## 中国高清网 ### 电影 @@ -1471,12 +1477,6 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性 | -- | ------ | ----- | ---- | -- | ------ | | 留空 | bluray | 1080p | 720p | 3d | webdl | -## 中国广播 - -### 电台节目 - - - ## 注视影视 ### 更新通知 diff --git a/lib/router.js b/lib/router.js index 9db2721f0..16aecfab8 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1758,7 +1758,7 @@ router.get('/huodongxing/explore', lazyloadRouteHandler('./routes/hdx/explore')) // router.get('/flyertea/creditcard/:bank', lazyloadRouteHandler('./routes/flyert/creditcard')); // 中国广播 -router.get('/radio/:channelname/:name', lazyloadRouteHandler('./routes/radio/radio')); +// router.get('/radio/:channelname/:name', lazyloadRouteHandler('./routes/radio/radio')); // TOPYS // router.get('/topys/:category', lazyloadRouteHandler('./routes/topys/article')); diff --git a/lib/v2/radio/index.js b/lib/v2/radio/index.js new file mode 100644 index 000000000..9e6f6d43a --- /dev/null +++ b/lib/v2/radio/index.js @@ -0,0 +1,48 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const rootUrl = 'http://www.radio.cn'; + const currentUrl = `${rootUrl}/pc-portal/sanji/detail.html?columnId=${id}`; + + const apiRootUrl = 'http://tacc.radio.cn'; + const apiUrl = `${apiRootUrl}/pcpages/odchannelpages?od_id=${id}&start=1&rows=50`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + if (/^\(.*\)$/.test(response.data)) { + response.data = JSON.parse(response.data)[0]; + } + + const data = response.data.data; + + const items = data.program.map((item) => ({ + guid: item.id, + title: item.name, + link: item.streams[0].url, + description: `${item.description}${art(path.join(__dirname, 'templates/description.art'), { + streams: item.streams, + })}`, + pubDate: parseDate(item.onlinetime), + enclosure_url: item.streams[0].url, + enclosure_type: 'audio/x-m4a', + itunes_duration: item.duration, + itunes_item_image: data.odchannel.imageUrl[0].url, + })); + + ctx.state.data = { + 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 || '', + }; +}; diff --git a/lib/v2/radio/maintainer.js b/lib/v2/radio/maintainer.js new file mode 100644 index 000000000..fac8655d8 --- /dev/null +++ b/lib/v2/radio/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:id': ['kt286', 'nczitzk'], +}; diff --git a/lib/v2/radio/radar.js b/lib/v2/radio/radar.js new file mode 100644 index 000000000..fd7428fd9 --- /dev/null +++ b/lib/v2/radio/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'radio.cn': { + _name: '云听', + '.': [ + { + title: '电台节目', + docs: 'https://docs.rsshub.app/multimedia.html#yun-ting-dian-tai-jie-mu', + source: ['/pc-portal/sanji/detail.html', '/'], + target: (params, url) => `/radio/${new URL(url).searchParams.get('columnId')}`, + }, + ], + }, +}; diff --git a/lib/routes/radio/radio.js b/lib/v2/radio/radio.js similarity index 100% rename from lib/routes/radio/radio.js rename to lib/v2/radio/radio.js diff --git a/lib/v2/radio/router.js b/lib/v2/radio/router.js new file mode 100644 index 000000000..641c23df3 --- /dev/null +++ b/lib/v2/radio/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:id', require('./index')); +}; diff --git a/lib/v2/radio/templates/description.art b/lib/v2/radio/templates/description.art new file mode 100644 index 000000000..6325c012a --- /dev/null +++ b/lib/v2/radio/templates/description.art @@ -0,0 +1,5 @@ + \ No newline at end of file