fix(route): add full video option for sctv (#11240)
* fix(route): add full video option for sctv * fix: add video link exception * fix: filter full video by title * fix: typo
This commit is contained in:
@@ -1947,10 +1947,12 @@ category 对应的关键词有
|
||||
|
||||
### 电视回放
|
||||
|
||||
<Route author="nczitzk" example="/sctv/programme/1" path="/sctv/programme/:id?" :paramsDesc="['节目 id,可在对应节目页中找到,默认为 `1`,即四川新闻联播']">
|
||||
<Route author="nczitzk" example="/sctv/programme/1" path="/sctv/programme/:id?/:limit?/:isFull?" :paramsDesc="['节目 id,可在对应节目页中找到,默认为 `1`,即四川新闻联播', '期数,默认为 15,即单次获取最新 15 期', '是否仅获取完整视频,填写 true/yes 表示是、false/no 表示否,默认是']">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
参数 **是否仅获取完整视频** 设置为 `true` `yes` `t` `y` 等值后,路由仅返回当期节目的完整视频,而不会返回节目所提供的节选视频。
|
||||
|
||||
查看更多电视节目请前往 [电视回放](https://www.sctv.com/column/list)
|
||||
|
||||
:::
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module.exports = {
|
||||
'/programme/:id?': ['nczitzk'],
|
||||
'/programme/:id?/:limit?/:isFull?': ['nczitzk'],
|
||||
};
|
||||
|
||||
+39
-17
@@ -6,11 +6,13 @@ const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id ?? '1';
|
||||
const limit = ctx.params.limit ? parseInt(ctx.params.limit) : 15;
|
||||
const isFull = /t|y/i.test(ctx.params.isFull ?? 'true');
|
||||
|
||||
const rootUrl = 'https://www.sctv.com';
|
||||
const apiRootUrl = 'https://kscgc.sctv-tf.com';
|
||||
const apiUrl = `${apiRootUrl}//sctv/lookback/${id}/index.json`;
|
||||
const listUrl = `${apiRootUrl}//sctv/lookback/index/lookbackList.json`;
|
||||
const apiUrl = `${apiRootUrl}/sctv/lookback/${id}/date.json`;
|
||||
const listUrl = `${apiRootUrl}/sctv/lookback/index/lookbackList.json`;
|
||||
const currentUrl = `${rootUrl}/column/detail?programmeIndex=/sctv/lookback/${id}/index.json`;
|
||||
|
||||
let response = await got({
|
||||
@@ -18,23 +20,43 @@ module.exports = async (ctx) => {
|
||||
url: apiUrl,
|
||||
});
|
||||
|
||||
const programmeUrl = `${apiRootUrl}/${response.data.data.programmeUrl}`;
|
||||
let items = [];
|
||||
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: programmeUrl,
|
||||
});
|
||||
|
||||
const items = response.data.data.programmeList.map((item) => ({
|
||||
title: item.programmeTitle,
|
||||
link: item.programmeUrl,
|
||||
pubDate: timezone(parseDate(item.pubTime), +8),
|
||||
description: art(path.join(__dirname, 'templates/description.art'), {
|
||||
cover: item.programmeImage,
|
||||
video: item.programmeUrl,
|
||||
}),
|
||||
const array = response.data.data.programmeArray.slice(0, limit).map((list) => ({
|
||||
guid: list.id,
|
||||
link: `${apiRootUrl}${list.programmeListUrl}`,
|
||||
}));
|
||||
|
||||
await Promise.all(
|
||||
array.map((list) =>
|
||||
ctx.cache.tryGet(list.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: list.link,
|
||||
});
|
||||
|
||||
const currentItems = detailResponse.data.data.programmeList.map((item) => ({
|
||||
guid: item.id,
|
||||
title: item.programmeTitle,
|
||||
link: item.programmeUrl,
|
||||
pubDate: timezone(parseDate(item.pubTime), +8),
|
||||
description: art(path.join(__dirname, 'templates/description.art'), {
|
||||
cover: item.programmeImage,
|
||||
video: item.programmeUrl,
|
||||
}),
|
||||
}));
|
||||
|
||||
let currentFullItems = [];
|
||||
|
||||
if (isFull) {
|
||||
currentFullItems = currentItems.filter((item) => /(\d{4}\.\d{2}\.\d{2})/.test(item.title));
|
||||
}
|
||||
|
||||
items = [...items, ...(currentFullItems.length === 0 ? currentItems : currentFullItems)];
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: listUrl,
|
||||
@@ -52,7 +74,7 @@ module.exports = async (ctx) => {
|
||||
ctx.state.data = {
|
||||
title: `四川广播电视台 - ${name}`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
item: items.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 100),
|
||||
image: cover,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/programme/:id?', require('./programme'));
|
||||
router.get('/programme/:id?/:limit?/:isFull?', require('./programme'));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user