From b379e7d1aa7fd5ec95e1ffd14d7211ca937c48d1 Mon Sep 17 00:00:00 2001 From: hinus <64959125+cxheng315@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:12:09 +0800 Subject: [PATCH] feat(route): add anime1 (#16842) * 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 --- lib/routes-deprecated/anime1/anime.js | 25 ---------- lib/routes-deprecated/anime1/search.js | 25 ---------- lib/routes/anime1/anime.ts | 63 ++++++++++++++++++++++++++ lib/routes/anime1/namespace.ts | 6 +++ lib/routes/anime1/search.ts | 57 +++++++++++++++++++++++ 5 files changed, 126 insertions(+), 50 deletions(-) delete mode 100644 lib/routes-deprecated/anime1/anime.js delete mode 100644 lib/routes-deprecated/anime1/search.js create mode 100644 lib/routes/anime1/anime.ts create mode 100644 lib/routes/anime1/namespace.ts create mode 100644 lib/routes/anime1/search.ts diff --git a/lib/routes-deprecated/anime1/anime.js b/lib/routes-deprecated/anime1/anime.js deleted file mode 100644 index 214f10ca2..000000000 --- a/lib/routes-deprecated/anime1/anime.js +++ /dev/null @@ -1,25 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const { time, name } = ctx.params; - const $ = await got.get(`https://anime1.me/category/${encodeURIComponent(time)}/${encodeURIComponent(name)}`).then((r) => cheerio.load(r.data)); - const title = $('.page-title').text().trim(); - ctx.state.data = { - title, - link: `https://anime1.me/category/${time}/${name}`, - description: title, - item: $('article') - .toArray() - .map((art) => { - const $el = $(art); - const title = $el.find('.entry-title a').text(); - return { - title: $el.find('.entry-title a').text(), - link: $el.find('.entry-title a').attr('href'), - description: title, - pubDate: new Date($el.find('time').attr('datetime')).toUTCString(), - }; - }), - }; -}; diff --git a/lib/routes-deprecated/anime1/search.js b/lib/routes-deprecated/anime1/search.js deleted file mode 100644 index 6b88f8b9d..000000000 --- a/lib/routes-deprecated/anime1/search.js +++ /dev/null @@ -1,25 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const { keyword } = ctx.params; - const $ = await got.get(`https://anime1.me/?s=${encodeURIComponent(keyword)}`).then((r) => cheerio.load(r.data)); - const title = $('.page-title').text().trim(); - ctx.state.data = { - title, - link: `https://anime1.me/?s=${keyword}`, - description: title, - item: $('article:has(.cat-links)') - .toArray() - .map((art) => { - const $el = $(art); - const title = $el.find('.entry-title a').text(); - return { - title: $el.find('.entry-title a').text(), - link: $el.find('.entry-title a').attr('href'), - description: title, - pubDate: new Date($el.find('time').attr('datetime')).toUTCString(), - }; - }), - }; -}; diff --git a/lib/routes/anime1/anime.ts b/lib/routes/anime1/anime.ts new file mode 100644 index 000000000..f0f066719 --- /dev/null +++ b/lib/routes/anime1/anime.ts @@ -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, + }; +} diff --git a/lib/routes/anime1/namespace.ts b/lib/routes/anime1/namespace.ts new file mode 100644 index 000000000..ddb3b91f0 --- /dev/null +++ b/lib/routes/anime1/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Anime1', + url: 'anime1.me', +}; diff --git a/lib/routes/anime1/search.ts b/lib/routes/anime1/search.ts new file mode 100644 index 000000000..2e2e8fa80 --- /dev/null +++ b/lib/routes/anime1/search.ts @@ -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, + }; +}