feat: add melonbooks (#18753)
* feat: add melonbooks * refactor: extend description content * fix: fix cache path * fix: update * Update lib/routes/melonbooks/search.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * refactor: add whole item page into description ---------
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: 'メロンブックス',
|
||||
url: 'www.melonbooks.co.jp',
|
||||
description: 'サイン本の同人誌、同人ゲーム、同人音楽、同人グッズの通販は国内最大級、業界最速の萌えいっぱいの総合書店メロンブックスで。同人作品、同人委託の特典付商品も多数あり。直営店舗数も同人業界で最大級。',
|
||||
lang: 'ja',
|
||||
categories: ['anime'],
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
import { type DataItem } from '@/types';
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import cache from '@/utils/cache';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
|
||||
export function parseItems($: CheerioAPI, baseUrl: string, fetchRestrictedContent: boolean): Promise<DataItem[]> {
|
||||
const list = $('div.item-list ul li')
|
||||
.toArray()
|
||||
.map((el) => {
|
||||
const $el = $(el);
|
||||
const a = $el.find('a').first();
|
||||
const title = a.attr('title')!;
|
||||
const link = fetchRestrictedContent ? `${a.attr('href')}&adult_view=1` : a.attr('href');
|
||||
// const author = $el.find('p.search-item-author-author a').text();
|
||||
const category = [$el.find('p.item-state').text()];
|
||||
const image = $el.find('div.item-image img').attr('data-src');
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
category,
|
||||
image,
|
||||
banner: image,
|
||||
};
|
||||
});
|
||||
|
||||
return Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(`${baseUrl}${item.link}`, async () => {
|
||||
const res = await ofetch(`${baseUrl}${item.link}`);
|
||||
const $ = load(res);
|
||||
const description = $.html('div.item-page');
|
||||
return {
|
||||
...item,
|
||||
description,
|
||||
};
|
||||
})
|
||||
)
|
||||
) as unknown as Promise<DataItem[]>;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Data, Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
import { parseItems } from './parser';
|
||||
import { Context } from 'hono';
|
||||
import querystring from 'querystring';
|
||||
|
||||
export const handler = async (ctx: Context): Promise<Data | null> => {
|
||||
const baseUrl = 'https://www.melonbooks.co.jp';
|
||||
const query = ctx.req.param('query') ?? '';
|
||||
const url = `${baseUrl}/search/search.php?${query}`;
|
||||
const fetchRestrictedContent = querystring.parse(query).adult_view === '1';
|
||||
|
||||
const res = await ofetch(url);
|
||||
const $ = load(res);
|
||||
const items = await parseItems($, baseUrl, fetchRestrictedContent);
|
||||
|
||||
return {
|
||||
title: '搜索结果',
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
||||
export const route: Route = {
|
||||
path: '/search/:query?',
|
||||
categories: ['anime'],
|
||||
example: '/melonbooks/search/name=けいおん',
|
||||
parameters: { category: '链接参数,对应网址问号后的内容,不携带问号' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
name: '搜索结果',
|
||||
maintainers: ['cokemine'],
|
||||
description: `::: tip
|
||||
如果你期望获取限制级内容,可以添加\`&adult_view=1\`参数
|
||||
:::`,
|
||||
handler,
|
||||
};
|
||||
Reference in New Issue
Block a user