Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add Nicesss呦糖社 #14364

Closed
wants to merge 11 commits into from
72 changes: 72 additions & 0 deletions lib/v2/nicesss/category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');

module.exports = async (ctx) => {
let category = decodeURIComponent(ctx.params.category);
const limit = ctx.params.limit || 20;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the common parameter limit from ctx.query.limit.
docs: https://docs.rsshub.app/parameter#limit-entries

const items = [];
let currPage = 1;

switch (category) {
case '秀人':
case '秀人网':
case 'XiuRen':
category = 'xr';
break;
case '韩国':
case '韩国美女':
case '韩国美女写真':
case '秘境':
category = 'mij';
break;
case '丝袜':
case '丝袜美女':
case '丝袜美女写真':
case '丝真':
category = 'siz';
break;
case '热门':
case '热门美女':
case '热门美女写真':
case '热站':
category = 'rez';
break;
case '私影':
category = '私影';
break;
case 'cos':
case 'Cos':
case 'cosplay':
case 'Cosplay':
category = 'cosplya';
break;
default:
category = 'xr';
break;
}

do {
const url = `https://www.nicesss.com/${category}/page/${currPage}`;
try {
// eslint-disable-next-line no-await-in-loop
const { data: response } = await got(url);
Fixed Show fixed Hide fixed
const content = cheerio.load(response);
// eslint-disable-next-line no-await-in-loop
const newItems = await utils.ProcessItems(ctx, content);
Fixed Show fixed Hide fixed
items.push(...newItems);
} catch {
break;
}
} while (items.length < limit && currPage++ < 10);

ctx.state.data = {
title: `呦糖社 - “${category}”Category结果`,
link: `https://www.nicesss.com/${category}`,
description: `呦糖社 - “${category}”Category结果`,
image: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/logo/logo-light.png',
icon: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png',
logo: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png',
item: items.slice(0, limit),
};
};
32 changes: 32 additions & 0 deletions lib/v2/nicesss/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');

module.exports = async (ctx) => {
const limit = ctx.params.limit || 24;
const items = [];
let currPage = 1;
do {
const url = `https://www.nicesss.com/page/${currPage}`;
try {
// eslint-disable-next-line no-await-in-loop
const { data: response } = await got(url);
Fixed Show fixed Hide fixed
const content = cheerio.load(response);
// eslint-disable-next-line no-await-in-loop
const newItems = await utils.ProcessItems(ctx, content);
Fixed Show fixed Hide fixed
items.push(...newItems);
} catch {
break;
}
} while (items.length < limit && currPage++ < 10);

ctx.state.data = {
title: '呦糖社 - 首页',
link: 'https://www.nicesss.com/',
description: '呦糖社 - 首页',
image: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/logo/logo-light.png',
icon: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png',
logo: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png',
item: items.slice(0, limit),
};
};
6 changes: 6 additions & 0 deletions lib/v2/nicesss/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
'/:limit?': ['Steven-Fake'],
'/search/:keyword/:limit?': ['Steven-Fake'],
'/tag/:tag/:limit?': ['Steven-Fake'],
'/category/:category/:limit?': ['Steven-Fake'],
};
6 changes: 6 additions & 0 deletions lib/v2/nicesss/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = (router) => {
router.get('/:limit?', require('./index'));
router.get('/search/:keyword/:limit?', require('./search'));
router.get('/tag/:tag/:limit?', require('./tag'));
router.get('/category/:category/:limit?', require('./category'));
};
33 changes: 33 additions & 0 deletions lib/v2/nicesss/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');

