From 050e72b67cc4ff9bc7324db36be155b4ba880673 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 20 Feb 2022 15:03:54 -0400 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=99=E6=92=AD=E5=AE=A2=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20(#9160)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加小宇宙播客支持 * refactor: migrate to v2 Co-authored-by: maijver Co-authored-by: maijver --- docs/multimedia.md | 4 +++ lib/router.js | 5 ++-- lib/v2/xiaoyuzhou/maintainer.js | 4 +++ lib/{routes => v2}/xiaoyuzhou/pickup.js | 0 lib/v2/xiaoyuzhou/podcast.js | 36 +++++++++++++++++++++++++ lib/v2/xiaoyuzhou/radar.js | 19 +++++++++++++ lib/v2/xiaoyuzhou/router.js | 4 +++ 7 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 lib/v2/xiaoyuzhou/maintainer.js rename lib/{routes => v2}/xiaoyuzhou/pickup.js (100%) create mode 100644 lib/v2/xiaoyuzhou/podcast.js create mode 100644 lib/v2/xiaoyuzhou/radar.js create mode 100644 lib/v2/xiaoyuzhou/router.js diff --git a/docs/multimedia.md b/docs/multimedia.md index 89eac44e78..c0710fdced 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -1389,6 +1389,10 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性 +### 播客 + + + ## 优酷 ### 频道 diff --git a/lib/router.js b/lib/router.js index 0345a7a276..215e334d61 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3128,8 +3128,9 @@ router.get('/manxiaosi/book/:id', lazyloadRouteHandler('./routes/manxiaosi/book' // 吉林大学校内通知 router.get('/jlu/oa', lazyloadRouteHandler('./routes/universities/jlu/oa')); -// 小宇宙 -router.get('/xiaoyuzhou', lazyloadRouteHandler('./routes/xiaoyuzhou/pickup')); +// 小宇宙 migrated to v2 +// router.get('/xiaoyuzhou', lazyloadRouteHandler('./routes/xiaoyuzhou/pickup')); +// router.get('/xiaoyuzhou/podcast/:id', lazyloadRouteHandler('./routes/xiaoyuzhou/podcast')); // 合肥工业大学 router.get('/hfut/tzgg', lazyloadRouteHandler('./routes/universities/hfut/tzgg')); diff --git a/lib/v2/xiaoyuzhou/maintainer.js b/lib/v2/xiaoyuzhou/maintainer.js new file mode 100644 index 0000000000..29f8a385e2 --- /dev/null +++ b/lib/v2/xiaoyuzhou/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/': ['prnake', 'Maecenas'], + '/podcast/:id': ['hondajojo'], +}; diff --git a/lib/routes/xiaoyuzhou/pickup.js b/lib/v2/xiaoyuzhou/pickup.js similarity index 100% rename from lib/routes/xiaoyuzhou/pickup.js rename to lib/v2/xiaoyuzhou/pickup.js diff --git a/lib/v2/xiaoyuzhou/podcast.js b/lib/v2/xiaoyuzhou/podcast.js new file mode 100644 index 0000000000..a7c24b3a72 --- /dev/null +++ b/lib/v2/xiaoyuzhou/podcast.js @@ -0,0 +1,36 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const link = `https://www.xiaoyuzhoufm.com/podcast/${ctx.params.id}`; + const response = await got({ + method: 'get', + url: link, + }); + + const $ = cheerio.load(response.data); + + const page_data = JSON.parse($('#__NEXT_DATA__')[0].children[0].data); + + const episodes = page_data.props.pageProps.podcast.episodes.map((item) => ({ + title: item.title, + enclosure_url: item.enclosure.url, + enclosure_length: item.duration, + enclosure_type: 'audio/mpeg', + link: `https://www.xiaoyuzhoufm.com/episode/${item.eid}`, + pubDate: parseDate(item.pubDate), + description: item.shownotes, + itunes_item_image: item.image.smallPicUrl, + })); + + ctx.state.data = { + title: page_data.props.pageProps.podcast.title, + link: `https://www.xiaoyuzhoufm.com/podcast/${page_data.props.pageProps.podcast.pid}`, + itunes_author: page_data.props.pageProps.podcast.author, + itunes_category: '', + image: page_data.props.pageProps.podcast.image.smallPicUrl, + item: episodes, + description: page_data.props.pageProps.podcast.description, + }; +}; diff --git a/lib/v2/xiaoyuzhou/radar.js b/lib/v2/xiaoyuzhou/radar.js new file mode 100644 index 0000000000..5462093ba8 --- /dev/null +++ b/lib/v2/xiaoyuzhou/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'xiaoyuzhoufm.com': { + _name: '小宇宙', + '.': [ + { + title: '发现', + docs: 'https://docs.rsshub.app/multimedia.html#xiao-yu-zhou', + source: ['/'], + target: '/xiaoyuzhou', + }, + { + title: '播客', + docs: 'https://docs.rsshub.app/multimedia.html#xiao-yu-zhou', + source: ['/podcast/:id'], + target: '/xiaoyuzhou/podcast/:id', + }, + ], + }, +}; diff --git a/lib/v2/xiaoyuzhou/router.js b/lib/v2/xiaoyuzhou/router.js new file mode 100644 index 0000000000..1e6fef5a64 --- /dev/null +++ b/lib/v2/xiaoyuzhou/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/podcast/:id', require('./podcast')); + router.get('/', require('./pickup')); +};