Skip to content

Commit

Permalink
feat(route): add anime1 (#16842)
Browse files Browse the repository at this point in the history
* feat(route): add anime1

add 2 anime1 route:
1. anime
2. search

* Update anime.ts

fix example

* remove deprecated route

remove deprecated anime1 route:
1. anime.js
2. search.js

* Update search.ts

remove radar rule
  • Loading branch information
cxheng315 authored Sep 22, 2024
1 parent df586c1 commit b379e7d
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 50 deletions.
25 changes: 0 additions & 25 deletions lib/routes-deprecated/anime1/anime.js

This file was deleted.

25 changes: 0 additions & 25 deletions lib/routes-deprecated/anime1/search.js

This file was deleted.

63 changes: 63 additions & 0 deletions lib/routes/anime1/anime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Route } from '@/types';
import { parseDate } from '@/utils/parse-date';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';

export const route: Route = {
path: 'anime/:category/:name',
name: 'Anime',
url: 'anime1.me',
maintainers: ['cxheng315'],
example: '/anime1/anime/2024年夏季/神之塔-第二季',
categories: ['anime'],
parameters: {
category: 'Anime1 Category',
name: 'Anime1 Name',
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['anime1.me/category/:category/:name'],
target: '/anime/:category/:name',
},
],
handler,
};

async function handler(ctx) {
const { category, name } = ctx.req.param();

const response = await ofetch(`https://anime1.me/category/${category}/${name}`);

const $ = load(response);

const title = $('page-title').text().trim();

const items = $('article')
.toArray()
.map((el) => {
const $el = $(el);
const title = $el.find('.entry-title a').text().trim();
return {
title,
link: $el.find('.entry-title a').attr('href'),
description: title,
pubDate: parseDate($el.find('time').attr('datetime') || ''),
itunes_item_image: $el.find('video').attr('poster'),
};
});

return {
title,
link: `https://anime1.me/category/${category}/${name}`,
description: title,
item: items,
};
}
6 changes: 6 additions & 0 deletions lib/routes/anime1/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Anime1',
url: 'anime1.me',
};
57 changes: 57 additions & 0 deletions lib/routes/anime1/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Route } from '@/types';
import { parseDate } from '@/utils/parse-date';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';

export const route: Route = {
path: 'search/:keyword',
name: 'Search',
url: 'anime1.me',
maintainers: ['cxheng315'],
example: '/anime1/search/神之塔',
categories: ['anime'],
parameters: {
keyword: 'Anime1 Search Keyword',
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
handler,
};

async function handler(ctx) {
const { keyword } = ctx.req.param();

const response = await ofetch(`https://anime1.me/?s=${keyword}`);

const $ = load(response);

const title = $('page-title').text().trim();

const items = $('article.type-post')
.toArray()
.map((el) => {
const $el = $(el);
const title = $el.find('.entry-title a').text().trim();
return {
title,
link: $el.find('.entry-title a').attr('href'),
description: title,
pubDate: parseDate($el.find('time').attr('datetime') || ''),
};
});

return {
title,
link: `https://anime1.me/?s=${keyword}`,
description: title,
itunes_author: 'Anime1',
itunes_image: 'https://anime1.me/wp-content/uploads/2021/02/cropped-1-180x180.png',
item: items,
};
}

0 comments on commit b379e7d

Please sign in to comment.