feat(route): 河北网络广播电视台农博士在行动视频 (#13694)
* feat(route): 河北网络广播电视台农博士在行动视频 * fix null checks
This commit is contained in:
parent
70dc17d356
commit
edf256d98b
|
|
@ -1,3 +1,3 @@
|
|||
module.exports = {
|
||||
'/nbszxd': ['iamqiz'],
|
||||
'/nbszxd': ['iamqiz', 'nczitzk'],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,11 +2,17 @@ const got = require('@/utils/got');
|
|||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
const baseUrl = 'https://web.cmc.hebtv.com/cms/rmt0336/19/19js/st/ds/nmpd/nbszxd/index.shtml';
|
||||
const sizeTitle = '农博士在行动-河北广播电视台';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 40;
|
||||
|
||||
const apiRootUrl = 'http://api.cmc.hebtv.com';
|
||||
const apiUrl = new URL('cmsback/api/article/getMyArticleDetail', apiRootUrl).href;
|
||||
|
||||
const response = await got(baseUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
|
|
@ -30,10 +36,74 @@ module.exports = async (ctx) => {
|
|||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.slice(0, limit).map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: detailResponse } = await got(item.link);
|
||||
|
||||
const tenantId = detailResponse.match(/tenantid = '(\w+)';/)[1];
|
||||
const articleId = item.link.match(/\/nbszxd\/(\d+)/)[1];
|
||||
|
||||
const { data: apiResponse } = await got(apiUrl, {
|
||||
searchParams: {
|
||||
tenantId,
|
||||
articleId,
|
||||
},
|
||||
});
|
||||
|
||||
const data = apiResponse.data;
|
||||
|
||||
let videoData;
|
||||
if (data.articleContentDto?.videoDtoList?.length > 0) {
|
||||
videoData = data.articleContentDto?.videoDtoList[0];
|
||||
}
|
||||
|
||||
item.title = data.title;
|
||||
item.author = data.source;
|
||||
item.guid = `hebtv-nbszxd-${articleId}`;
|
||||
item.pubDate = timezone(parseDate(data.publishDate), +8);
|
||||
item.updated = timezone(parseDate(data.modifyTime), +8);
|
||||
|
||||
if (videoData) {
|
||||
item.itunes_item_image = videoData.poster;
|
||||
item.itunes_duration = data.articleContentDto?.videoEditDtoList[0]?.sourceMediaInfo?.duration;
|
||||
item.enclosure_url = videoData.formats[0]?.url;
|
||||
item.enclosure_length = data.articleContentDto?.videoEditDtoList[0].sourceMediaInfo?.fileSize;
|
||||
item.enclosure_type = item.enclosure_url ? `video/${item.enclosure_url?.split(/\./)?.pop()}` : undefined;
|
||||
}
|
||||
|
||||
item.description = art(path.join(__dirname, 'templates/description.art'), {
|
||||
video: videoData
|
||||
? {
|
||||
src: item.enclosure_url,
|
||||
type: item.enclosure_type,
|
||||
poster: item.itunes_item_image,
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const description = $('meta[name="description"]').prop('content');
|
||||
const author = description.split(/,/)[0];
|
||||
const icon = $('link[rel="shortcut icon"]').prop('href');
|
||||
|
||||
ctx.state.data = {
|
||||
title: sizeTitle,
|
||||
item: items,
|
||||
title: $('title').text(),
|
||||
link: baseUrl,
|
||||
description: '农博士在行动-河北广播电视台',
|
||||
item: list,
|
||||
description,
|
||||
language: $('html').prop('lang'),
|
||||
image: $('div.logo a img').prop('src'),
|
||||
icon,
|
||||
logo: icon,
|
||||
subtitle: $('meta[name="keywords"]').prop('content'),
|
||||
author,
|
||||
itunes_author: author,
|
||||
itunes_category: 'News',
|
||||
allowEmpty: true,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
{{ if image?.src }}
|
||||
<figure>
|
||||
<img
|
||||
{{ if image.alt }}
|
||||
alt="{{ image.alt }}"
|
||||
{{ /if }}
|
||||
src="{{ image.src }}">
|
||||
</figure>
|
||||
{{ /if }}
|
||||
|
||||
{{ if video?.src }}
|
||||
<video
|
||||
{{ if video.poster }}
|
||||
poster={{ video.poster }}
|
||||
{{ /if }}
|
||||
controls>
|
||||
<source
|
||||
src="{{ video.src }}"
|
||||
type="{{ video.type }}">
|
||||
<object data="{{ video.src }}">
|
||||
<embed src="{{ video.src }}">
|
||||
</object>
|
||||
</video>
|
||||
{{ /if }}
|
||||
|
|
@ -1542,7 +1542,7 @@ IT・科学 tech_science
|
|||
|
||||
### 农博士在行动 {#he-bei-wang-luo-guang-bo-dian-shi-tai-nong-bo-shi-zai-xing-dong}
|
||||
|
||||
<Route author="iamqiz" example="/hebtv/nbszxd" path="/hebtv/nbszxd"/>
|
||||
<Route author="iamqiz nczitzk" example="/hebtv/nbszxd" path="/hebtv/nbszxd" radar="1" rssbud="1" supportBT="1" supportPodcast="1"/>
|
||||
|
||||
## 衡阳全搜索 {#heng-yang-quan-sou-suo}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue