feat(route): add Coomer (#9610)

* feat(route): add Coomer

* fix typo
This commit is contained in:
Ethan Shen 2022-04-25 08:56:03 +08:00 committed by GitHub
parent 7be82ccdd0
commit c9e423b8f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 116 additions and 0 deletions

View File

@ -30,6 +30,16 @@ Full transcript support for better user experience.
<RouteEn author="nczitzk" example="/bandcamp/live" path="/bandcamp/live"/>
## Coomer
### Artist
<RouteEn author="nczitzk" example="/coomer/artist/belledelphine" path="/coomer/artist/:id" :paramsDesc="['Artist id, can be found in URL']"/>
### Recent Posts
<RouteEn author="nczitzk" example="/coomer/posts" path="/coomer/posts"/>
## EZTV
::: tip

View File

@ -303,6 +303,16 @@ BT 之家的域名会变更,本路由以 <https://www.btbtt20.com> 为默认
</Route>
## Coomer
### Artist
<Route author="nczitzk" example="/coomer/artist/belledelphine" path="/coomer/artist/:id" :paramsDesc="['Artist id可在对应页面中找到']"/>
### Recent Posts
<Route author="nczitzk" example="/coomer/posts" path="/coomer/posts"/>
## E-Hentai
### 分类

9
lib/v2/coomer/artist.js Normal file
View File

@ -0,0 +1,9 @@
const fetchItems = require('./utils');
module.exports = async (ctx) => {
const id = ctx.params.id;
const currentUrl = `onlyfans/user/${id}`;
ctx.state.data = await fetchItems(ctx, currentUrl);
};

View File

@ -0,0 +1,4 @@
module.exports = {
'/artist/:id': ['nczitzk'],
'/posts': ['nczitzk'],
};

7
lib/v2/coomer/posts.js Normal file
View File

@ -0,0 +1,7 @@
const fetchItems = require('./utils');
module.exports = async (ctx) => {
const currentUrl = 'posts';
ctx.state.data = await fetchItems(ctx, currentUrl);
};

19
lib/v2/coomer/radar.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = {
'coomer.party': {
_name: 'Coomer',
'.': [
{
title: 'Artist',
docs: 'https://docs.rsshub.app/multimedia.html#coomer-artist',
source: ['/onlyfans/user/:id', '/'],
target: '/coomer/artist/:id',
},
{
title: 'Recent Posts',
docs: 'https://docs.rsshub.app/multimedia.html#coomer-recent-posts',
source: ['/posts', '/'],
target: '/coomer/posts',
},
],
},
};

4
lib/v2/coomer/router.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/artist/:id', require('./artist'));
router.get('/posts', require('./posts'));
};

53
lib/v2/coomer/utils.js Normal file
View File

@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx, currentUrl) => {
const rootUrl = 'https://coomer.party';
currentUrl = `${rootUrl}/${currentUrl}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = $('.post-card__link .fancy-link')
.toArray()
.map((item) => {
item = $(item);
return {
link: `${rootUrl}${item.attr('href')}`,
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.ad-container').remove();
item.author = content('.post__user-name').text();
item.title = content('.post__title span').first().text();
item.pubDate = parseDate(content('.timestamp').attr('datetime'));
item.description = content('.post__body').html();
return item;
})
)
);
return {
title: $('title').text(),
link: currentUrl,
item: items,
};
};