From 8ec92353447858adcc2b0079a20111ae48cdf26c Mon Sep 17 00:00:00 2001 From: huanfei <41602338+huanfe1@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:50:24 +0800 Subject: [PATCH] feat(route): add route of javtiful (#16964) * feat(route): add route of javtiful * fix: fix some wrong --- lib/routes/javtiful/actress.ts | 37 +++++++++++++++++++ lib/routes/javtiful/channel.ts | 37 +++++++++++++++++++ lib/routes/javtiful/namespace.ts | 6 +++ lib/routes/javtiful/templates/description.art | 7 ++++ lib/routes/javtiful/utils.ts | 18 +++++++++ 5 files changed, 105 insertions(+) create mode 100644 lib/routes/javtiful/actress.ts create mode 100644 lib/routes/javtiful/channel.ts create mode 100644 lib/routes/javtiful/namespace.ts create mode 100644 lib/routes/javtiful/templates/description.art create mode 100644 lib/routes/javtiful/utils.ts diff --git a/lib/routes/javtiful/actress.ts b/lib/routes/javtiful/actress.ts new file mode 100644 index 00000000000000..7ddf8a5af0760d --- /dev/null +++ b/lib/routes/javtiful/actress.ts @@ -0,0 +1,37 @@ +import { Route, Data, DataItem } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { parseItems } from './utils'; + +export const route: Route = { + path: '/actress/:id', + name: 'Actress', + maintainers: ['huanfe1'], + example: '/javtiful/actress/akari-tsumugi', + parameters: { id: 'Actress name' }, + handler, + categories: ['multimedia'], + radar: [ + { + source: ['javtiful.com/actress/:id', 'javtiful.com/actress/:id/*'], + target: '/actress/:id', + }, + ], +}; + +async function handler(ctx): Promise { + const { id } = ctx.req.param(); + const html = await ofetch(`https://javtiful.com/actress/${id}`); + const $ = load(html); + const items: DataItem[] = $('section .card:not(:has(.bg-danger))') + .toArray() + .map((item) => parseItems($(item))); + return { + title: $('.channel-item__name_details a').text(), + link: `https://javtiful.com/actress/${id}`, + allowEmpty: true, + item: items, + image: $('.content-section-title img').attr('src'), + language: $('html').attr('lang'), + }; +} diff --git a/lib/routes/javtiful/channel.ts b/lib/routes/javtiful/channel.ts new file mode 100644 index 00000000000000..f0c82b2585a1d4 --- /dev/null +++ b/lib/routes/javtiful/channel.ts @@ -0,0 +1,37 @@ +import { Route, Data, DataItem } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { parseItems } from './utils'; + +export const route: Route = { + path: '/channel/:id', + name: 'Channel', + maintainers: ['huanfe1'], + example: '/javtiful/channel/madonna', + parameters: { id: 'Channel name' }, + handler, + categories: ['multimedia'], + radar: [ + { + source: ['javtiful.com/channel/:id', 'javtiful.com/channel/:id/*'], + target: '/channel/:id', + }, + ], +}; + +async function handler(ctx): Promise { + const { id } = ctx.req.param(); + const html = await ofetch(`https://javtiful.com/channel/${id}`); + const $ = load(html); + const items: DataItem[] = $('section .card:not(:has(.bg-danger))') + .toArray() + .map((item) => parseItems($(item))); + return { + title: $('.channel-item__name_details a').text(), + link: `https://javtiful.com/channel/${id}`, + allowEmpty: true, + item: items, + image: $('.content-section-title img').attr('src'), + language: $('html').attr('lang'), + }; +} diff --git a/lib/routes/javtiful/namespace.ts b/lib/routes/javtiful/namespace.ts new file mode 100644 index 00000000000000..1bf3f8239062ad --- /dev/null +++ b/lib/routes/javtiful/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Javtiful', + url: 'javtiful.com', +}; diff --git a/lib/routes/javtiful/templates/description.art b/lib/routes/javtiful/templates/description.art new file mode 100644 index 00000000000000..393036a449aaba --- /dev/null +++ b/lib/routes/javtiful/templates/description.art @@ -0,0 +1,7 @@ +{{ if previewVideo }} + +{{else if poster}} + +{{ /if }} diff --git a/lib/routes/javtiful/utils.ts b/lib/routes/javtiful/utils.ts new file mode 100644 index 00000000000000..e3fe4c5850da04 --- /dev/null +++ b/lib/routes/javtiful/utils.ts @@ -0,0 +1,18 @@ +import { getCurrentPath } from '@/utils/helpers'; +const __dirname = getCurrentPath(import.meta.url); + +import { art } from '@/utils/render'; +import path from 'node:path'; +import { parseRelativeDate } from '@/utils/parse-date'; + +const renderDescription = (data) => art(path.join(__dirname, 'templates/description.art'), data); + +export const parseItems = (e) => ({ + title: e.find('a > img').attr('alt')!, + link: e.find('a').attr('href')!, + description: renderDescription({ + poster: e.find('a > img').data('src'), + previewVideo: e.find('a > span').data('trailer'), + }), + pubDate: parseRelativeDate(e.find('.video-addtime').text()), +});