diff --git a/lib/v2/cs/maintainer.js b/lib/v2/cs/maintainer.js index 066baab97..f2590aca1 100644 --- a/lib/v2/cs/maintainer.js +++ b/lib/v2/cs/maintainer.js @@ -1,4 +1,5 @@ module.exports = { '/zzkx': ['nczitzk'], + '/video/:category?': ['nczitzk'], '/:category?': ['nczitzk'], }; diff --git a/lib/v2/cs/radar.js b/lib/v2/cs/radar.js index 5467b450f..b4d4769ff 100644 --- a/lib/v2/cs/radar.js +++ b/lib/v2/cs/radar.js @@ -183,5 +183,47 @@ module.exports = { target: '/cs/yc/gsnjd', }, ], + video: [ + { + title: '中证视频', + docs: 'https://docs.rsshub.app/routes/finance#zhong-zheng-wang-zhong-zheng-shi-pin', + source: ['list.html'], + target: (_, url) => { + const category = url.searchParams.get('title') || url.searchParams.get('id'); + + return `/cs/video${category ? `/${category}` : ''}`; + }, + }, + { + title: '今日聚焦', + docs: 'https://docs.rsshub.app/routes/finance#zhong-zheng-wang-zhong-zheng-shi-pin', + source: ['list.html'], + target: '/cs/video/今日聚焦', + }, + { + title: '传闻求证', + docs: 'https://docs.rsshub.app/routes/finance#zhong-zheng-wang-zhong-zheng-shi-pin', + source: ['list.html'], + target: '/cs/video/传闻求证', + }, + { + title: '高端访谈', + docs: 'https://docs.rsshub.app/routes/finance#zhong-zheng-wang-zhong-zheng-shi-pin', + source: ['list.html'], + target: '/cs/video/高端访谈', + }, + { + title: '投教课堂', + docs: 'https://docs.rsshub.app/routes/finance#zhong-zheng-wang-zhong-zheng-shi-pin', + source: ['list.html'], + target: '/cs/video/投教课堂', + }, + { + title: '直播汇', + docs: 'https://docs.rsshub.app/routes/finance#zhong-zheng-wang-zhong-zheng-shi-pin', + source: ['list.html'], + target: '/cs/video/直播汇', + }, + ], }, }; diff --git a/lib/v2/cs/router.js b/lib/v2/cs/router.js index fb1aa85c8..484a9bf41 100644 --- a/lib/v2/cs/router.js +++ b/lib/v2/cs/router.js @@ -8,5 +8,6 @@ const toZzkx = (ctx) => { module.exports = (router) => { router.get('/news/zzkx', toZzkx); router.get('/zzkx', toZzkx); + router.get('/video/:category?', require('./video')); router.get('/:category*', require('./')); }; diff --git a/lib/v2/cs/video.js b/lib/v2/cs/video.js new file mode 100644 index 000000000..967db7add --- /dev/null +++ b/lib/v2/cs/video.js @@ -0,0 +1,70 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { category = '今日聚焦' } = ctx.params; + const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 50; + + const rootUrl = 'https://video.cs.com.cn'; + const apiCategoryUrl = new URL('web/api/getCategory', rootUrl).href; + const apiUrl = new URL('web/api/toSecondPage', rootUrl).href; + + const { + data: { data: categoryResponse }, + } = await got.post(apiCategoryUrl); + + const categories = categoryResponse.map((c) => ({ + id: c.id, + title: c.categoryTitle, + image: c.categoryImg, + sortType: c.categorySortType, + })); + + const selected = categories.find((c) => c.title === category || c.id === category); + + const currentUrl = new URL(`list.html?title=${selected.title}&id=${selected.id}`, rootUrl).href; + + const { + data: { records: response }, + } = await got.post(apiUrl, { + json: { + categorySortType: selected.sortType, + id: selected.id, + pageNum: 1, + pageSize: limit, + }, + }); + + const items = response.slice(0, limit).map((item) => ({ + title: item.contentTitle, + link: new URL(item.contentUrl, rootUrl).href, + description: item.contentDetails, + author: item.contentSource, + pubDate: timezone(parseDate(item.contentDatetime), +8), + updated: timezone(parseDate(item.updateDate), +8), + })); + + const { data: currentResponse } = await got(currentUrl); + + const $ = cheerio.load(currentResponse); + + const title = $('title').text(); + const image = selected.image; + const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; + + ctx.state.data = { + item: items, + title: `${title} | ${selected.title}`, + link: currentUrl, + description: $('meta[name="Description"]').prop('content'), + language: $('html').prop('lang'), + image, + icon, + logo: icon, + subtitle: $('meta[name="Keywords"]').prop('content'), + author: title.split('-').pop().trim(), + allowEmpty: true, + }; +}; diff --git a/website/docs/routes/finance.mdx b/website/docs/routes/finance.mdx index c45056eba..49de89011 100644 --- a/website/docs/routes/finance.mdx +++ b/website/docs/routes/finance.mdx @@ -993,3 +993,10 @@ TokenInsight also provides official RSS, you can take a look at [https://api.tok | sylm/jsbd | yc/ipojz | yc/gsnjd | + +### 中证视频 {#zhong-zheng-wang-zhong-zheng-shi-pin} + + + | 今日聚焦 | 传闻求证 | 高端访谈 | 投教课堂 | 直播汇 | + | -------- | -------- | -------- | -------- | ------ | +