Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -25,7 +25,7 @@ app.get("/search", async (req, res) => {
|
|
| 25 |
console.log(`Chromium Path: ${chromiumPath || "Using Playwright's default"}`);
|
| 26 |
|
| 27 |
const browser = await chromium.launch({
|
| 28 |
-
headless: true,
|
| 29 |
executablePath: chromiumPath || undefined,
|
| 30 |
args: ["--no-sandbox", "--disable-blink-features=AutomationControlled", "--disable-dev-shm-usage"]
|
| 31 |
});
|
|
@@ -46,10 +46,10 @@ app.get("/search", async (req, res) => {
|
|
| 46 |
page.waitForNavigation({ waitUntil: "domcontentloaded", timeout: 60000 })
|
| 47 |
]);
|
| 48 |
|
| 49 |
-
// **Step 1: Get first movie result
|
| 50 |
const movieData = await page.evaluate(() => {
|
| 51 |
-
const
|
| 52 |
-
return
|
| 53 |
});
|
| 54 |
|
| 55 |
if (!movieData) {
|
|
@@ -61,25 +61,33 @@ app.get("/search", async (req, res) => {
|
|
| 61 |
console.log(`✅ Movie Found: ${movieData.title}`);
|
| 62 |
await page.goto(movieData.link, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 63 |
|
| 64 |
-
// **Step 2:
|
| 65 |
-
await page.
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
const finalDownloadPage = await page.evaluate(() => {
|
| 70 |
const links = document.querySelectorAll('a[href*="download.php?downloadkey="]');
|
| 71 |
return links.length ? links[links.length - 1].href : null;
|
| 72 |
});
|
| 73 |
|
| 74 |
if (!finalDownloadPage) {
|
| 75 |
-
console.log("❌ No final download page found!");
|
| 76 |
await browser.close();
|
| 77 |
return res.status(404).json({ error: "Final download page not found" });
|
| 78 |
}
|
| 79 |
|
| 80 |
await page.goto(finalDownloadPage, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 81 |
|
| 82 |
-
// **Step 4: Extract redirection link (dlink.php)**
|
| 83 |
let redirectedDownloadLink = await page.evaluate(() => {
|
| 84 |
const links = document.querySelectorAll('a[href*="dlink.php?id="]');
|
| 85 |
return links.length ? links[links.length - 1].href : null;
|
|
@@ -100,15 +108,17 @@ app.get("/search", async (req, res) => {
|
|
| 100 |
while (!finalDownloadURL && retryAttempts > 0) {
|
| 101 |
try {
|
| 102 |
const downloadPage = await context.newPage();
|
| 103 |
-
await downloadPage.goto(redirectedDownloadLink, { waitUntil: "
|
| 104 |
|
| 105 |
-
// **Check for session expiration
|
| 106 |
if (await downloadPage.evaluate(() => document.body.innerText.includes("Your previous session has expired"))) {
|
| 107 |
console.warn("⚠️ Session expired! Restarting...");
|
|
|
|
|
|
|
| 108 |
await page.goto(movieData.link, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 109 |
|
| 110 |
await page.click('a[href*="download1.php?downloadoptionskey="]');
|
| 111 |
-
await page.
|
| 112 |
|
| 113 |
redirectedDownloadLink = await page.evaluate(() => {
|
| 114 |
const links = document.querySelectorAll('a[href*="dlink.php?id="]');
|
|
|
|
| 25 |
console.log(`Chromium Path: ${chromiumPath || "Using Playwright's default"}`);
|
| 26 |
|
| 27 |
const browser = await chromium.launch({
|
| 28 |
+
headless: true,
|
| 29 |
executablePath: chromiumPath || undefined,
|
| 30 |
args: ["--no-sandbox", "--disable-blink-features=AutomationControlled", "--disable-dev-shm-usage"]
|
| 31 |
});
|
|
|
|
| 46 |
page.waitForNavigation({ waitUntil: "domcontentloaded", timeout: 60000 })
|
| 47 |
]);
|
| 48 |
|
| 49 |
+
// **Step 1: Get first movie result**
|
| 50 |
const movieData = await page.evaluate(() => {
|
| 51 |
+
const results = document.querySelectorAll(".mainbox a");
|
| 52 |
+
return results.length ? { title: results[0].innerText.trim(), link: results[0].href } : null;
|
| 53 |
});
|
| 54 |
|
| 55 |
if (!movieData) {
|
|
|
|
| 61 |
console.log(`✅ Movie Found: ${movieData.title}`);
|
| 62 |
await page.goto(movieData.link, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 63 |
|
| 64 |
+
// **Step 2: Extract the LAST download1.php link**
|
| 65 |
+
const downloadPageLink = await page.evaluate(() => {
|
| 66 |
+
const links = document.querySelectorAll('a[href*="download1.php?downloadoptionskey="]');
|
| 67 |
+
return links.length ? links[links.length - 1].href : null;
|
| 68 |
+
});
|
| 69 |
|
| 70 |
+
if (!downloadPageLink) {
|
| 71 |
+
await browser.close();
|
| 72 |
+
return res.status(404).json({ error: "Download page not found" });
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
await page.goto(downloadPageLink, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 76 |
+
|
| 77 |
+
// **Step 3: Extract "download.php" page link (LAST one)**
|
| 78 |
const finalDownloadPage = await page.evaluate(() => {
|
| 79 |
const links = document.querySelectorAll('a[href*="download.php?downloadkey="]');
|
| 80 |
return links.length ? links[links.length - 1].href : null;
|
| 81 |
});
|
| 82 |
|
| 83 |
if (!finalDownloadPage) {
|
|
|
|
| 84 |
await browser.close();
|
| 85 |
return res.status(404).json({ error: "Final download page not found" });
|
| 86 |
}
|
| 87 |
|
| 88 |
await page.goto(finalDownloadPage, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 89 |
|
| 90 |
+
// **Step 4: Extract LAST redirection link (dlink.php)**
|
| 91 |
let redirectedDownloadLink = await page.evaluate(() => {
|
| 92 |
const links = document.querySelectorAll('a[href*="dlink.php?id="]');
|
| 93 |
return links.length ? links[links.length - 1].href : null;
|
|
|
|
| 108 |
while (!finalDownloadURL && retryAttempts > 0) {
|
| 109 |
try {
|
| 110 |
const downloadPage = await context.newPage();
|
| 111 |
+
await downloadPage.goto(redirectedDownloadLink, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 112 |
|
| 113 |
+
// **Check for session expiration**
|
| 114 |
if (await downloadPage.evaluate(() => document.body.innerText.includes("Your previous session has expired"))) {
|
| 115 |
console.warn("⚠️ Session expired! Restarting...");
|
| 116 |
+
|
| 117 |
+
// Restart from the movie page
|
| 118 |
await page.goto(movieData.link, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 119 |
|
| 120 |
await page.click('a[href*="download1.php?downloadoptionskey="]');
|
| 121 |
+
await page.waitForSelector('a[href*="dlink.php?id="]', { timeout: 60000 });
|
| 122 |
|
| 123 |
redirectedDownloadLink = await page.evaluate(() => {
|
| 124 |
const links = document.querySelectorAll('a[href*="dlink.php?id="]');
|