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