From 32bd527684e18e1947aeef4625668a7062e0d192 Mon Sep 17 00:00:00 2001 From: xianghuawe Date: Wed, 22 May 2024 17:28:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20route=20/domp4/latest=5Fmovie=5Fb?= =?UTF-8?q?t=20=E8=AE=A2=E9=98=85=E6=9C=80=E6=96=B0=E7=94=B5=E5=BD=B1bt=20?= =?UTF-8?q?(#15650)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add-route: /domp4/latest_movie_bt 订阅最新电影bt * optimize: remove response buffer parse --- lib/routes/domp4/detail.ts | 2 +- lib/routes/domp4/latest-movie-bt.ts | 71 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 lib/routes/domp4/latest-movie-bt.ts diff --git a/lib/routes/domp4/detail.ts b/lib/routes/domp4/detail.ts index 701933f76a8a7..ba9780237065a 100644 --- a/lib/routes/domp4/detail.ts +++ b/lib/routes/domp4/detail.ts @@ -26,7 +26,7 @@ function getDomList($, detailUrl) { return list; } -function getItemList($, detailUrl, second) { +export function getItemList($, detailUrl, second) { const encoded = $('.article script[type]') .text() .match(/return p}\('(.*)',(\d+),(\d+),'(.*)'.split\(/); diff --git a/lib/routes/domp4/latest-movie-bt.ts b/lib/routes/domp4/latest-movie-bt.ts new file mode 100644 index 0000000000000..b9c38a011339b --- /dev/null +++ b/lib/routes/domp4/latest-movie-bt.ts @@ -0,0 +1,71 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { getItemList as detailItemList } from './detail'; + +import { defaultDomain, ensureDomain } from './utils'; +import cache from '@/utils/cache'; + +function getItemList($) { + const list = $(`#vod .list-group-item`) + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('a').text(), + publishDate: item.find('b').text(), + link: `https://${defaultDomain}${item.find('a').attr('href')}`, // fixed domain for guid + }; + }) + .filter((item) => !item.title.includes('话') && !item.title.includes('集') && !item.title.includes('更新至')); + return list; +} + +export const route: Route = { + path: '/latest_movie_bt', + categories: ['multimedia'], + example: '/domp4/latest_movie_bt', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: true, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['domp4.cc/', 'domp4.cc/custom/update.html'], + }, + ], + name: '最近更新的电源BT列表', + maintainers: ['xianghuawe'], + handler, + url: 'domp4.cc/', +}; + +async function handler(ctx) { + const { domain, second } = ctx.req.query(); + const hostUrl = ensureDomain(ctx, domain); + const latestUrl = `${hostUrl}/custom/update.html`; + const res = await got.get(latestUrl); + const $ = load(res.data); + const list = getItemList($); + const process = await Promise.all( + list.map( + async (item) => + await cache.tryGet(item.link, async () => { + const response = await got.get(item.link); + const $ = load(response.data); + return detailItemList($, item.link, second); + }) + ) + ); + + return { + link: latestUrl, + title: 'domp4电影', + item: process.filter((item) => item !== undefined).flat(), + }; +}