feat(route): add 中证网中证视频 (#14457)

This commit is contained in:
Ethan Shen 2024-02-15 02:26:37 +08:00 committed by GitHub
parent 718f036e9b
commit 6eef6cdcdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 121 additions and 0 deletions

View File

@ -1,4 +1,5 @@
module.exports = {
'/zzkx': ['nczitzk'],
'/video/:category?': ['nczitzk'],
'/:category?': ['nczitzk'],
};

View File

@ -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/直播汇',
},
],
},
};

View File

@ -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('./'));
};

70
lib/v2/cs/video.js Normal file
View File

@ -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,
};
};

View File

@ -993,3 +993,10 @@ TokenInsight also provides official RSS, you can take a look at [https://api.tok
| sylm/jsbd | yc/ipojz | yc/gsnjd |
</details>
</Route>
### 中证视频 {#zhong-zheng-wang-zhong-zheng-shi-pin}
<Route author="nczitzk" example="/cs/video/今日聚焦" path="/cs/video/:category?" paramsDesc={['分类,见下表,默认为今日聚焦']} radar="1">
| 今日聚焦 | 传闻求证 | 高端访谈 | 投教课堂 | 直播汇 |
| -------- | -------- | -------- | -------- | ------ |
</Route>