Reaperxxxx commited on
Commit
08fc82f
·
verified ·
1 Parent(s): 33a5f2d

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +7 -9
server.js CHANGED
@@ -1,19 +1,17 @@
1
  const express = require("express");
2
- const { chromium } = require("playwright");
3
- const cors = require("cors");
4
 
5
  const app = express();
6
  const PORT = 7860;
7
 
8
- app.use(cors());
9
-
10
  async function getDownloadLink(youtubeUrl) {
11
  const browser = await chromium.launch({
12
  headless: true,
13
- args: ["--no-sandbox", "--disable-setuid-sandbox"],
 
14
  });
15
-
16
  const page = await browser.newPage();
 
17
  let downloadLink = null;
18
 
19
  try {
@@ -23,7 +21,7 @@ async function getDownloadLink(youtubeUrl) {
23
  // Enter the YouTube link into the input field
24
  await page.fill("#url", youtubeUrl);
25
 
26
- // Listen for network responses to find the download URL
27
  page.on("response", async (response) => {
28
  const url = response.url();
29
  if (url.includes("safestytmp3.cc") && url.includes("/download/")) {
@@ -34,8 +32,8 @@ async function getDownloadLink(youtubeUrl) {
34
  // Click the convert/download button
35
  await page.click("#convert-button");
36
 
37
- // Wait for the download link to appear
38
- await page.waitForTimeout(15000);
39
 
40
  } catch (error) {
41
  console.error("Error:", error);
 
1
  const express = require("express");
2
+ const { chromium } = require("playwright-core");
 
3
 
4
  const app = express();
5
  const PORT = 7860;
6
 
 
 
7
  async function getDownloadLink(youtubeUrl) {
8
  const browser = await chromium.launch({
9
  headless: true,
10
+ executablePath: "/usr/bin/chromium", // Use system Chromium path in Docker
11
+ args: ["--no-sandbox", "--disable-setuid-sandbox"]
12
  });
 
13
  const page = await browser.newPage();
14
+
15
  let downloadLink = null;
16
 
17
  try {
 
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/")) {
 
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);