Reaperxxxx commited on
Commit
22ee2b4
·
verified ·
1 Parent(s): 08fc82f

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +11 -10
server.js CHANGED
@@ -12,7 +12,7 @@ async function getDownloadLink(youtubeUrl) {
12
  });
13
  const page = await browser.newPage();
14
 
15
- let downloadLink = null;
16
 
17
  try {
18
  // Open the website
@@ -21,19 +21,20 @@ async function getDownloadLink(youtubeUrl) {
21
  // Enter the YouTube link into the input field
22
  await page.fill("#url", youtubeUrl);
23
 
24
- // Intercept network responses to find the download URL
25
- page.on("response", async (response) => {
26
- const url = response.url();
27
- if (url.includes("safestytmp3.cc") && url.includes("/download/")) {
28
- downloadLink = url;
 
29
  }
30
  });
31
 
32
  // Click the convert/download button
33
  await page.click("#convert-button");
34
 
35
- // Wait for a maximum of 15 seconds for the download link to appear
36
- await new Promise((resolve) => setTimeout(resolve, 15000));
37
 
38
  } catch (error) {
39
  console.error("Error:", error);
@@ -41,7 +42,7 @@ async function getDownloadLink(youtubeUrl) {
41
  await browser.close();
42
  }
43
 
44
- return downloadLink;
45
  }
46
 
47
  // API Endpoint
@@ -60,7 +61,7 @@ app.get("/api/q", async (req, res) => {
60
  if (downloadLink) {
61
  res.json({ success: true, download_link: downloadLink });
62
  } else {
63
- res.status(404).json({ success: false, error: "No download link found" });
64
  }
65
  } catch (error) {
66
  console.error("Error processing the YouTube link:", error);
 
12
  });
13
  const page = await browser.newPage();
14
 
15
+ let mp3DownloadLink = null;
16
 
17
  try {
18
  // Open the website
 
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) {
40
  console.error("Error:", error);
 
42
  await browser.close();
43
  }
44
 
45
+ return mp3DownloadLink;
46
  }
47
 
48
  // API Endpoint
 
61
  if (downloadLink) {
62
  res.json({ success: true, download_link: downloadLink });
63
  } else {
64
+ res.status(404).json({ success: false, error: "No MP3 link found" });
65
  }
66
  } catch (error) {
67
  console.error("Error processing the YouTube link:", error);