Update server.js
Browse files
server.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 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 |
|
|
@@ -23,10 +25,25 @@ app.get('/download-links', async (req, res) => {
|
|
| 23 |
}
|
| 24 |
});
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
async function getVideoLinks(downloadPageUrl) {
|
| 27 |
console.log(`Opening Playwright: ${downloadPageUrl}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
const browser = await chromium.launch({
|
| 29 |
headless: true,
|
|
|
|
| 30 |
args: [
|
| 31 |
"--no-sandbox",
|
| 32 |
"--disable-blink-features=AutomationControlled",
|
|
@@ -42,11 +59,11 @@ async function getVideoLinks(downloadPageUrl) {
|
|
| 42 |
await page.setViewportSize({ width: 1280, height: 720 });
|
| 43 |
|
| 44 |
// Navigate and wait for the page to fully load
|
| 45 |
-
await page.goto(downloadPageUrl, { waitUntil: '
|
| 46 |
|
| 47 |
-
// Wait
|
| 48 |
await page.waitForTimeout(5000);
|
| 49 |
-
await page.waitForSelector('a[href*="ggredi.info/download.php"]', { timeout:
|
| 50 |
|
| 51 |
// Extract video links
|
| 52 |
const videoLinks = await page.evaluate(() => {
|
|
@@ -81,9 +98,12 @@ async function getVideoLinks(downloadPageUrl) {
|
|
| 81 |
async function getFinalMp4Link(redirectLink) {
|
| 82 |
try {
|
| 83 |
console.log(`Following redirect: ${redirectLink}`);
|
| 84 |
-
const response = await fetch(redirectLink, { redirect: "follow" });
|
| 85 |
-
const finalUrl = response.url;
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
if (finalUrl && finalUrl.includes(".mp4")) {
|
| 88 |
console.log(`Final MP4 Link: ${finalUrl}`);
|
| 89 |
return finalUrl;
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
+
const { chromium } = require('playwright-core');
|
| 3 |
const cors = require('cors');
|
| 4 |
+
const { execSync } = require('child_process');
|
| 5 |
+
const axios = require('axios'); // Replaced fetch with axios
|
| 6 |
|
| 7 |
const app = express();
|
| 8 |
+
const PORT = process.env.PORT || 7860;
|
| 9 |
|
| 10 |
app.use(cors());
|
| 11 |
|
|
|
|
| 25 |
}
|
| 26 |
});
|
| 27 |
|
| 28 |
+
async function getChromiumPath() {
|
| 29 |
+
try {
|
| 30 |
+
return execSync("which chromium-browser || which google-chrome || which chromium")
|
| 31 |
+
.toString()
|
| 32 |
+
.trim();
|
| 33 |
+
} catch {
|
| 34 |
+
return null; // No system Chromium found
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
async function getVideoLinks(downloadPageUrl) {
|
| 39 |
console.log(`Opening Playwright: ${downloadPageUrl}`);
|
| 40 |
+
|
| 41 |
+
const chromiumPath = await getChromiumPath();
|
| 42 |
+
console.log(`Chromium Path: ${chromiumPath || "Using Playwright's default"}`);
|
| 43 |
+
|
| 44 |
const browser = await chromium.launch({
|
| 45 |
headless: true,
|
| 46 |
+
executablePath: chromiumPath || undefined, // Use found path or default
|
| 47 |
args: [
|
| 48 |
"--no-sandbox",
|
| 49 |
"--disable-blink-features=AutomationControlled",
|
|
|
|
| 59 |
await page.setViewportSize({ width: 1280, height: 720 });
|
| 60 |
|
| 61 |
// Navigate and wait for the page to fully load
|
| 62 |
+
await page.goto(downloadPageUrl, { waitUntil: 'domcontentloaded', timeout: 60000 });
|
| 63 |
|
| 64 |
+
// Wait for elements to appear (handles delays)
|
| 65 |
await page.waitForTimeout(5000);
|
| 66 |
+
await page.waitForSelector('a[href*="ggredi.info/download.php"]', { timeout: 15000 });
|
| 67 |
|
| 68 |
// Extract video links
|
| 69 |
const videoLinks = await page.evaluate(() => {
|
|
|
|
| 98 |
async function getFinalMp4Link(redirectLink) {
|
| 99 |
try {
|
| 100 |
console.log(`Following redirect: ${redirectLink}`);
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
// Use axios to follow redirects automatically
|
| 103 |
+
const response = await axios.get(redirectLink, { maxRedirects: 5 });
|
| 104 |
+
|
| 105 |
+
const finalUrl = response.request.res.responseUrl || response.config.url;
|
| 106 |
+
|
| 107 |
if (finalUrl && finalUrl.includes(".mp4")) {
|
| 108 |
console.log(`Final MP4 Link: ${finalUrl}`);
|
| 109 |
return finalUrl;
|