Spaces:
Paused
Paused
Update server.js
#1
by Reaperxxxx - opened
server.js
CHANGED
|
@@ -100,17 +100,35 @@ app.get("/search", async (req, res) => {
|
|
| 100 |
return res.status(404).json({ error: "Redirected download link not found" });
|
| 101 |
}
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
const downloadPage = await context.newPage();
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
|
| 108 |
-
const response = await downloadPage.waitForResponse(response => response.status() === 200);
|
| 109 |
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
await downloadPage.close();
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
// Extract movie name from filename in URL
|
| 115 |
let cleanedMovieTitle = movieData.title
|
| 116 |
.replace(/[_\.-]/g, " ") // Replace underscores and hyphens with spaces
|
|
|
|
| 100 |
return res.status(404).json({ error: "Redirected download link not found" });
|
| 101 |
}
|
| 102 |
|
| 103 |
+
console.log(`Redirecting to final download page: ${redirectedDownloadLink}`);
|
| 104 |
+
|
| 105 |
+
// Step 5: Follow the redirection, intercept network requests, and extract the REAL file URL
|
| 106 |
const downloadPage = await context.newPage();
|
| 107 |
+
let finalDownloadURL = null;
|
| 108 |
+
|
| 109 |
+
// Capture the final URL using network interception
|
| 110 |
+
downloadPage.on("response", async (response) => {
|
| 111 |
+
const url = response.url();
|
| 112 |
+
if (url.match(/\.(mp4|mkv|avi|mov)$/i)) {
|
| 113 |
+
console.log(`Final File Found: ${url}`);
|
| 114 |
+
finalDownloadURL = url;
|
| 115 |
+
}
|
| 116 |
+
});
|
| 117 |
|
| 118 |
+
await downloadPage.goto(redirectedDownloadLink, { waitUntil: "domcontentloaded", timeout: 60000 });
|
|
|
|
| 119 |
|
| 120 |
+
// If no final URL is found, check the current page URL (sometimes it's a direct link)
|
| 121 |
+
if (!finalDownloadURL) {
|
| 122 |
+
finalDownloadURL = downloadPage.url();
|
| 123 |
+
}
|
| 124 |
|
| 125 |
await downloadPage.close();
|
| 126 |
|
| 127 |
+
if (!finalDownloadURL) {
|
| 128 |
+
await browser.close();
|
| 129 |
+
return res.status(500).json({ error: "Failed to retrieve final download link" });
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
// Extract movie name from filename in URL
|
| 133 |
let cleanedMovieTitle = movieData.title
|
| 134 |
.replace(/[_\.-]/g, " ") // Replace underscores and hyphens with spaces
|