module.exports = async (ctx) => {
const keyword = decodeURIComponent(ctx.params.keyword);
const limit = ctx.params.limit || 20;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the common parameter limit from ctx.query.limit.
docs: https://docs.rsshub.app/parameter#limit-entries

const items = [];
let currPage = 1;
do {
const url = `https://www.nicesss.com/page/${currPage}?s=${keyword}`;
try {
// eslint-disable-next-line no-await-in-loop
const { data: response } = await got(url);
Fixed Show fixed Hide fixed
const content = cheerio.load(response);
// eslint-disable-next-line no-await-in-loop
const newItems = await utils.ProcessItems(ctx, content);
Fixed Show fixed Hide fixed
items.push(...newItems);
} catch {
break;
}
} while (items.length < limit && currPage++ < 10);

ctx.state.data = {
title: `呦糖社 - “${keyword}”搜索结果`,
link: `https://www.nicesss.com/?s=${keyword}`,
description: `呦糖社 - “${keyword}”搜索结果`,
image: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/logo/logo-light.png',
icon: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png',
logo: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png',
item: items.slice(0, limit),
};
};
33 changes: 33 additions & 0 deletions lib/v2/nicesss/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');

module.exports = async (ctx) => {
const tag = decodeURIComponent(ctx.params.tag);
const limit = ctx.params.limit || 20;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the common parameter limit from ctx.query.limit.
docs: https://docs.rsshub.app/parameter#limit-entries

const items = [];
let currPage = 1;
do {
const url = `https://www.nicesss.com/archives/tag/${tag}/page/${currPage}`;
try {
// eslint-disable-next-line no-await-in-loop
const { data: response } = await got(url);
Fixed Show fixed Hide fixed
const content = cheerio.load(response);
// eslint-disable-next-line no-await-in-loop
const newItems = await utils.ProcessItems(ctx, content);
Fixed Show fixed Hide fixed
items.push(...newItems);
} catch {
break;
}
} while (items.length < limit && currPage++ < 10);

ctx.state.data = {
title: `呦糖社 - “${tag}”Tag结果`,
link: `https://www.nicesss.com/archives/tag/${tag}`,
description: `呦糖社 - “${tag}”Tag结果`,
image: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/logo/logo-light.png',
icon: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png',
logo: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png',
item: items.slice(0, limit),
};
};
129 changes: 129 additions & 0 deletions lib/v2/nicesss/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

function ParseImgs(html) {
// 解析详情页的全部图片
const $ = cheerio.load(html);

return $('img.alignnone')
.toArray()
.map((img) => {
const src = img.attribs['data-srcset'];
const alt = img.attribs.alt;
return { src, alt };
});
}
function ParseDownloadLinks(html, defaultDrive) {
// 解析详情页的全部下载链接
const $ = cheerio.load(html);
const links = $('center button a').toArray();

return links.slice(0, Math.floor(links.length / 2)).map((link) => {
const href = link.attribs.href;
let text = '';
if (href.includes('rosefile')) {
text = 'RoseFile';
} else if (href.includes('77file')) {
text = '77File';
} else if (href.includes('stfly') || href.includes('shrinkme') || href.includes('ouo.io') || href.includes('link1s')) {
Fixed Show fixed Hide fixed
text = defaultDrive;
} else {
text = '未知下载方式';
}

return { href, text };
});
}

