feat(route): add search route for Hanime1 (#18992)

* feat(route): add search route for Hanime1

* fix(route): modify the indents in description

* fix(route): delete the unnecessary indent
This commit is contained in:
Kjasn 2025-05-03 00:31:49 +08:00 committed by GitHub
parent ff83e833a6
commit b638c77848
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,110 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { config } from '@/config';
import { load } from 'cheerio';
async function handler(ctx) {
const { params } = ctx.req.param();
const baseUrl = 'https://hanime1.me';
// 提取参数
const searchParams = new URLSearchParams(params);
const query = searchParams.get('query') || '';
const genre = searchParams.get('genre') || '';
const broad = searchParams.get('broad') || '';
const tags = searchParams.getAll('tags[]');
const sort = searchParams.get('sort') || '';
const year = searchParams.get('year') || '';
const month = searchParams.get('month') || '';
let link = `${baseUrl}/search?query=${query}&genre=${genre}&broad=${broad}&sort=${sort}&year=${year}&month=${month}`;
for (const tag of tags) {
link += `&tags[]=${tag}`;
}
const response = await ofetch(link, {
headers: {
referer: baseUrl,
'user-agent': config.trueUA,
},
});
const $ = load(response);
const target = '.content-padding-new .row.no-gutter';
const items = $(target)
.find('.search-doujin-videos.hidden-xs') // 过滤掉重复的元素
.toArray()
.map((item) => {
const element = $(item);
const title = element.attr('title');
const videoLink = element.find('a.overlay').attr('href');
const imageSrc = element.find('img[style*="object-fit: cover"]').attr('src'); // 选择缩略图
return {
title,
videoLink,
description: `<img src="${imageSrc}">`,
};
});
// 最多显示三个标签
const maxTagsToShow = 3;
const displayedTags = tags.slice(0, maxTagsToShow).join(', ') + (tags.length > maxTagsToShow ? ', ...' : '');
const feedTitle = `Hanime1 搜索结果` + (genre ? ` | 类型: ${genre}` : '') + (query ? ` | 关键词: ${query}` : '') + (tags.length ? ` | 标签: ${displayedTags}` : '');
return {
title: feedTitle,
link,
item: items,
};
}
export const route: Route = {
path: '/search/:params',
name: '搜索结果',
maintainers: ['kjasn'],
example: '/hanime1/search/tags%5B%5D=%E7%B4%94%E6%84%9B&',
categories: ['anime'],
parameters: {
params: {
description: `
:
- (query) \`\`
- (genre)\`全部\`,可选类型有:
-
-
-
- Motion+Anime
- 3D動畫
-
- MMD
- Cosplay
- (tags[]) \`tags[]=純愛&tags[]=中文字幕\`
- broad \`on\`\`off\`,默认为\`off\`
- (sort)\`最新上市\`,可选排序有:
-
-
-
-
-
-
-
-
- (year, month) \`year=2025&month=5\`,默认为\`全部时间\`
**Tips**: 使 \`https://hanime1.me/search?query=&genre=裏番&broad=on&sort=最新上市&tags[]=純愛&tags[]=中文字幕\`\`/search?\`后面的部分就是参数了,最后得到类似这样的路由 \`https://rsshub.app/hanime1/search/query=&genre=裏番&broad=on&sort=最新上市&tags[]=純愛&tags[]=中文字幕\`
`,
},
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
handler,
};