Update server.js
Browse files
server.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
-
const express = require(
|
| 2 |
-
const { chromium } = require(
|
| 3 |
-
const cors = require(
|
| 4 |
-
const { execSync } = require(
|
| 5 |
-
const axios = require(
|
| 6 |
|
| 7 |
const app = express();
|
| 8 |
const PORT = process.env.PORT || 7860;
|
| 9 |
|
| 10 |
app.use(cors());
|
| 11 |
|
| 12 |
-
app.get(
|
| 13 |
const { url } = req.query;
|
| 14 |
|
| 15 |
if (!url) {
|
|
@@ -43,46 +43,41 @@ async function getVideoLinks(downloadPageUrl) {
|
|
| 43 |
|
| 44 |
const browser = await chromium.launch({
|
| 45 |
headless: true,
|
| 46 |
-
executablePath: chromiumPath || undefined,
|
| 47 |
-
args: [
|
| 48 |
-
"--no-sandbox",
|
| 49 |
-
"--disable-blink-features=AutomationControlled",
|
| 50 |
-
"--disable-dev-shm-usage"
|
| 51 |
-
]
|
| 52 |
});
|
| 53 |
|
| 54 |
-
const
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
// Set a realistic user agent
|
| 58 |
-
await page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36");
|
| 59 |
-
await page.setViewportSize({ width: 1280, height: 720 });
|
| 60 |
|
| 61 |
-
|
| 62 |
-
await page.goto(downloadPageUrl, { waitUntil:
|
| 63 |
|
| 64 |
-
// Wait for
|
| 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(() =>
|
| 70 |
-
|
| 71 |
quality: link.innerText.trim(),
|
| 72 |
url: link.href
|
| 73 |
-
}))
|
| 74 |
-
|
| 75 |
|
| 76 |
await browser.close();
|
| 77 |
|
| 78 |
// Convert links to final MP4 links
|
| 79 |
const directDownloadLinks = {};
|
| 80 |
const promises = videoLinks
|
| 81 |
-
.filter(link => link.quality.includes(
|
| 82 |
.map(async link => {
|
| 83 |
const finalLink = await getFinalMp4Link(link.url);
|
| 84 |
if (finalLink) {
|
| 85 |
-
directDownloadLinks[link.quality.replace(/\D/g,
|
| 86 |
}
|
| 87 |
});
|
| 88 |
|
|
@@ -99,11 +94,10 @@ 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;
|
|
|
|
| 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"); // Using Axios for better redirect handling
|
| 6 |
|
| 7 |
const app = express();
|
| 8 |
const PORT = process.env.PORT || 7860;
|
| 9 |
|
| 10 |
app.use(cors());
|
| 11 |
|
| 12 |
+
app.get("/download-links", async (req, res) => {
|
| 13 |
const { url } = req.query;
|
| 14 |
|
| 15 |
if (!url) {
|
|
|
|
| 43 |
|
| 44 |
const browser = await chromium.launch({
|
| 45 |
headless: true,
|
| 46 |
+
executablePath: chromiumPath || undefined,
|
| 47 |
+
args: ["--no-sandbox", "--disable-blink-features=AutomationControlled", "--disable-dev-shm-usage"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
});
|
| 49 |
|
| 50 |
+
const context = await browser.newContext({
|
| 51 |
+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
|
| 52 |
+
});
|
| 53 |
|
| 54 |
+
const page = await context.newPage();
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
try {
|
| 57 |
+
await page.goto(downloadPageUrl, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 58 |
|
| 59 |
+
// Wait for the download buttons to load
|
| 60 |
await page.waitForTimeout(5000);
|
| 61 |
await page.waitForSelector('a[href*="ggredi.info/download.php"]', { timeout: 15000 });
|
| 62 |
|
| 63 |
// Extract video links
|
| 64 |
+
const videoLinks = await page.evaluate(() =>
|
| 65 |
+
Array.from(document.querySelectorAll('a[href*="ggredi.info/download.php"]')).map(link => ({
|
| 66 |
quality: link.innerText.trim(),
|
| 67 |
url: link.href
|
| 68 |
+
}))
|
| 69 |
+
);
|
| 70 |
|
| 71 |
await browser.close();
|
| 72 |
|
| 73 |
// Convert links to final MP4 links
|
| 74 |
const directDownloadLinks = {};
|
| 75 |
const promises = videoLinks
|
| 76 |
+
.filter(link => link.quality.includes("360") || link.quality.includes("720"))
|
| 77 |
.map(async link => {
|
| 78 |
const finalLink = await getFinalMp4Link(link.url);
|
| 79 |
if (finalLink) {
|
| 80 |
+
directDownloadLinks[link.quality.replace(/\D/g, "") + "p"] = finalLink;
|
| 81 |
}
|
| 82 |
});
|
| 83 |
|
|
|
|
| 94 |
try {
|
| 95 |
console.log(`Following redirect: ${redirectLink}`);
|
| 96 |
|
|
|
|
| 97 |
const response = await axios.get(redirectLink, { maxRedirects: 5 });
|
| 98 |
|
| 99 |
const finalUrl = response.request.res.responseUrl || response.config.url;
|
| 100 |
+
|
| 101 |
if (finalUrl && finalUrl.includes(".mp4")) {
|
| 102 |
console.log(`Final MP4 Link: ${finalUrl}`);
|
| 103 |
return finalUrl;
|