From 69dcb7ec66b7edc72f0ebd15306197ea64d4dcb8 Mon Sep 17 00:00:00 2001 From: zxzhuty <706415203@qq.com> Date: Thu, 17 Feb 2022 08:36:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20audiobar.cn=20=E9=9F=B3?= =?UTF-8?q?=E9=A2=91=E5=BA=94=E7=94=A8=E8=AE=BA=E5=9D=9B=20(#9063)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add * add audiobar * add * add doc * use parseDate * fix * add v2 * remove old doc * Update docs/bbs.md Co-authored-by: Tony * Update lib/v2/audiobar/latest.js Co-authored-by: Tony * Update lib/v2/audiobar/maintainer.js Co-authored-by: Tony * Update lib/v2/audiobar/router.js Co-authored-by: Tony * fix doc * Update lib/v2/audiobar/radar.js Co-authored-by: Tony * fix: docs link Co-authored-by: zhuty Co-authored-by: Tony --- docs/bbs.md | 6 ++++ lib/v2/audiobar/latest.js | 53 +++++++++++++++++++++++++++++++++++ lib/v2/audiobar/maintainer.js | 3 ++ lib/v2/audiobar/radar.js | 13 +++++++++ lib/v2/audiobar/router.js | 3 ++ 5 files changed, 78 insertions(+) create mode 100644 lib/v2/audiobar/latest.js create mode 100644 lib/v2/audiobar/maintainer.js create mode 100644 lib/v2/audiobar/radar.js create mode 100644 lib/v2/audiobar/router.js diff --git a/docs/bbs.md b/docs/bbs.md index 2955d34c14..a2008d1394 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -895,3 +895,9 @@ pageClass: routes | lingyishijain | lingyitupian | minjianqitan | + +## 音频应用 + +### 最新主题 + + diff --git a/lib/v2/audiobar/latest.js b/lib/v2/audiobar/latest.js new file mode 100644 index 0000000000..cde096afc1 --- /dev/null +++ b/lib/v2/audiobar/latest.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const rootUrl = 'http://www.audiobar.cn/'; + +module.exports = async (ctx) => { + const currentUrl = `${rootUrl}/all.php`; + + const response = await got({ + method: 'get', + url: currentUrl, + responseType: 'buffer', + }); + const data = iconv.decode(response.data, 'gb2312'); + const $ = cheerio.load(data); + + const list = $('.thread_every_container_div') + .map((_, item) => { + item = $(item); + + const link = item.find('.thread_subject').attr('href'); + const dateStr = item.find('.atrd_span').text().slice(-26).replace(' ', ''); + return { + title: item.find('.thread_subject').text().replace('\n', '').replace(' ', ''), + link: link.indexOf('http') > -1 ? link : `${rootUrl}${link}`, + pubDate: timezone(parseDate(dateStr, 'YY-M-D HH:mm'), +8), + }; + }) + .get(); + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + responseType: 'buffer', + }); + const detailResponsedata = iconv.decode(detailResponse.data, 'gb2312'); + const content = cheerio.load(detailResponsedata); + item.description = content('.zhengwen_div').text().replace('Your browser does not support HTML5, please change another browser.', ''); + return item; + }) + ) + ); + ctx.state.data = { + title: '音频应用-最新主题', + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/audiobar/maintainer.js b/lib/v2/audiobar/maintainer.js new file mode 100644 index 0000000000..2791d6cae4 --- /dev/null +++ b/lib/v2/audiobar/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/latest': ['zxzhuty'], +}; diff --git a/lib/v2/audiobar/radar.js b/lib/v2/audiobar/radar.js new file mode 100644 index 0000000000..229d27c653 --- /dev/null +++ b/lib/v2/audiobar/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'audiobar.cn': { + _name: '音频应用', + '.': [ + { + title: '最新主题', + docs: 'https://docs.rsshub.app/bbs.html#yin-pin-ying-yong', + source: ['/all.php'], + target: '/audiobar/latest', + }, + ], + }, +}; diff --git a/lib/v2/audiobar/router.js b/lib/v2/audiobar/router.js new file mode 100644 index 0000000000..c7599855e1 --- /dev/null +++ b/lib/v2/audiobar/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/latest', require('./latest')); +};