feat: 添加A站用户投稿 (#2628)

This commit is contained in:
沉冰浮水 2019-07-16 21:46:06 +08:00 committed by DIYgod
parent 1370d71b3d
commit 61b5af5f2c
3 changed files with 49 additions and 0 deletions

View File

@ -17,6 +17,10 @@ pageClass: routes
:::
### 用户投稿
<Route author="wdssmq" example="/acfun/user/video/14450522" path="/acfun/user/video/:id" :paramsDesc="['用户 UID']"/>
## bilibili
见 [#bilibili](/social-media.html#bilibili)

View File

@ -818,6 +818,7 @@ router.get('/ltaaa/:type?', require('./routes/ltaaa/main'));
// AcFun
router.get('/acfun/bangumi/:id', require('./routes/acfun/bangumi'));
router.get('/acfun/user/video/:uid', require('./routes/acfun/video'));
// Auto Trader
router.get('/autotrader/:query', require('./routes/autotrader'));

44
lib/routes/acfun/video.js Normal file
View File

@ -0,0 +1,44 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const uid = ctx.params.uid;
const url = `http://www.acfun.cn/u/${uid}.aspx`;
const host = 'http://www.acfun.cn';
const response = await got({
method: 'get',
url,
headers: {
Referer: host,
},
});
const data = response.data;
const $ = cheerio.load(data);
const title = $('title').text();
const description = $('.tan .info').text();
const list = $('#listVideo .contentView a').get();
ctx.state.data = {
title: title,
link: url,
description,
item: list
.map((item) => {
const $ = cheerio.load(item);
const itemTitle = $('p.title').text();
const itemImg = $('figure img').attr('data-original');
const itemUrl = $('a').attr('href');
const itemDate = $('.date').text();
return {
title: itemTitle,
description: `<img referrerpolicy="no-referrer" src="${itemImg}">`,
link: host + itemUrl,
pubDate: new Date(itemDate).toUTCString(),
};
})
.reverse(),
};
};