Skip to content

Commit

Permalink
feat(route): add route of javtiful (#16964)
Browse files Browse the repository at this point in the history
* feat(route): add route of javtiful

* fix: fix some wrong
  • Loading branch information
huanfe1 authored Sep 30, 2024
1 parent 6bd881c commit 8ec9235
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/routes/javtiful/actress.ts
Original file line number Diff line number Diff line change
@@ -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<Data> {
const { id } = ctx.req.param();
const html = await ofetch(`https://javtiful.com/actress/${id}`);
const $ = load(<string>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'),
};
}
37 changes: 37 additions & 0 deletions lib/routes/javtiful/channel.ts
Original file line number Diff line number Diff line change
@@ -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<Data> {
const { id } = ctx.req.param();
const html = await ofetch(`https://javtiful.com/channel/${id}`);
const $ = load(<string>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'),
};
}
6 changes: 6 additions & 0 deletions lib/routes/javtiful/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: 'Javtiful',
url: 'javtiful.com',
};
7 changes: 7 additions & 0 deletions lib/routes/javtiful/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ if previewVideo }}
<video controls preload="metadata" poster="{{ poster }}">
<source src="{{ previewVideo }}" type="video/mp4">
</video>
{{else if poster}}
<img src="{{ poster }}">
{{ /if }}
18 changes: 18 additions & 0 deletions lib/routes/javtiful/utils.ts
Original file line number Diff line number Diff line change
@@ -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()),
});

0 comments on commit 8ec9235

Please sign in to comment.