From 61b5af5f2c3dbc4368e2d49fc5453dcb8cad8080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=89=E5=86=B0=E6=B5=AE=E6=B0=B4?= Date: Tue, 16 Jul 2019 21:46:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0A=E7=AB=99=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8A=95=E7=A8=BF=20(#2628)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/multimedia.md | 4 ++++ lib/router.js | 1 + lib/routes/acfun/video.js | 44 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 lib/routes/acfun/video.js diff --git a/docs/multimedia.md b/docs/multimedia.md index 5b99b06a4..ed8012da4 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -17,6 +17,10 @@ pageClass: routes ::: +### 用户投稿 + + + ## bilibili 见 [#bilibili](/social-media.html#bilibili) diff --git a/lib/router.js b/lib/router.js index f41320d93..acbafd594 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/acfun/video.js b/lib/routes/acfun/video.js new file mode 100644 index 000000000..cb99e0b26 --- /dev/null +++ b/lib/routes/acfun/video.js @@ -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: ``, + link: host + itemUrl, + pubDate: new Date(itemDate).toUTCString(), + }; + }) + .reverse(), + }; +};