feat(route): jpxgmn (#14734)
* feat(route): jpxgmn * docs: revert unnecessary build * Apply suggestions from code review - parsing pubDate - radar rules
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: '极品性感美女',
|
||||
url: 'www.jpxgmn.com',
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Route } from '@/types';
|
||||
import { originUrl, getArticleDesc } from './utils';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/search/:kw',
|
||||
categories: ['picture'],
|
||||
example: '/jpxgmn/search/candy',
|
||||
parameters: { kw: '搜索关键词' },
|
||||
name: '搜索',
|
||||
maintainers: ['Urabartin'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const { kw } = ctx.req.param();
|
||||
const searchUrl = originUrl + `/plus/search/index.asp?keyword=${kw}`;
|
||||
const response = await got(searchUrl);
|
||||
const baseUrl = new URL(response.url).origin;
|
||||
const $ = load(response.data);
|
||||
const items = $('div.list div.list div.node p')
|
||||
.toArray()
|
||||
.map((item) => ({
|
||||
title: $(item).find('b').text(),
|
||||
link: new URL($(item).find('a').attr('href'), baseUrl).href,
|
||||
pubDate: parseDate($(item).next().next().next().find('span').first().text()),
|
||||
}))
|
||||
.filter((item) => item.title.length !== 0);
|
||||
|
||||
return {
|
||||
title: `极品性感美女搜索 - ${kw}`,
|
||||
link: response.url,
|
||||
item: await Promise.all(
|
||||
items.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
item.description = await getArticleDesc(item.link);
|
||||
return item;
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { Route } from '@/types';
|
||||
import { originUrl, getArticleDesc } from './utils';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/tab/:tab?',
|
||||
categories: ['picture'],
|
||||
example: '/jpxgmn/tab',
|
||||
parameters: { tab: '分类,默认为`top`,包括`top`、`new`、`hot`,以及[源网站](http://www.jpxgmn.com/)所包含的其他相对路径,比如`Xiuren`、`XiaoYu`等' },
|
||||
radar: [{
|
||||
source: ['www.12356782.xyz/:tab'],
|
||||
target: '/:tab',
|
||||
}],
|
||||
name: '分类',
|
||||
maintainers: ['Urabartin'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const { tab = 'top' } = ctx.req.param();
|
||||
const isSpecial = ['new', 'top', 'hot'].includes(tab);
|
||||
const tabUrl = `${originUrl}/${tab}` + (isSpecial ? '.html' : '/');
|
||||
const response = await got(tabUrl);
|
||||
const baseUrl = new URL(response.url).origin;
|
||||
const $ = load(response.data);
|
||||
const topTitle = $('div.toptip > a').get(1);
|
||||
let feedTitle = $('title').text();
|
||||
if (isSpecial) {
|
||||
feedTitle = feedTitle.split('_')[1];
|
||||
} else if (topTitle) {
|
||||
feedTitle = $(topTitle).text();
|
||||
}
|
||||
const items = $('div.related_posts ul > li')
|
||||
.toArray()
|
||||
.map((item) => ({
|
||||
title: $(item).find('a span').text(),
|
||||
link: new URL($(item).find('a').attr('href'), baseUrl).href,
|
||||
pubDate: parseDate($(item).find('footer span').first().text()),
|
||||
}));
|
||||
return {
|
||||
title: `极品性感美女 - ${feedTitle}`,
|
||||
link: response.url,
|
||||
item: await Promise.all(
|
||||
items.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
item.description = await getArticleDesc(item.link);
|
||||
return item;
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{{ each images }}
|
||||
<img src="{{ $value }}">
|
||||
{{ /each }}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { getCurrentPath } from '@/utils/helpers';
|
||||
const __dirname = getCurrentPath(import.meta.url);
|
||||
|
||||
import got from '@/utils/got';
|
||||
import { art } from '@/utils/render';
|
||||
import { load } from 'cheerio';
|
||||
import * as path from 'node:path';
|
||||
|
||||
const originUrl = 'http://www.jpxgmn.com';
|
||||
|
||||
const getImages = ($articleContent) =>
|
||||
$articleContent('article > p img')
|
||||
.toArray()
|
||||
.map((img) => $articleContent(img).attr('src'));
|
||||
|
||||
const getArticleDesc = async (articleUrl) => {
|
||||
const response = await got(articleUrl);
|
||||
const $content = load(response.data);
|
||||
let pageCnt = $content('div.pagination:first ul a').length - 1;
|
||||
if (pageCnt === -1) {
|
||||
pageCnt = 1;
|
||||
}
|
||||
const images = getImages($content);
|
||||
const otherImages = await Promise.all(
|
||||
[...Array(pageCnt - 1).keys()].map(async (pageIndex) => {
|
||||
const pageUrl = articleUrl.replace('.html', `_${pageIndex + 1}.html`);
|
||||
const pageResponse = await got(pageUrl);
|
||||
return getImages(load(pageResponse.data));
|
||||
})
|
||||
);
|
||||
return art(path.join(__dirname, 'templates/description.art'), {
|
||||
images: [...images, ...otherImages.flat()],
|
||||
});
|
||||
};
|
||||
|
||||
export { originUrl, getArticleDesc };
|
||||
@@ -0,0 +1,52 @@
|
||||
import { Route } from '@/types';
|
||||
import { originUrl, getArticleDesc } from './utils';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/weekly',
|
||||
categories: ['picture'],
|
||||
example: '/jpxgmn/weekly',
|
||||
radar: [{
|
||||
source: ['www.12356782.xyz/'],
|
||||
target: '/weekly',
|
||||
}],
|
||||
name: '本周热门',
|
||||
maintainers: ['Urabartin'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const response = await got(originUrl);
|
||||
const baseUrl = new URL(response.url).origin;
|
||||
const $ = load(response.data);
|
||||
const items = $('aside div:nth-child(2) li')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
const fullTitle = $(item).find('a').attr('title') || '';
|
||||
const result = fullTitle.match(/([^.]+)\.\D+([\d-]+)/);
|
||||
const ret = {
|
||||
title: fullTitle,
|
||||
link: new URL($(item).find('a').attr('href'), baseUrl).href,
|
||||
};
|
||||
if (result !== null) {
|
||||
ret.title = result[1];
|
||||
ret.pubDate = parseDate(result[2]);
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
return {
|
||||
title: `极品性感美女 - 本周热门推荐`,
|
||||
link: response.url,
|
||||
item: await Promise.all(
|
||||
items.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
item.description = await getArticleDesc(item.link);
|
||||
return item;
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user