mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-06 04:33:21 +00:00
✨ feat: Puppeteer scraping
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
"music-metadata": "^8.3.0",
|
||||
"play-audio": "^0.5.2",
|
||||
"play-dl": "github:YuzuZensai/play-dl-test#test",
|
||||
"puppeteer": "^23.1.0",
|
||||
"readable-web-to-node-stream": "^3.0.2",
|
||||
"speaker": "^0.5.5",
|
||||
"yt-dlp-wrap": "^2.3.12"
|
||||
|
||||
764
pnpm-lock.yaml
generated
764
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,7 @@
|
||||
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
||||
import puppeteer, { Browser } from "puppeteer";
|
||||
|
||||
let browser: Browser | null = null;
|
||||
|
||||
export async function makeStreamRequest(
|
||||
url: string,
|
||||
@@ -55,12 +58,14 @@ export async function getStream(
|
||||
}
|
||||
|
||||
export async function getYouTubeFormats(id: string) {
|
||||
const new_url = `https://www.youtube.com/watch?v=${id}&has_verified=1`;
|
||||
const response = await axios.get(new_url, {
|
||||
headers: { "accept-language": "en-US,en;q=0.9" },
|
||||
withCredentials: true,
|
||||
if (!browser) browser = await puppeteer.launch();
|
||||
|
||||
const page = await browser.newPage();
|
||||
await page.goto(`https://www.youtube.com/watch?v=${id}&has_verified=1`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
const body = response.data;
|
||||
const body = await page.evaluate(() => document.body.innerHTML);
|
||||
await page.close();
|
||||
|
||||
const match = body.match(
|
||||
/var ytInitialPlayerResponse = (.*?)(?=;\s*<\/script>)/,
|
||||
|
||||
Reference in New Issue
Block a user