From 4b128aca9d869d6e448314f4fc0412d0ebb6c07c Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 30 Sep 2024 01:03:31 +0800 Subject: [PATCH] feat(route): spankbang (#16962) * feat(route): spankbang * fix: add antiCrawler flag --- lib/routes/spankbang/namespace.ts | 6 +++ lib/routes/spankbang/new-videos.ts | 64 ++++++++++++++++++++++++ lib/routes/spankbang/templates/video.art | 7 +++ 3 files changed, 77 insertions(+) create mode 100644 lib/routes/spankbang/namespace.ts create mode 100644 lib/routes/spankbang/new-videos.ts create mode 100644 lib/routes/spankbang/templates/video.art diff --git a/lib/routes/spankbang/namespace.ts b/lib/routes/spankbang/namespace.ts new file mode 100644 index 00000000000000..bc37481f9dcd3e --- /dev/null +++ b/lib/routes/spankbang/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'SpankBang', + url: 'spankbang.com', +}; diff --git a/lib/routes/spankbang/new-videos.ts b/lib/routes/spankbang/new-videos.ts new file mode 100644 index 00000000000000..54490e097fd8e5 --- /dev/null +++ b/lib/routes/spankbang/new-videos.ts @@ -0,0 +1,64 @@ +import { Data, Route } from '@/types'; +import { getCurrentPath } from '@/utils/helpers'; + +import ofetch from '@/utils/ofetch'; +import * as cheerio from 'cheerio'; +import { art } from '@/utils/render'; +import path from 'node:path'; +import { config } from '@/config'; + +const __dirname = getCurrentPath(import.meta.url); +const render = (data) => art(path.join(__dirname, 'templates/video.art'), data); + +const handler = async () => { + const baseUrl = 'https://spankbang.com'; + const link = `${baseUrl}/new_videos/`; + + const response = await ofetch(link, { + headers: { + 'User-Agent': config.trueUA, + }, + }); + const $ = cheerio.load(response); + + const items = $('.video-item') + .toArray() + .map((item) => { + const $item = $(item); + const thumb = $item.find('.thumb'); + const cover = $item.find('img.cover'); + + return { + title: thumb.attr('title'), + link: new URL(thumb.attr('href')!, baseUrl).href, + description: render({ + cover: cover.data('src'), + preview: cover.data('preview'), + }), + }; + }); + + return { + title: $('head title').text(), + description: $('head meta[name="description"]').attr('content'), + link, + item: items, + } as unknown as Promise; +}; + +export const route: Route = { + path: '/new_videos', + categories: ['multimedia'], + example: '/spankbang/new_videos', + name: 'New Porn Videos', + maintainers: ['TonyRL'], + features: { + antiCrawler: true, + }, + radar: [ + { + source: ['spankbang.com/new_videos/', 'spankbang.com/'], + }, + ], + handler, +}; diff --git a/lib/routes/spankbang/templates/video.art b/lib/routes/spankbang/templates/video.art new file mode 100644 index 00000000000000..c30942421bef40 --- /dev/null +++ b/lib/routes/spankbang/templates/video.art @@ -0,0 +1,7 @@ +{{ if preview }} + +{{ /if }}