Skip to content

Commit

Permalink
feat: add route /domp4/latest_movie_bt 订阅最新电影bt (#15650)
Browse files Browse the repository at this point in the history
* add-route: /domp4/latest_movie_bt 订阅最新电影bt

* optimize: remove response buffer parse
  • Loading branch information
xianghuawe committed May 22, 2024
1 parent 58bb8ef commit 32bd527
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/routes/domp4/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\(/);
Expand Down
71 changes: 71 additions & 0 deletions lib/routes/domp4/latest-movie-bt.ts
Original file line number Diff line number Diff line change
@@ -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(),
};
}

0 comments on commit 32bd527

Please sign in to comment.