mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-31 14:57:58 +00:00
✨ feat: Header and cookie spoof
This commit is contained in:
@@ -2,6 +2,8 @@ import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
|||||||
import playwright, { Browser } from "playwright";
|
import playwright, { Browser } from "playwright";
|
||||||
|
|
||||||
let browser: Browser | null = null;
|
let browser: Browser | null = null;
|
||||||
|
let globalHeaders: Record<string, string> = {};
|
||||||
|
let globalCookies: string = "";
|
||||||
|
|
||||||
export async function makeStreamRequest(
|
export async function makeStreamRequest(
|
||||||
url: string,
|
url: string,
|
||||||
@@ -9,11 +11,14 @@ export async function makeStreamRequest(
|
|||||||
body?: any,
|
body?: any,
|
||||||
): Promise<AxiosResponse> {
|
): Promise<AxiosResponse> {
|
||||||
const { headers = {}, method = "GET" } = options;
|
const { headers = {}, method = "GET" } = options;
|
||||||
|
|
||||||
let config: AxiosRequestConfig = {
|
let config: AxiosRequestConfig = {
|
||||||
url,
|
url,
|
||||||
method,
|
method,
|
||||||
headers,
|
headers: {
|
||||||
|
...globalHeaders,
|
||||||
|
...headers,
|
||||||
|
Cookie: globalCookies,
|
||||||
|
},
|
||||||
data: body,
|
data: body,
|
||||||
responseType: "stream",
|
responseType: "stream",
|
||||||
};
|
};
|
||||||
@@ -81,10 +86,21 @@ export async function getYouTubeFormats(id: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
page.once("request", (request) => {
|
||||||
|
globalHeaders = request.headers();
|
||||||
|
});
|
||||||
|
|
||||||
await page.goto(`https://www.youtube.com/watch?v=${id}&has_verified=1`, {
|
await page.goto(`https://www.youtube.com/watch?v=${id}&has_verified=1`, {
|
||||||
waitUntil: "domcontentloaded",
|
waitUntil: "domcontentloaded",
|
||||||
});
|
});
|
||||||
const body = await page.evaluate(() => document.body.innerHTML);
|
const body = await page.evaluate(() => document.body.innerHTML);
|
||||||
|
const cookies = await page.context().cookies();
|
||||||
|
|
||||||
|
globalCookies = cookies
|
||||||
|
.map((cookie) => `${cookie.name}=${cookie.value}`)
|
||||||
|
.join("; ");
|
||||||
|
|
||||||
await page.close();
|
await page.close();
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user