From b86fd05d5aa0e2a707652ed8da5c480e3b1d78f0 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Thu, 10 Mar 2022 20:02:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=96=B0=E5=94=90?= =?UTF-8?q?=E4=BA=BA=E9=9B=BB=E8=A6=96=E5=8F=B0=20(#9292)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 新唐人電視台 * Update docs/traditional-media.md Co-authored-by: Tony * Update lib/v2/ntdtv/channel.js Co-authored-by: Tony Co-authored-by: Tony --- docs/traditional-media.md | 12 +++++++++++ lib/v2/ntdtv/channel.js | 44 ++++++++++++++++++++++++++++++++++++++ lib/v2/ntdtv/maintainer.js | 3 +++ lib/v2/ntdtv/radar.js | 13 +++++++++++ lib/v2/ntdtv/router.js | 3 +++ 5 files changed, 75 insertions(+) create mode 100644 lib/v2/ntdtv/channel.js create mode 100644 lib/v2/ntdtv/maintainer.js create mode 100644 lib/v2/ntdtv/radar.js create mode 100644 lib/v2/ntdtv/router.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index dda316069..0ffa3bf1f 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1456,6 +1456,18 @@ category 对应的关键词有 +## 新唐人电视台 + +### 频道 + + + +参数均可在官网获取,如: + +`https://www.ntdtv.com/b5/prog1201` 对应 `/ntdtv/b5/prog1201` + + + ## 信报财经新闻 ### 即时新闻 diff --git a/lib/v2/ntdtv/channel.js b/lib/v2/ntdtv/channel.js new file mode 100644 index 000000000..0aea69b6c --- /dev/null +++ b/lib/v2/ntdtv/channel.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const host = 'https://www.ntdtv.com'; + +module.exports = async (ctx) => { + const language = ctx.params.language; + const id = ctx.params.id; + const url = `${host}/${language}/${id}`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const title = $('h1.block_title').text(); + const list = $('div.list_wrapper > div') + .map((_, item) => ({ + title: $(item).find('div.title').text(), + link: $(item).find('div.title > a').attr('href'), + description: $(item).find('div.excerpt').text(), + })) + .get() + .filter((item) => item.link); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got.get(item.link); + const content = cheerio.load(detailResponse.data); + + item.description = content('div.post_content').html(); + item.pubDate = timezone(parseDate(content('div.time > span').text()), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `新唐人电视台 - ${title}`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/ntdtv/maintainer.js b/lib/v2/ntdtv/maintainer.js new file mode 100644 index 000000000..52d2f169d --- /dev/null +++ b/lib/v2/ntdtv/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:language/:id': ['Fatpandac'], +}; diff --git a/lib/v2/ntdtv/radar.js b/lib/v2/ntdtv/radar.js new file mode 100644 index 000000000..0ccd75e3c --- /dev/null +++ b/lib/v2/ntdtv/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'ntdtv.com': { + _name: '新唐人电视台', + www: [ + { + title: '频道', + docs: 'https://docs.rsshub.app/traditional-media.html#xin-tang-ren-dian-shi-tai', + source: '/:language/:id', + target: '/ntdtv/:language/:id', + }, + ], + }, +}; diff --git a/lib/v2/ntdtv/router.js b/lib/v2/ntdtv/router.js new file mode 100644 index 000000000..d7693882b --- /dev/null +++ b/lib/v2/ntdtv/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:language/:id', require('./channel')); +};