From ac77cb202fa57530b86397f6c8bba22cdcdb37eb Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Mon, 15 Aug 2022 23:48:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=97=E9=B1=BC=E9=B1=BC?= =?UTF-8?q?=E5=90=A7=E5=B8=96=E5=AD=90=20&=20=E8=B7=9F=E5=B8=96=20(#10465)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 斗鱼鱼吧帖子 & 跟帖 * fix replies * fix: sort route --- docs/bbs.md | 16 ++++++++ lib/router.js | 2 +- lib/v2/douyu/group.js | 45 +++++++++++++++++++++++ lib/v2/douyu/maintainer.js | 5 +++ lib/v2/douyu/post.js | 51 ++++++++++++++++++++++++++ lib/v2/douyu/radar.js | 27 ++++++++++++++ lib/{routes => v2}/douyu/room.js | 0 lib/v2/douyu/router.js | 5 +++ lib/v2/douyu/templates/description.art | 14 +++++++ 9 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 lib/v2/douyu/group.js create mode 100644 lib/v2/douyu/maintainer.js create mode 100644 lib/v2/douyu/post.js create mode 100644 lib/v2/douyu/radar.js rename lib/{routes => v2}/douyu/room.js (100%) create mode 100644 lib/v2/douyu/router.js create mode 100644 lib/v2/douyu/templates/description.art diff --git a/docs/bbs.md b/docs/bbs.md index 2c68ef132..0ffe8eb2b 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -428,6 +428,22 @@ pageClass: routes +## 斗鱼 + +### 鱼吧帖子 + + + +| 回复时间排序 | 发布时间排序 | +| ------ | ------ | +| 1 | 2 | + + + +### 鱼吧跟帖 + + + ## 恩山无线论坛 ### 板块 diff --git a/lib/router.js b/lib/router.js index ef6716556..fe14b5ca0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -188,7 +188,7 @@ router.get('/dribbble/user/:name', lazyloadRouteHandler('./routes/dribbble/user' router.get('/dribbble/keyword/:keyword', lazyloadRouteHandler('./routes/dribbble/keyword')); // 斗鱼 -router.get('/douyu/room/:id', lazyloadRouteHandler('./routes/douyu/room')); +// router.get('/douyu/room/:id', lazyloadRouteHandler('./routes/douyu/room')); // 虎牙 router.get('/huya/live/:id', lazyloadRouteHandler('./routes/huya/live')); diff --git a/lib/v2/douyu/group.js b/lib/v2/douyu/group.js new file mode 100644 index 000000000..8a19f0621 --- /dev/null +++ b/lib/v2/douyu/group.js @@ -0,0 +1,45 @@ +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const sort = ctx.params.sort ?? '2'; + + const rootUrl = 'https://yuba.douyu.com'; + const detailUrl = `${rootUrl}/wbapi/web/group/head?group_id=${id}`; + const apiUrl = `${rootUrl}/wbapi/web/group/postlist?group_id=${id}&page=1&sort=${sort}`; + const currentUrl = `${rootUrl}/group/${sort === '1' ? 'newall' : 'newself'}/${id}`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const detailResponse = await got({ + method: 'get', + url: detailUrl, + }); + + const items = response.data.data.map((item) => ({ + title: item.title, + link: `${rootUrl}/p/${item.post_id}`, + pubDate: timezone(parseDate(item.created_at_std), +8), + description: art(path.join(__dirname, 'templates/description.art'), { + content: item.describe, + images: item.imglist.map((i) => ({ + size: i.size, + url: i.url, + })), + }), + })); + + ctx.state.data = { + title: `斗鱼鱼吧 - ${detailResponse.data.data.group_name}`, + link: currentUrl, + item: items, + description: detailResponse.data.data.describe, + }; +}; diff --git a/lib/v2/douyu/maintainer.js b/lib/v2/douyu/maintainer.js new file mode 100644 index 000000000..b423214bf --- /dev/null +++ b/lib/v2/douyu/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/group/:id/:sort?': ['nczitzk'], + '/post/:id': ['nczitzk'], + '/room/:id': ['DIYgod'], +}; diff --git a/lib/v2/douyu/post.js b/lib/v2/douyu/post.js new file mode 100644 index 000000000..a10ed5c10 --- /dev/null +++ b/lib/v2/douyu/post.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const rootUrl = 'https://yuba.douyu.com'; + const currentUrl = `${rootUrl}/p/${id}`; + const detailUrl = `${rootUrl}/wbapi/web/post/detail/${id}`; + + const detailResponse = await got({ + method: 'get', + url: detailUrl, + }); + + const data = detailResponse.data.data; + const apiUrl = `${rootUrl}/wbapi/web/post/comments/${id}?group_id=${data.group_id}&sink=1&page=1`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const items = response.data.data.map((item) => ({ + title: `${item.nick_name}: ${item.content}`, + link: `${currentUrl}#${item.comment_id}${item.sub_replies.length > 0 ? `+${item.sub_replies.map((r) => r.comment_id).join('+')}` : ''}`, + pubDate: parseDate(item.created_ts * 1000), + description: art(path.join(__dirname, 'templates/description.art'), { + content: item.content, + images: item.imglist.map((i) => ({ + size: i.size, + url: i.url, + })), + replies: + item.sub_replies.map((r) => ({ + nickname: r.nickname, + content: r.content, + time: new Date(r.created_ts * 1000).toLocaleString(), + })) ?? undefined, + }), + })); + + ctx.state.data = { + title: `斗鱼鱼吧 - ${data.title}`, + link: currentUrl, + item: items, + description: data.content, + }; +}; diff --git a/lib/v2/douyu/radar.js b/lib/v2/douyu/radar.js new file mode 100644 index 000000000..da50367db --- /dev/null +++ b/lib/v2/douyu/radar.js @@ -0,0 +1,27 @@ +module.exports = { + 'douyu.com': { + _name: '斗鱼', + www: [ + { + title: '直播间开播', + docs: 'https://docs.rsshub.app/live.html#dou-yu-zhi-bo-zhi-bo-jian-kai-bo', + source: ['/:id', '/'], + target: '/douyu/room/:id', + }, + ], + yuba: [ + { + title: '鱼吧帖子', + docs: 'https://docs.rsshub.app/bbs.html#dou-yu-yu-ba-tie-zi', + source: ['/group/:id', '/group/newself/:id', '/group/newall/:id', '/'], + target: '/douyu/group/:id', + }, + { + title: '鱼吧跟帖', + docs: 'https://docs.rsshub.app/bbs.html#dou-yu-yu-ba-gen-tie', + source: ['/p/:id', '/'], + target: '/douyu/post/:id', + }, + ], + }, +}; diff --git a/lib/routes/douyu/room.js b/lib/v2/douyu/room.js similarity index 100% rename from lib/routes/douyu/room.js rename to lib/v2/douyu/room.js diff --git a/lib/v2/douyu/router.js b/lib/v2/douyu/router.js new file mode 100644 index 000000000..0cab7dfe1 --- /dev/null +++ b/lib/v2/douyu/router.js @@ -0,0 +1,5 @@ +module.exports = function (router) { + router.get('/group/:id/:sort?', require('./group')); + router.get('/post/:id', require('./post')); + router.get('/room/:id', require('./room')); +}; diff --git a/lib/v2/douyu/templates/description.art b/lib/v2/douyu/templates/description.art new file mode 100644 index 000000000..f935538bd --- /dev/null +++ b/lib/v2/douyu/templates/description.art @@ -0,0 +1,14 @@ +{{ if content }} +{{ content }} +{{ /if }} +{{ if images }} +{{ each images image }} + +{{ /each }} +{{ /if }} +{{ if replies }} +

回复

+{{ each replies reply }} +

{{ reply.nickname }} [{{ reply.time }}]: {{ reply.content }}

+{{ /each }} +{{ /if }} \ No newline at end of file