Added Cookie.ts. Changed request changes.
This commit is contained in:
parent
46253bad0c
commit
c8ad3387c5
|
@ -0,0 +1,22 @@
|
|||
export interface Cookie {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export function makeCookieHeader(cookies: Record<string, string>): string {
|
||||
return Object.entries(cookies)
|
||||
.map(([name, value]) => `${name}=${value}`)
|
||||
.join('; ');
|
||||
}
|
||||
|
||||
export function parseSetCookie(headerValue: string): Record<string, Cookie> {
|
||||
const cookies: Record<string, Cookie> = {};
|
||||
const parts = headerValue.split(/; */);
|
||||
for (const part of parts) {
|
||||
const [name, value] = part.split('=');
|
||||
if (name && value) {
|
||||
cookies[name] = { name, value };
|
||||
}
|
||||
}
|
||||
return cookies;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import { makeCookieHeader, parseSetCookie } from '@/entrypoint/utils/cookie';
|
||||
import { flags } from '@/entrypoint/utils/targets';
|
||||
import { makeEmbed } from '@/providers/base';
|
||||
|
||||
|
@ -15,7 +16,8 @@ export const wootlyScraper = makeEmbed({
|
|||
readHeaders: ['Set-Cookie'],
|
||||
});
|
||||
|
||||
const wootssesCookie = wootlyData.headers.get('Set-Cookie')?.match(/wootsses=([^;]+)/)?.[1];
|
||||
const cookies = parseSetCookie(wootlyData.headers.get('Set-Cookie') || '');
|
||||
const wootssesCookie = cookies.wootsses.value;
|
||||
|
||||
let $ = load(wootlyData.body); // load the html data
|
||||
const iframeSrc = $('iframe').attr('src') ?? '';
|
||||
|
@ -24,17 +26,18 @@ export const wootlyScraper = makeEmbed({
|
|||
method: 'GET',
|
||||
readHeaders: ['Set-Cookie'],
|
||||
headers: {
|
||||
cookie: `wootsses=${wootssesCookie};`,
|
||||
cookie: makeCookieHeader({ wootsses: wootssesCookie }),
|
||||
},
|
||||
});
|
||||
|
||||
const woozCookie = woozCookieRequest.headers.get('Set-Cookie')?.match(/wooz=([^;]+)/)?.[1];
|
||||
const woozCookies = parseSetCookie(woozCookieRequest.headers.get('Set-Cookie') || '');
|
||||
const woozCookie = woozCookies.wooz.value;
|
||||
|
||||
const iframeData = await ctx.proxiedFetcher<string>(iframeSrc, {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams({ qdf: '1' }),
|
||||
headers: {
|
||||
cookie: `wooz=${woozCookie}`,
|
||||
cookie: makeCookieHeader({ wooz: woozCookie }),
|
||||
Referer: iframeSrc,
|
||||
},
|
||||
});
|
||||
|
@ -44,7 +47,6 @@ export const wootlyScraper = makeEmbed({
|
|||
const scriptText = $('script').html() ?? '';
|
||||
|
||||
// Regular expressions to match the variables
|
||||
|
||||
const tk = scriptText.match(/tk=([^;]+)/)?.[0].replace(/tk=|["\s]/g, '');
|
||||
const vd = scriptText.match(/vd=([^,]+)/)?.[0].replace(/vd=|["\s]/g, '');
|
||||
|
||||
|
@ -55,7 +57,7 @@ export const wootlyScraper = makeEmbed({
|
|||
query: { t: tk, id: vd },
|
||||
method: 'GET',
|
||||
headers: {
|
||||
cookie: `wooz=${woozCookie}; wootsses=${wootssesCookie};`,
|
||||
cookie: makeCookieHeader({ wooz: woozCookie, wootsses: wootssesCookie }),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import { makeCookieHeader, parseSetCookie } from '@/entrypoint/utils/cookie';
|
||||
import { ScrapeContext } from '@/utils/context';
|
||||
|
||||
import { EmbedsResult, baseUrl, baseUrl2 } from './type';
|
||||
|
@ -14,7 +15,8 @@ export async function getEmbeds(ctx: ScrapeContext, id: string): Promise<EmbedsR
|
|||
method: 'GET',
|
||||
});
|
||||
|
||||
const aGoozCookie = data.headers.get('Set-Cookie')?.match(/aGooz=([^;]+)/)?.[1];
|
||||
const cookies = parseSetCookie(data.headers.get('Set-Cookie') || '');
|
||||
const aGoozCookie = cookies.aGooz.value;
|
||||
|
||||
const $ = load(data.body);
|
||||
const RandomCookieName = data.body.split(`_3chk('`)[1].split(`'`)[0];
|
||||
|
@ -31,7 +33,10 @@ export async function getEmbeds(ctx: ScrapeContext, id: string): Promise<EmbedsR
|
|||
ctx.fetcher
|
||||
.full(url, {
|
||||
headers: {
|
||||
cookie: `aGooz=${aGoozCookie}; ${RandomCookieName}=${RandomCookieValue};`,
|
||||
cookie: makeCookieHeader({
|
||||
aGooz: aGoozCookie,
|
||||
[RandomCookieName]: RandomCookieValue,
|
||||
}),
|
||||
Referer: baseUrl2,
|
||||
},
|
||||
method: 'GET',
|
||||
|
@ -45,11 +50,8 @@ export async function getEmbeds(ctx: ScrapeContext, id: string): Promise<EmbedsR
|
|||
|
||||
// Process each page result
|
||||
for (const result of embedPages) {
|
||||
// Ensure there's a result to process
|
||||
if (result) {
|
||||
// Attempt to find a matching embed ID
|
||||
const embedId = ['wootly', 'upstream', 'mixdrop', 'dood'].find((a) => result.finalUrl.includes(a));
|
||||
// If an embed ID is found, push the result to the results array
|
||||
if (embedId) {
|
||||
results.push({ embedId, url: result.finalUrl });
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue