feat(route): add Kemono (#8640)

This commit is contained in:
Ethan Shen
2022-01-22 16:09:54 +00:00
committed by GitHub
parent 46075a072e
commit 02f8872d5a
6 changed files with 159 additions and 0 deletions
+20
View File
@@ -253,6 +253,26 @@ pageClass: routes
</Route>
## Kemono
### Posts
<Route author="nczitzk" example="/kemono" path="/kemono/:source?/:id?" :paramsDesc="['来源,见下表,默认为 Posts', '用户 Id,可在对应页 URL 中找到']">
Sources
| Posts | Patreon | Pixiv Fanbox | Gumroad | SubscribeStar | DLsite | Discord | Fantia |
| ----- | ------- | ------------ | ------- | ------------- | ------ | ------- | ------ |
| posts | patreon | fanbox | gumroad | subscribestar | dlsite | discord | fantia |
::: tip 提示
当选择 `posts` 作为参数 **source** 的值时,参数 **id** 不生效。
:::
</Route>
## Mox.moe
### 首頁
+20
View File
@@ -10,6 +10,26 @@ pageClass: routes
<RouteEn author="EsuRt" example="/hanime/video" path="/hanime/video"/>
## Kemono
### Posts
<RouteEn author="nczitzk" example="/kemono" path="/kemono/:source?/:id?" :paramsDesc="['Source, see below, Posts by default', 'User id, can be found in URL']">
Sources
| Posts | Patreon | Pixiv Fanbox | Gumroad | SubscribeStar | DLsite | Discord | Fantia |
| ----- | ------- | ------------ | ------- | ------------- | ------ | ------- | ------ |
| posts | patreon | fanbox | gumroad | subscribestar | dlsite | discord | fantia |
::: tip Tip
When `posts` is selected as the value of the parameter **source**, the parameter **id** does not take effect.
:::
</RouteEn>
## Touhougarakuta
### Articles
+99
View File
@@ -0,0 +1,99 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const source = ctx.params.source ?? '';
const id = ctx.params.id;
const rootUrl = 'https://kemono.party';
const apiUrl = `${rootUrl}/api/discord/channels/lookup?q=${id}`;
const currentUrl = `${rootUrl}/${source ? `${source}/${source === 'discord' ? `server/${id}` : `user/${id}`}` : 'posts'}`;
const headers = {
cookie: '__ddg2=sBQ4uaaGecmfEUk7',
};
const response = await got({
method: 'get',
url: source === 'discord' ? apiUrl : currentUrl,
headers,
});
let items = [],
title = '';
if (source === 'discord') {
title = `Posts of ${id} from Discord | Kemono`;
await Promise.all(
response.data.map(async (channel) => {
await ctx.cache.tryGet(channel.id, async () => {
const channelResponse = await got({
method: 'get',
url: `${rootUrl}/api/discord/channel/${channel.id}?skip=0`,
headers,
});
items.push(
...channelResponse.data
.filter((i) => i.content || i.attachments)
.map((i) => ({
title: i.content,
description: (i.content ? `<p>${i.content}</p>` : '') + (i.attachments ? i.attachments.map((a) => `<img src="${rootUrl}${a.path}">`).join('') : ''),
author: i.author.username,
pubDate: parseDate(i.published),
category: channel.name,
}))
);
});
})
);
} else {
const $ = cheerio.load(response.data);
title = $('title').text();
items = await Promise.all(
$('.post-card')
.find('.fancy-link')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25)
.toArray()
.map((item) => {
item = $(item);
return {
link: `${rootUrl}${item.attr('href')}`,
};
})
.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
headers,
});
const content = cheerio.load(detailResponse.data);
content('.post__thumbnail').each(function () {
content(this).html(`<img src="${rootUrl}${content(this).find('.fileThumb').attr('href')}">`);
});
item.description = content('.post__body').html();
item.author = content('.post__user-name').text();
item.title = content('.post__title span').first().text();
item.pubDate = parseDate(content('.timestamp').attr('datetime'));
return item;
})
)
);
}
ctx.state.data = {
title,
link: currentUrl,
item: items,
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/:source?/:id?': ['nczitzk'],
'/posts': ['nczitzk'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'kemono.party': {
_name: 'Kemono',
'.': [
{
title: 'Posts',
docs: 'https://docs.rsshub.app/anime.html#kemono-posts',
source: ['/:source/user/:id', '/'],
target: '/kemono/:source?/:id?',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:source?/:id?', require('./index'));
};