module.exports = {
ProcessItems: async (ctx, content) => {
let items = content('div.row.posts-wrapper article') // 列表页数据,基本信息
.toArray()
.map((item) => {
item = content(item);
const link = item.find('a').first().attr('href');

return {
title: item.find('h2').text(),
link,
pubDate: parseDate(item.find('time').attr('datetime')),
author: item.find('span.meta-category').first().text(),
};
});

items = await Promise.all(
// 获取详情页数据
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);
const content = cheerio.load(detailResponse);

const uploader = content('span.sjblog-name a').first();
const uploadDate = content('span.sjblog-time').first();
let metaInfos = [];

metaInfos = content('font') // 部分元信息
.toArray()
.map((info) => {
info = content(info);
return {
key: info
.text()
.split(':')[0]
.replaceAll(/\[|]|-|[A-Za-z]/g, ''),
value: info.text().split(':')[1],
};
});
if (metaInfos.length === 0) {
metaInfos = [
{ key: '解压密码', value: '未知密码' },
{ key: '下载网盘', value: '未知网盘' },
{ key: '图片像素', value: '未知' },
{ key: '联系邮箱', value: '未知' },
];
}
let tags = content('div.entry-tags').first();
tags = tags
.find('a')
.toArray()
.map((tag) => content(tag).text());
const imgs = ParseImgs(detailResponse); // 详情页,预览图列表
const downloadLinks = ParseDownloadLinks(detailResponse, metaInfos[1].value); // 详情页,下载链接列表

item.category = tags;
item.author = uploader.text();
// 如果downloadLinks中有defaultDrive的,将其设为item.enclosure_url
item.enclosure_url = downloadLinks.find((link) => link.text === metaInfos[1].value)?.href || '';
item.description = `
<ul>
<li>
<b>上传日期</b>:${uploadDate.text().split(':')[1]}
</li>
<li>
<b>上传者</b>: ${uploader.text()}
</li>
<li>
<b>类型</b>: ${item.author}
</li>
${metaInfos.map((info) => `<li><b>${info.key}</b>: ${info.value}</li>`).join('')}
<li>
<b>下载链接</b>:
<ul>${downloadLinks.map((link) => `<li><a href="${link.href}">${link.text}</a></li>`).join('')}</ul>
</li>
<li>
<b>标签</b>:
<ul>${tags.map((tag) => `<li><a href="https://www.nicesss.com/archives/tag/${tag}">${tag}</a></li>`).join('')}</ul>
</li>
</ul>
<div>
${imgs.map((img) => `<img src="${img.src}" alt="${img.alt}" /><br>`).join('')}
</div>`;

return item;
})
)
);
return items;
},
};
26 changes: 26 additions & 0 deletions website/docs/routes/picture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,32 @@ For RSS content, specify options in the `routeParams` parameter in query string

<Route author="LogicJake OrangeEd1t TonyRL" example="/natgeo/dailyphoto" path="/natgeo/dailyphoto" />

## Nicesss 呦糖社 {#nicesss-you-tang-she}

### 首页 Homepage {#nicesss-you-tang-she-shou-ye-homepage}

<Route author="Steven-Fake" example="/nicesss/30" path="/nicesss/:limit?" paramsDesc={['结果数量,不足时显示全部结果,默认为24(第1页的数量)']} anticrawler="1" />

### 搜索 Search {#nicesss-you-tang-she-sou-suo-search}

<Route author="Steven-Fake" example="/nicesss/search/蠢沫沫/40" path="/nicesss/search/:keyword/:limit?" paramsDesc={['搜索关键词' ,'结果数量,不足时显示全部结果,默认为20(第1页的数量)']} />

### 类别 Category {#nicesss-you-tang-she-lei-bie-category}

<Route author="Steven-Fake" example="/nicesss/category/Cosplay" path="/nicesss/category/:category/:limit?" paramsDesc={['类别,可选项见下表' ,'结果数量,不足时显示全部结果,默认为20(第1页的数量)']}>
- Category 可选项
- `秀人`, `秀人网`, `XiuRen` 任选其一
- `韩国`, `韩国美女`, `韩国美女写真`, `秘境` 任选其一
- `丝袜`, `丝袜美女`, `丝袜美女写真`, `丝真` 任选其一
- `热门`, `热门美女`, `热门美女写真`, `热站` 任选其一
- `私影`
- `cos`, `Cos`, `cosplay`, `Cosplay` 任选其一
</Route>

### 标签 Tag {#nicesss-you-tang-she-biao-qian-tag}

<Route author="Steven-Fake" example="/nicesss/tag/rioko凉凉子/40" path="/nicesss/tag/:tag/:limit?" paramsDesc={['标签' ,'结果数量,不足时显示全部结果,默认为20(第1页的数量)']} />

## Pixabay {#pixabay}

### Search {#pixabay-search}
Expand Down
Loading