Reaperxxxx commited on
Commit
38faa33
·
verified ·
1 Parent(s): 22ee2b4

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +10 -10
server.js CHANGED
@@ -15,25 +15,25 @@ async function getDownloadLink(youtubeUrl) {
15
  let mp3DownloadLink = null;
16
 
17
  try {
 
 
 
 
 
 
 
 
 
18
  // Open the website
19
  await page.goto("https://ogmp3.com", { waitUntil: "domcontentloaded" });
20
 
21
  // Enter the YouTube link into the input field
22
  await page.fill("#url", youtubeUrl);
23
 
24
- // Intercept navigation events for the direct MP3 download
25
- page.on("framenavigated", async (frame) => {
26
- const url = frame.url();
27
- if (url.includes(".mp3")) {
28
- console.log("MP3 Detected:", url);
29
- mp3DownloadLink = url;
30
- }
31
- });
32
-
33
  // Click the convert/download button
34
  await page.click("#convert-button");
35
 
36
- // Wait up to 15 seconds for the MP3 link to appear
37
  await page.waitForTimeout(15000);
38
 
39
  } catch (error) {
 
15
  let mp3DownloadLink = null;
16
 
17
  try {
18
+ // Intercept all network requests to find the direct MP3 file
19
+ page.on("response", async (response) => {
20
+ const url = response.url();
21
+ if (url.includes(".mp3")) {
22
+ console.log("MP3 Link Found:", url);
23
+ mp3DownloadLink = url;
24
+ }
25
+ });
26
+
27
  // Open the website
28
  await page.goto("https://ogmp3.com", { waitUntil: "domcontentloaded" });
29
 
30
  // Enter the YouTube link into the input field
31
  await page.fill("#url", youtubeUrl);
32
 
 
 
 
 
 
 
 
 
 
33
  // Click the convert/download button
34
  await page.click("#convert-button");
35
 
36
+ // Wait up to 15 seconds for an MP3 request to appear
37
  await page.waitForTimeout(15000);
38
 
39
  } catch (error) {