增加: 中国大学MOOC(慕课) (#1305)

Closes #1301
This commit is contained in:
凉凉 2018-12-20 11:42:55 +08:00 committed by DIYgod
parent 61e2aa59f2
commit f473f72099
3 changed files with 86 additions and 0 deletions

View File

@ -2701,3 +2701,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
### 36kr
<route name="搜索文章" author="xyqfer" example="/36kr/search/article/8%E7%82%B91%E6%B0%AA" path="/36kr/search/article/:keyword" :paramsDesc="['关键字']" />
### 中国大学 MOOC(慕课)
<route name="最新" author="xyqfer" example="/icourse163/newest" path="/icourse163/newest" />

View File

@ -937,4 +937,7 @@ router.get('/tingdiantz/95598/:orgNo/:provinceNo/:scope?', require('./routes/tin
// 36kr
router.get('/36kr/search/article/:keyword', require('./routes/36kr/search/article'));
// icourse163
router.get('/icourse163/newest', require('./routes/icourse163/newest'));
module.exports = router;

View File

@ -0,0 +1,79 @@
const axios = require('../../utils/axios');
const qs = require('querystring');
module.exports = async (ctx) => {
const link = 'https://www.icourse163.org/category/all';
const homePage = await axios({
method: 'get',
url: link,
});
const csrfKey = homePage.headers['set-cookie'][0].split(';')[0].split('=')[1];
const response = await axios({
method: 'post',
url: `https://www.icourse163.org/web/j/courseBean.getCoursePanelListByFrontCategory.rpc?csrfKey=${csrfKey}`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Cookie: `NTESSTUDYSI=${csrfKey};`,
},
data: qs.stringify({
categoryId: -1,
type: 30,
orderBy: 10,
pageIndex: 1,
pageSize: 20,
}),
});
const items = response.data.result.result.map((item) => {
const title = item.name;
const link = `https://www.icourse163.org/course/${item.schoolPanel.shortName}-${item.id}`;
const lectors = item.termPanel.lectorPanels.reduce((lectors, lector) => {
lectors += `${lector.realName || lector.nickName}`;
return lectors;
}, '');
const tags = item.mocTagDtos.reduce((tags, tag) => {
tags += `${tag.name}`;
return tags;
}, '');
const startTime = new Date(item.termPanel.startTime);
const startYear = startTime.getFullYear();
const startMonth = (startTime.getMonth() + 1).toString().padStart(2, '0');
const startDate = startTime.getDate();
const startTimeString = item.termPanel.startTime === 32503651201000 ? '待定' : `${startYear}-${startMonth}-${startDate}`;
const media = item.VideoUrl
? `
<p>
<video
controls="controls"
style="width: 100%;"
poster="${item.imgUrl}"
src="https://v.stu.126.net/mooc-video/${item.VideoUrl}"
>
</p>
`
: `<img referrerpolicy="no-referrer" src="${item.imgUrl}"><br>`;
const description = `
<strong>${title}</strong><br>
${tags}<br>
${item.schoolPanel.name} ${lectors}<br>
开课时间: ${startTimeString}<br><br>
${media}
${item.termPanel.jsonContent.replace('spContent=', '')}
`;
return {
title,
link,
description,
};
});
ctx.state.data = {
title: '中国大学MOOC(慕课)-最新',
link,
description:
'中国大学MOOC(慕课) 是爱课程网携手网易云课堂打造的在线学习平台每一个有提升愿望的人都可以在这里学习中国优质的大学课程学完还能获得认证证书。中国大学MOOC是国内优质的中文MOOC学习平台拥有众多985高校的大学课程与名师零距离。',
item: items,
};
};