feat(route): add 央视网栏目 (#7937)
Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
parent
c3e0948297
commit
e3edc868f3
|
|
@ -1166,6 +1166,26 @@ category 对应的关键词有
|
|||
|
||||
</Route>
|
||||
|
||||
### 栏目
|
||||
|
||||
<Route author="nczitzk" example="/cctv/lm/xwzk" path="/cctv/lm/:id?" :paramsDesc="['栏目 id,可在对应栏目页 URL 中找到,默认为 `xwzk` 即 新闻周刊']">
|
||||
|
||||
| 焦点访谈 | 等着我 | 今日说法 | 开讲啦 |
|
||||
| -------- | ------ | -------- | ------ |
|
||||
| jdft | dzw | jrsf | kjl |
|
||||
|
||||
| 正大综艺 | 经济半小时 | 第一动画乐园 |
|
||||
| -------- | ---------- | ------------ |
|
||||
| zdzy | jjbxs | dydhly |
|
||||
|
||||
::: tip 提示
|
||||
|
||||
更多栏目请看 [这里](https://tv.cctv.com/lm)
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
### 新闻专题
|
||||
|
||||
<Route author="nczitzk" example="/cctv-special/315" path="/cctv-special/:id?" :paramsDesc="['专题 id,可在对应专题页 URL 中找到,默认为 `315` 即 3·15 晚会']">
|
||||
|
|
|
|||
|
|
@ -368,6 +368,7 @@ router.get('/mihoyo/bh2/:type', lazyloadRouteHandler('./routes/mihoyo/bh2'));
|
|||
router.get('/cctv/xwlb', lazyloadRouteHandler('./routes/cctv/xwlb'));
|
||||
|
||||
// 央视新闻
|
||||
router.get('/cctv/lm/:id?', require('./routes/cctv/lm'));
|
||||
router.get('/cctv/:category', lazyloadRouteHandler('./routes/cctv/category'));
|
||||
router.get('/cctv/photo/jx', lazyloadRouteHandler('./routes/cctv/jx'));
|
||||
router.get('/cctv-special/:id?', lazyloadRouteHandler('./routes/cctv/special'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
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 id = ctx.params.id || 'xwzk';
|
||||
|
||||
const rootUrl = 'https://tv.cctv.com';
|
||||
const apiRootUrl = 'https://api.cntv.cn';
|
||||
const vdnRootUrl = 'https://vdn.apps.cntv.cn';
|
||||
|
||||
const currentUrl = `${rootUrl}/lm/${id}/videoset`;
|
||||
|
||||
const titleResponse = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(titleResponse.data);
|
||||
|
||||
const topId = titleResponse.data.match(/(TOPC\d{16})/)[1];
|
||||
const apiUrl = `${apiRootUrl}/NewVideo/getVideoListByColumn?id=${topId}&n=20&sort=desc&p=1&mode=0&serviceId=tvcctv`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
});
|
||||
|
||||
const list = response.data.data.list.map((item) => ({
|
||||
url: item.url,
|
||||
guid: item.guid,
|
||||
image: item.image,
|
||||
title: item.title,
|
||||
pubDate: timezone(parseDate(item.time), +8),
|
||||
link: `${vdnRootUrl}/api/getHttpVideoInfo.do?pid=${item.guid}`,
|
||||
description: `<p>${item.brief.replace(/\r\n/g, '</p><p>')}</p>`,
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const data = detailResponse.data;
|
||||
|
||||
item.description += `<video src="${data.hls_url}" controls="controls" poster="${item.image}" width="100%"></video><br>`;
|
||||
|
||||
for (const c of data.video.chapters) {
|
||||
item.description += `<video src="${c.url}" controls="controls" poster="${c.image}" width="100%"></video><br>`;
|
||||
}
|
||||
|
||||
for (let i = 2; data.video[`chapters${i}`]; i++) {
|
||||
for (const c of data.video[`chapters${i}`]) {
|
||||
item.description += `<video src="${c.url}" controls="controls" poster="${c.image}" width="100%"></video><br>`;
|
||||
}
|
||||
}
|
||||
|
||||
item.link = item.url;
|
||||
|
||||
delete item.url;
|
||||
delete item.image;
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
description: $('meta[name=description]').attr('content'),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue