mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
feat: add 网易公开课 (#3895)
This commit is contained in:
@@ -982,12 +982,26 @@
|
||||
_name: '网易',
|
||||
ds: [
|
||||
{
|
||||
title: '网易大神',
|
||||
title: '大神',
|
||||
docs: 'https://docs.rsshub.app/game.html#wang-yi-da-shen',
|
||||
source: '/user/:id',
|
||||
target: '/netease/ds/:id',
|
||||
},
|
||||
],
|
||||
open: [
|
||||
{
|
||||
title: '公开课 - 精品课程',
|
||||
docs: 'https://docs.rsshub.app/study.html#wang-yi-gong-kai-ke',
|
||||
source: '/',
|
||||
target: '/open163/vip',
|
||||
},
|
||||
{
|
||||
title: '公开课 - 最新课程',
|
||||
docs: 'https://docs.rsshub.app/study.html#wang-yi-gong-kai-ke',
|
||||
source: '/',
|
||||
target: '/open163/latest',
|
||||
},
|
||||
],
|
||||
},
|
||||
'suzhou.gov.cn': {
|
||||
_name: '苏州市政府',
|
||||
|
||||
@@ -103,6 +103,16 @@ pageClass: routes
|
||||
|
||||
</Route>
|
||||
|
||||
## 网易公开课
|
||||
|
||||
### 精品课程
|
||||
|
||||
<Route author="hoilc" example="/open163/vip" path="/open163/vip" radar="1" />
|
||||
|
||||
### 最新课程
|
||||
|
||||
<Route author="hoilc" example="/open163/latest" path="/open163/latest" radar="1" />
|
||||
|
||||
## 下厨房
|
||||
|
||||
### 用户作品
|
||||
|
||||
@@ -2198,4 +2198,8 @@ router.get('/lastfm/top/:country?', require('./routes/lastfm/top'));
|
||||
router.get('/piapro/user/:pid', require('./routes/piapro/user'));
|
||||
router.get('/piapro/public/:type/:tag?/:category?', require('./routes/piapro/public'));
|
||||
|
||||
// 网易公开课
|
||||
router.get('/open163/vip', require('./routes/netease/open/vip'));
|
||||
router.get('/open163/latest', require('./routes/netease/open/latest'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
68
lib/routes/netease/open/latest.js
Normal file
68
lib/routes/netease/open/latest.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const list_response = await got.get('https://c.open.163.com/open/getLatestMovies.do?callback=');
|
||||
|
||||
const list = JSON.parse(list_response.data.match(/\((.*?)\)/)[1]) || [];
|
||||
|
||||
const parseContent = (htmlString) => {
|
||||
const $ = cheerio.load(htmlString);
|
||||
|
||||
const author = $('.m-courseinfo__side ul > li:nth-child(2)');
|
||||
|
||||
const images = $('img');
|
||||
for (let k = 0; k < images.length; k++) {
|
||||
const testRealURL = $(images[k])
|
||||
.attr('src')
|
||||
.match(/\?url=([^&]+)/);
|
||||
if (testRealURL) {
|
||||
$(images[k]).replaceWith(`<img src="${testRealURL[1]}" />`);
|
||||
}
|
||||
}
|
||||
|
||||
const content = $('.m-courseinfo__side');
|
||||
$('.i-container__title').remove();
|
||||
|
||||
return {
|
||||
author: author.text().trim(),
|
||||
description: content.html(),
|
||||
pubDate: new Date(),
|
||||
};
|
||||
};
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const link = item.url;
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const rssitem = {
|
||||
title: item.title,
|
||||
link: link,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await got.get(link);
|
||||
const result = parseContent(response.data);
|
||||
|
||||
rssitem.author = result.author;
|
||||
rssitem.description = result.description;
|
||||
rssitem.pubDate = result.pubDate;
|
||||
} catch (err) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
ctx.cache.set(link, JSON.stringify(rssitem));
|
||||
return Promise.resolve(rssitem);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '网易公开课 - 最新课程',
|
||||
link: 'https://open.163.com/',
|
||||
item: out.filter((item) => item !== ''),
|
||||
};
|
||||
};
|
||||
65
lib/routes/netease/open/vip.js
Normal file
65
lib/routes/netease/open/vip.js
Normal file
@@ -0,0 +1,65 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = 'https://open.163.com/';
|
||||
|
||||
const list_response = await got.get(url);
|
||||
const $ = cheerio.load(list_response.data);
|
||||
|
||||
const list = $('.tabcon > div:nth-child(1) ul.list li').toArray();
|
||||
|
||||
const parseContent = (htmlString) => {
|
||||
const $ = cheerio.load(htmlString);
|
||||
|
||||
const author = $('.CourseCommonDetail_info > div:nth-child(4)');
|
||||
const content = $('.CourseCommonDetail_contentDesc');
|
||||
|
||||
return {
|
||||
author: author.text().trim(),
|
||||
description: content.html(),
|
||||
pubDate: new Date(),
|
||||
};
|
||||
};
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const title = $('.ltxt')
|
||||
.text()
|
||||
.trim();
|
||||
const link = $('a.item')
|
||||
.attr('href')
|
||||
.split('?')[0];
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const rssitem = {
|
||||
title: title,
|
||||
link: link,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await got.get(link);
|
||||
const result = parseContent(response.data);
|
||||
|
||||
rssitem.author = result.author;
|
||||
rssitem.description = result.description;
|
||||
rssitem.pubDate = result.pubDate;
|
||||
} catch (err) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
ctx.cache.set(link, JSON.stringify(rssitem));
|
||||
return Promise.resolve(rssitem);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '网易公开课 - 精品课程',
|
||||
link: url,
|
||||
item: out.filter((item) => item !== ''),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user