add 游民娱乐 (#1924)

closes #1920
This commit is contained in:
Chenyang Shi
2019-04-13 14:29:17 +08:00
committed by DIYgod
parent 4d96d1cbd0
commit 51ed188c7c
3 changed files with 108 additions and 0 deletions

View File

@@ -90,6 +90,14 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
<Route name="游民星空今日推荐" author="LightStrawberry" example="/gamersky/news" path="/gamersky/news"/>
<Route name="游民娱乐" author="LogicJake" example="/gamersky/ent/ymfl" path="/gamersky/ent/:category" :paramsDesc="['分类类型']">
| 趣囧时间 | 游民影院 | 游观天下 | 壁纸图库 | 游民盘点 | 游民福利 |
| -------- | -------- | -------- | -------- | -------- | -------- |
| qysj | ymyy | ygtx | bztk | ympd | ymfl |
</Route>
## 游研社
<Route name="游研社" author="LightStrawberry" example="/yystv/category/:category" path="/yystv/category/:category" :paramsDesc="['专栏类型']"/>

View File

@@ -1201,6 +1201,7 @@ router.get('/people/xjpjh/:keyword?/:year?', require('./routes/people/xjpjh'));
// gamersky
router.get('/gamersky/news', require('./routes/gamersky/news'));
router.get('/gamersky/ent/:category', require('./routes/gamersky/ent'));
// 游研社
router.get('/yystv/category/:category', require('./routes/yystv/category'));

View File

@@ -0,0 +1,99 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const map = new Map([
['qysj', { title: '趣囧时间', suffix: 'ent/qw' }],
['ymyy', { title: '游民影院', suffix: 'wenku/movie' }],
['ygtx', { title: '游观天下', suffix: 'ent/discovery' }],
['bztk', { title: '壁纸图库', suffix: 'ent/wp' }],
['ympd', { title: '游民盘点', suffix: 'wenku' }],
['ymfl', { title: '游民福利', suffix: 'ent/xz/' }],
]);
module.exports = async (ctx) => {
const category = ctx.params.category;
const suffix = map.get(category).suffix;
const title = map.get(category).title;
const url = `https://www.gamersky.com/${suffix}`;
const response = await axios({
method: 'get',
url: url,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('ul.pictxt.contentpaging li')
.slice(0, 10)
.map(function() {
const info = {
title: $(this)
.find('div.tit a')
.text(),
link: $(this)
.find('div.tit a')
.attr('href'),
pubDate: new Date(
$(this)
.find('.time')
.text()
).toUTCString(),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const itemUrl = info.link;
const pubDate = info.pubDate;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
let next_pages = $('div.page_css a')
.map(function() {
return $(this).attr('href');
})
.get();
next_pages = next_pages.slice(0, -1);
const des = await Promise.all(
next_pages.map(async (next_page) => {
const response = await axios.get(next_page);
const $ = cheerio.load(response.data);
$('div.page_css').remove();
return $('.Mid2L_con')
.html()
.trim();
})
);
const description = des.join('');
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: pubDate,
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `游民娱乐-${title}`,
link: url,
item: out,
};
};