feat(route): add s-hentai (#8146)

This commit is contained in:
Ethan Shen
2021-09-06 13:24:47 +08:00
committed by GitHub
parent ee0ed94081
commit 611d9dd548
4 changed files with 91 additions and 0 deletions

View File

@@ -122,6 +122,18 @@ Refer to [Pornhub F.A.Qs](https://help.pornhub.com/hc/en-us/articles/36004432703
- `cn` (Chinese), for Pornhub in China <https://cn.pornhub.com/>
- `jp` (Japanese), for Pornhub in Japan <https://jp.pornhub.com/> etc.
## s-hentai
### Category
<RouteEn author="nczitzk" example="/s-hentai" path="/hentai/:id?" :paramsDesc="['id, see below, ready-to-download by default']">
| Doujin | HCG | Games・Animes | Voices・ASMR | Ready to Download |
| ------ | --- | ------------- | ------------ | ----------------- |
| 1 | 2 | 3 | 4 | ready-to-download |
</RouteEn>
## Sankaku Complex
### Post

View File

@@ -628,6 +628,18 @@ pageClass: routes
<Route author="monner-henster" example="/rs05/rs05" path="/rs05/rs05"/>
## s-hentai
### Category
<Route author="nczitzk" example="/s-hentai" path="/s-hentai/:id?" :paramsDesc="['id见下表默认为 ready-to-download']">
| Doujin | HCG | Games・Animes | Voices・ASMR | Ready to Download |
| ------ | --- | ------------- | ------------ | ----------------- |
| 1 | 2 | 3 | 4 | ready-to-download |
</Route>
## Sankaku Complex
### Post

View File

@@ -4246,4 +4246,7 @@ router.get('/biodiscover/:channel?', lazyloadRouteHandler('./routes/biodiscover'
// 香港經濟日報
router.get('/hket/:category?', lazyloadRouteHandler('./routes/hket/index'));
// s-hentai
router.get('/s-hentai/:id?', lazyloadRouteHandler('./routes/s-hentai'));
module.exports = router;

View File

@@ -0,0 +1,64 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id || 'ready-to-download';
const rootUrl = 'https://s-hentai.org';
const currentUrl = `${rootUrl}/${id === 'ready-to-download' ? id : `menu/${id}`}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.block-product')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20)
.map((_, item) => {
item = $(item);
const a = item.find('.name-product a');
return {
title: a.text(),
link: a.attr('href'),
pubDate: parseDate(item.find('.post-date').text().trim().split(' ')[0], 'YYYY年MM月DD日'),
};
})
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const images = content('#sync1');
const description = content('#description-deital');
content('.single-support').remove();
item.enclosure_url = content('.file-download-comment a').eq(0).attr('href');
item.enclosure_type = 'application/x-bittorrent';
item.description = (images ? images.html() : '') + content('.detial-short').html() + (description ? description.html() : '');
item.category = detailResponse.data.match(/<a href="https:\/\/s-hentai\.org\/category\/\d+">(.*)<\/a>/g).map((category) => category.match(/>(.*)</)[1]);
return item;
})
)
);
ctx.state.data = {
title: `${$('title').text().trim().split('|')[0]} | S-HENTAI.ORG`,
link: currentUrl,
item: items,
};
};