feat: add 飘花电影网首页资源 (#4747)

This commit is contained in:
Ethan Shen 2020-05-12 14:25:04 +08:00 committed by GitHub
parent f3acba5f9e
commit 7555cd685e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 0 deletions

View File

@ -383,6 +383,12 @@ pageClass: routes
<Route author="greatcodeeer" example="/pianyuan" path="/pianyuan" radar="1"/>
## 飘花电影网
### 今日热门
<Route author="nczitzk" example="/piaohua/hot" path="/piaohua/hot" />
## 蜻蜓 FM
### 专辑

View File

@ -2664,4 +2664,7 @@ router.get('/qingting/channel/:id', require('./routes/qingting/channel'));
// 金色财经
router.get('/jinse/lives', require('./routes/jinse/lives'));
// 飘花电影网
router.get('/piaohua/hot', require('./routes/piaohua/hot'));
module.exports = router;

38
lib/routes/piaohua/hot.js Normal file
View File

@ -0,0 +1,38 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = 'https://www.piaohua.com/';
const response = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(response.data);
const list = $('ul.ul-imgtxt1.row li')
.map((_, item) => {
item = $(item);
return {
title: item.find('h3').text(),
link: url.resolve(link, item.find('a').attr('href')),
pubDate: new Date(item.find('span').text()).toUTCString(),
};
})
.get();
ctx.state.data = {
title: '飘花电影网 - 今日推荐',
link: link,
item: await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({ method: 'get', url: item.link });
const content = cheerio.load(detailResponse.data);
item.description = content('div.m-text1').html();
return item;
})
)
),
};
};