From 6742ef803a3021f1671aa60fc95f56018cd87e9d Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Fri, 12 May 2023 00:41:56 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=95=85=E4=BA=8BFM?=
=?UTF-8?q?=E6=92=AD=E5=AE=A2=20(#12494)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): add 故事FM播客
* fix: wrong url
---
docs/multimedia.md | 4 ++
lib/router.js | 2 +-
lib/v2/storyfm/episodes.js | 63 ++++++++++++++++++++++++
lib/{routes => v2}/storyfm/index.js | 0
lib/v2/storyfm/maintainer.js | 4 ++
lib/v2/storyfm/radar.js | 19 +++++++
lib/v2/storyfm/router.js | 4 ++
lib/v2/storyfm/templates/description.art | 6 +++
8 files changed, 101 insertions(+), 1 deletion(-)
create mode 100644 lib/v2/storyfm/episodes.js
rename lib/{routes => v2}/storyfm/index.js (100%)
create mode 100644 lib/v2/storyfm/maintainer.js
create mode 100644 lib/v2/storyfm/radar.js
create mode 100644 lib/v2/storyfm/router.js
create mode 100644 lib/v2/storyfm/templates/description.art
diff --git a/docs/multimedia.md b/docs/multimedia.md
index c58a5f8bf..610794d13 100644
--- a/docs/multimedia.md
+++ b/docs/multimedia.md
@@ -1493,6 +1493,10 @@ JavDB 有多个备用域名,本路由默认使用永久域名
+### 播客
+
+
+
## 开眼
### 每日精选
diff --git a/lib/router.js b/lib/router.js
index b226aca37..8e9922b64 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1925,7 +1925,7 @@ router.get('/ctfhub/search/:limit?/:form?/:class?/:title?', lazyloadRouteHandler
router.get('/liwushuo/index', lazyloadRouteHandler('./routes/liwushuo/index.js'));
// 故事fm
-router.get('/storyfm/index', lazyloadRouteHandler('./routes/storyfm/index.js'));
+// router.get('/storyfm/index', lazyloadRouteHandler('./routes/storyfm/index.js'));
// 中国日报
router.get('/chinadaily/english/:category', lazyloadRouteHandler('./routes/chinadaily/english.js'));
diff --git a/lib/v2/storyfm/episodes.js b/lib/v2/storyfm/episodes.js
new file mode 100644
index 000000000..4ac593158
--- /dev/null
+++ b/lib/v2/storyfm/episodes.js
@@ -0,0 +1,63 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+const { art } = require('@/utils/render');
+const path = require('path');
+
+module.exports = async (ctx) => {
+ const rootUrl = 'https://storyfm.cn';
+ const currentUrl = `${rootUrl}/episodes-list/`;
+
+ const response = await got({
+ method: 'get',
+ url: currentUrl,
+ });
+
+ const $ = cheerio.load(response.data);
+
+ let items = $('.e-ep')
+ .toArray()
+ .map((item) => {
+ item = $(item);
+
+ const a = item.find('h2.e-ep__title a');
+
+ return {
+ title: a.text(),
+ link: a.attr('href'),
+ pubDate: parseDate(item.find('.whitespace-nowrap').text()),
+ enclosure_type: 'audio/mpeg',
+ enclosure_url: item.find('audio source').attr('src'),
+ itunes_item_image: item.find('.zoom-image-container-progression img').attr('src'),
+ };
+ });
+
+ items = await Promise.all(
+ items.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const detailResponse = await got({
+ method: 'get',
+ url: item.link,
+ });
+
+ const content = cheerio.load(detailResponse.data);
+
+ item.author = content('.rs-post__author').text().replace(/By/, '').trim();
+ item.description = art(path.join(__dirname, 'templates/description.art'), {
+ audio: item.enclosure_url,
+ description: content('.rs-post__content').html(),
+ });
+
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: '故事FM',
+ link: currentUrl,
+ item: items,
+ itunes_author: '故事FM',
+ image: $('.custom-logo-link img').attr('src'),
+ };
+};
diff --git a/lib/routes/storyfm/index.js b/lib/v2/storyfm/index.js
similarity index 100%
rename from lib/routes/storyfm/index.js
rename to lib/v2/storyfm/index.js
diff --git a/lib/v2/storyfm/maintainer.js b/lib/v2/storyfm/maintainer.js
new file mode 100644
index 000000000..df7fe971d
--- /dev/null
+++ b/lib/v2/storyfm/maintainer.js
@@ -0,0 +1,4 @@
+module.exports = {
+ '/episodes': ['nczitzk'],
+ '/index': ['sanmmm'],
+};
diff --git a/lib/v2/storyfm/radar.js b/lib/v2/storyfm/radar.js
new file mode 100644
index 000000000..6247a30c9
--- /dev/null
+++ b/lib/v2/storyfm/radar.js
@@ -0,0 +1,19 @@
+module.exports = {
+ 'storyfm.cn': {
+ _name: '故事FM',
+ '.': [
+ {
+ title: '首页',
+ docs: 'https://docs.rsshub.app/multimedia.html#ge-shi-fm',
+ source: ['/'],
+ target: '/storyfm/index',
+ },
+ {
+ title: '播客',
+ docs: 'https://docs.rsshub.app/multimedia.html#ge-shi-fm',
+ source: ['/episodes-list', '/'],
+ target: '/storyfm/episodes',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/storyfm/router.js b/lib/v2/storyfm/router.js
new file mode 100644
index 000000000..4170971fb
--- /dev/null
+++ b/lib/v2/storyfm/router.js
@@ -0,0 +1,4 @@
+module.exports = function (router) {
+ router.get('/episodes', require('./episodes'));
+ router.get('/index', require('./index'));
+};
diff --git a/lib/v2/storyfm/templates/description.art b/lib/v2/storyfm/templates/description.art
new file mode 100644
index 000000000..d95f4e1fa
--- /dev/null
+++ b/lib/v2/storyfm/templates/description.art
@@ -0,0 +1,6 @@
+{{ if audio }}
+
+{{ /if }}
+{{@ description }}
\ No newline at end of file