feat: Switched to playwright

This commit is contained in:
2024-08-18 10:26:28 +07:00
parent 0907e215b4
commit ca601e3248
3 changed files with 33 additions and 767 deletions

View File

@@ -50,7 +50,7 @@
"music-metadata": "^8.3.0",
"play-audio": "^0.5.2",
"play-dl": "github:YuzuZensai/play-dl-test#test",
"puppeteer": "^23.1.0",
"playwright": "^1.46.1",
"readable-web-to-node-stream": "^3.0.2",
"speaker": "^0.5.5",
"yt-dlp-wrap": "^2.3.12"

789
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
import puppeteer, { Browser } from "puppeteer";
import playwright, { Browser } from "playwright";
let browser: Browser | null = null;
@@ -59,7 +59,7 @@ export async function getStream(
export async function getYouTubeFormats(id: string) {
if (!browser) {
browser = await puppeteer.launch({
browser = await playwright["chromium"].launch({
headless: true,
args: [
"--disable-gpu",
@@ -82,10 +82,11 @@ export async function getYouTubeFormats(id: string) {
const page = await browser.newPage();
await page.goto(`https://www.youtube.com/watch?v=${id}&has_verified=1`, {
waitUntil: "networkidle2",
waitUntil: "domcontentloaded",
});
const body = await page.evaluate(() => document.body.innerHTML);
page.close();
await page.close();
await browser.close();
const match = body.match(
/var ytInitialPlayerResponse = (.*?)(?=;\s*<\/script>)/,