Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -49,9 +49,8 @@ app.get("/search", async (req, res) => {
|
|
| 49 |
// Step 1: Get first movie result (title & page link)
|
| 50 |
const movieData = await page.evaluate(() => {
|
| 51 |
const firstResult = document.querySelector(".mainbox a");
|
| 52 |
-
const title = firstResult ? firstResult.innerText.trim() : null;
|
| 53 |
const link = firstResult ? firstResult.href : null;
|
| 54 |
-
return
|
| 55 |
});
|
| 56 |
|
| 57 |
if (!movieData) {
|
|
@@ -60,7 +59,6 @@ app.get("/search", async (req, res) => {
|
|
| 60 |
return res.status(404).json({ error: "Movie not found" });
|
| 61 |
}
|
| 62 |
|
| 63 |
-
console.log(`Movie Found: ${movieData.title}`);
|
| 64 |
await page.goto(movieData.link, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 65 |
|
| 66 |
// Step 2: Extract the LAST download1.php link
|
|
@@ -123,17 +121,22 @@ app.get("/search", async (req, res) => {
|
|
| 123 |
return res.status(500).json({ error: "Failed to retrieve final download link" });
|
| 124 |
}
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
// **Remove everything after .mp4, .mkv, etc.**
|
| 127 |
const cleanedDownloadURL = finalDownloadURL.match(/(.*\.(mp4|mkv|avi))/i);
|
| 128 |
const finalLink = cleanedDownloadURL ? cleanedDownloadURL[1] : finalDownloadURL;
|
| 129 |
|
|
|
|
| 130 |
console.log(`Final Download Link: ${finalLink}`);
|
| 131 |
|
| 132 |
await browser.close();
|
| 133 |
|
| 134 |
// Return JSON response
|
| 135 |
return res.json({
|
| 136 |
-
movieTitle:
|
| 137 |
downloadLink: finalLink
|
| 138 |
});
|
| 139 |
|
|
|
|
| 49 |
// Step 1: Get first movie result (title & page link)
|
| 50 |
const movieData = await page.evaluate(() => {
|
| 51 |
const firstResult = document.querySelector(".mainbox a");
|
|
|
|
| 52 |
const link = firstResult ? firstResult.href : null;
|
| 53 |
+
return link ? { link } : null;
|
| 54 |
});
|
| 55 |
|
| 56 |
if (!movieData) {
|
|
|
|
| 59 |
return res.status(404).json({ error: "Movie not found" });
|
| 60 |
}
|
| 61 |
|
|
|
|
| 62 |
await page.goto(movieData.link, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 63 |
|
| 64 |
// Step 2: Extract the LAST download1.php link
|
|
|
|
| 121 |
return res.status(500).json({ error: "Failed to retrieve final download link" });
|
| 122 |
}
|
| 123 |
|
| 124 |
+
// Extract movie name from the filename in the URL
|
| 125 |
+
const filenameMatch = finalDownloadURL.match(/\/([^\/]+)\.(mp4|mkv|avi)/i);
|
| 126 |
+
const movieTitle = filenameMatch ? decodeURIComponent(filenameMatch[1]).replace(/[_\.-]/g, " ") : "Unknown Movie";
|
| 127 |
+
|
| 128 |
// **Remove everything after .mp4, .mkv, etc.**
|
| 129 |
const cleanedDownloadURL = finalDownloadURL.match(/(.*\.(mp4|mkv|avi))/i);
|
| 130 |
const finalLink = cleanedDownloadURL ? cleanedDownloadURL[1] : finalDownloadURL;
|
| 131 |
|
| 132 |
+
console.log(`Movie Title: ${movieTitle}`);
|
| 133 |
console.log(`Final Download Link: ${finalLink}`);
|
| 134 |
|
| 135 |
await browser.close();
|
| 136 |
|
| 137 |
// Return JSON response
|
| 138 |
return res.json({
|
| 139 |
+
movieTitle: movieTitle.trim(),
|
| 140 |
downloadLink: finalLink
|
| 141 |
});
|
| 142 |
|