mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-16 21:02:57 +08:00
fix(secshi): recover the current public movie list through the browser
This commit is contained in:
@@ -3,6 +3,43 @@ import type { Context } from 'hono';
|
||||
|
||||
import type { Data, Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { getPlaywrightPage } from '@/utils/playwright';
|
||||
|
||||
const isExpiredCertificate = (error: unknown): boolean => error instanceof Error && (('code' in error && error.code === 'CERT_HAS_EXPIRED') || isExpiredCertificate(error.cause));
|
||||
|
||||
async function getBrowserContent(link: string) {
|
||||
const { page, destroy } = await getPlaywrightPage(link, { noGoto: true, closeTimeout: 0 });
|
||||
try {
|
||||
await page.route('**/*', (route) => (['document', 'script', 'xhr', 'fetch', 'stylesheet'].includes(route.request().resourceType()) ? route.continue() : route.abort()));
|
||||
await page.goto(link, { waitUntil: 'domcontentloaded', timeout: 20000 });
|
||||
await page.waitForSelector('ul.hl-vod-list li.hl-list-item a.hl-item-thumb[href][title]', { state: 'attached', timeout: 15000 });
|
||||
if (new URL(page.url()).origin !== new URL(link).origin) {
|
||||
throw new Error('Secshi redirected away from the requested source.');
|
||||
}
|
||||
return await page.content();
|
||||
} finally {
|
||||
await destroy();
|
||||
}
|
||||
}
|
||||
|
||||
async function getContent(link: string) {
|
||||
try {
|
||||
const initResponse = await ofetch.raw<string>(link, {
|
||||
ignoreResponseError: true,
|
||||
redirect: 'manual',
|
||||
});
|
||||
const cookie = initResponse.headers
|
||||
.getSetCookie()
|
||||
.map((c) => c.split(';', 1)[0])
|
||||
.join('; ');
|
||||
return initResponse.ok ? initResponse._data! : await ofetch<string>(link, { headers: { Cookie: cookie } });
|
||||
} catch (error) {
|
||||
if (!isExpiredCertificate(error)) {
|
||||
throw error;
|
||||
}
|
||||
return getBrowserContent(link);
|
||||
}
|
||||
}
|
||||
|
||||
export const route: Route = {
|
||||
path: '/:category?',
|
||||
@@ -14,6 +51,7 @@ export const route: Route = {
|
||||
| 1 | 2 | 3 | 4 | 5 | 30 |`,
|
||||
features: {
|
||||
antiCrawler: true,
|
||||
requirePuppeteer: true,
|
||||
},
|
||||
name: '分类',
|
||||
maintainers: ['8430177'],
|
||||
@@ -26,15 +64,7 @@ async function handler(ctx: Context): Promise<Data> {
|
||||
const baseUrl = 'https://www.secshi.com';
|
||||
const link = `${baseUrl}/go/${category}.html`;
|
||||
|
||||
const initResponse = await ofetch.raw<string>(link, {
|
||||
ignoreResponseError: true,
|
||||
redirect: 'manual',
|
||||
});
|
||||
const cookie = initResponse.headers
|
||||
.getSetCookie()
|
||||
.map((c) => c.split(';', 1)[0])
|
||||
.join('; ');
|
||||
const response = initResponse.ok ? initResponse._data! : await ofetch(link, { headers: { Cookie: cookie } });
|
||||
const response = await getContent(link);
|
||||
|
||||
const $ = load(response);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user