feat(rotue): playno1 (#9866)

This commit is contained in:
Tony 2022-06-01 08:00:32 +08:00 committed by GitHub
parent fefd96b853
commit 2c343e0ac9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 160 additions and 0 deletions

View File

@ -244,6 +244,28 @@ pageClass: routes
<Route author="xyqfer" example="/nga/post/18449558" path="/nga/post/:tid" :paramsDesc="['帖子 id, 可在帖子 URL 找到']" radar="1" rssbud="1"/>
## PLAYNO.1 玩樂達人
### AV
<Route author="TonyRL" example="/playno1/av" path="/playno1/av/:catid?" :paramsDesc="['分类,见下表,默认为全部文章']" radar="1" rssbud="1">
| 全部文章 | AV 新聞 | AV 導覽 |
| ---- | ----- | ----- |
| 78 | 3 | 5 |
</Route>
### 情趣
<Route author="sanmmm" example="/playno1/st" path="/playno1/st/:catid?" :paramsDesc="['分类,见下表,默认为全部文章']" radar="1" rssbud="1">
| 全部文章 | 情趣體驗報告 | 情趣新聞 | 情趣研究所 |
| ---- | ---------- | ---- | -------- |
| all | experience | news | graduate |
</Route>
## RF 技术社区
### 文章

41
lib/v2/playno1/av.js Normal file
View File

@ -0,0 +1,41 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const { cookieJar, processArticle } = require('./utils');
const baseUrl = 'http://www.playno1.com';
module.exports = async (ctx) => {
const { catid = '78' } = ctx.params;
const url = `${baseUrl}/portal.php?mod=list&catid=${catid}`;
const response = await got(url, {
cookieJar,
});
const $ = cheerio.load(response.data);
let items = $('.fire_float')
.toArray()
.filter((i) => $(i).text().length)
.map((item) => {
item = $(item);
return {
title: item.find('h3 a').attr('title'),
link: item.find('h3 a').attr('href'),
pubDate: timezone(parseDate(item.find('.fire_left').text()), 8),
author: item
.find('.fire_right')
.text()
.match(/作者:(.*)\s*\|/)[1]
.trim(),
};
});
items = await processArticle(items, ctx.cache);
ctx.state.data = {
title: $('head title').text(),
link: url,
item: items,
language: 'zh-TW',
};
};

View File

@ -0,0 +1,4 @@
module.exports = {
'/av/:catid?': ['TonyRL'],
'/st/:catid?': ['TonyRL'],
};

21
lib/v2/playno1/radar.js Normal file
View File

@ -0,0 +1,21 @@
module.exports = {
'playno1.com': {
_name: 'PLAYNO.1玩樂達人',
stno1: [
{
title: '情趣',
docs: 'https://docs.rsshub.app/bbs.html#playno-1-wan-le-da-ren',
source: ['/stno1/:catid/'],
target: '/playno1/st/:catid',
},
],
www: [
{
title: 'AV',
docs: 'https://docs.rsshub.app/bbs.html#playno-1-wan-le-da-ren',
source: ['/portal.php'],
target: (_params, url) => `/playno1/av/${new URL(url).searchParams.get('catid')}`,
},
],
},
};

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

@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/av/:catid?', require('./av'));
router.get('/st/:catid?', require('./st'));
};

36
lib/v2/playno1/st.js Normal file
View File

@ -0,0 +1,36 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const { cookieJar, processArticle } = require('./utils');
const baseUrl = 'http://stno1.playno1.com';
module.exports = async (ctx) => {
const { catid = 'all' } = ctx.params;
const url = `${baseUrl}/stno1/${catid}/`;
const response = await got(url, {
cookieJar,
});
const $ = cheerio.load(response.data);
let items = $('.fallsBox')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('.ftitle a').attr('title'),
link: item.find('.ftitle a').attr('href'),
pubDate: timezone(parseDate(item.find('.dateBox').text(), 'YYYY-MM-DD HH:mm'), 8),
author: item.find('.dateBox span a').eq(0).text().trim(),
};
});
items = await processArticle(items, ctx.cache);
ctx.state.data = {
title: $('head title').text(),
link: url,
item: items,
language: 'zh-TW',
};
};

32
lib/v2/playno1/utils.js Normal file
View File

@ -0,0 +1,32 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { CookieJar, Cookie } = require('tough-cookie');
const cookieJar = new CookieJar();
const cookie = Cookie.fromJSON({
key: 'playno1',
value: 'playno1Cookie',
domain: 'playno1.com',
path: '/',
});
(async () => {
await cookieJar.setCookie(cookie, 'http://www.playno1.com/');
})();
const processArticle = (items, cache) =>
Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link, {
cookieJar,
});
const content = cheerio.load(detailResponse.data);
item.description = content('#article_content').html();
return item;
})
)
);
module.exports = {
cookieJar,
processArticle,
};