feat(route): 斗鱼鱼吧帖子 & 跟帖 (#10465)

* feat(route): 斗鱼鱼吧帖子 & 跟帖

* fix replies

* fix: sort route
This commit is contained in:
Ethan Shen 2022-08-15 23:48:48 +08:00 committed by GitHub
parent 2992e73891
commit ac77cb202f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 164 additions and 1 deletions

View File

@ -428,6 +428,22 @@ pageClass: routes
<Route author="sfyumi" example="/eleduck/jobs" path="/eleduck/jobs"/>
## 斗鱼
### 鱼吧帖子
<Route author="nczitzk" example="/douyu/group/1011" path="/douyu/group/:id/:sort?" :paramsDesc="['鱼吧 id可在鱼吧页 URL 中找到', '排序方式,见下表,默认为发布时间排序']">
| 回复时间排序 | 发布时间排序 |
| ------ | ------ |
| 1 | 2 |
</Route>
### 鱼吧跟帖
<Route author="nczitzk" example="/douyu/post/631737151576473201" path="/douyu/post/:id" :paramsDesc="['帖子 id可在帖子页 URL 中找到']" />
## 恩山无线论坛
### 板块

View File

@ -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'));

45
lib/v2/douyu/group.js Normal file
View File

@ -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,
};
};

View File

@ -0,0 +1,5 @@
module.exports = {
'/group/:id/:sort?': ['nczitzk'],
'/post/:id': ['nczitzk'],
'/room/:id': ['DIYgod'],
};

51
lib/v2/douyu/post.js Normal file
View File

@ -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,
};
};

27
lib/v2/douyu/radar.js Normal file
View File

@ -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',
},
],
},
};

5
lib/v2/douyu/router.js Normal file
View File

@ -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'));
};

View File

@ -0,0 +1,14 @@
{{ if content }}
{{ content }}
{{ /if }}
{{ if images }}
{{ each images image }}
<img src="{{ image.url }}" width="{{ image.size.w }}" height="{{ image.size.h }}">
{{ /each }}
{{ /if }}
{{ if replies }}
<h3>回复</h3>
{{ each replies reply }}
<p><b>{{ reply.nickname }}</b> <small>[{{ reply.time }}]</small>: {{ reply.content }}</p>
{{ /each }}
{{ /if }}