Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -49,8 +49,7 @@ 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 |
-
|
| 53 |
-
return link ? { link } : null;
|
| 54 |
});
|
| 55 |
|
| 56 |
if (!movieData) {
|
|
@@ -59,6 +58,7 @@ app.get("/search", async (req, res) => {
|
|
| 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
|
|
@@ -100,15 +100,20 @@ app.get("/search", async (req, res) => {
|
|
| 100 |
return res.status(404).json({ error: "Redirected download link not found" });
|
| 101 |
}
|
| 102 |
|
| 103 |
-
// Step 5: Follow the redirection
|
| 104 |
let finalDownloadURL = null;
|
| 105 |
let retryAttempts = 2;
|
| 106 |
|
| 107 |
while (!finalDownloadURL && retryAttempts > 0) {
|
| 108 |
try {
|
| 109 |
const downloadPage = await context.newPage();
|
| 110 |
-
await downloadPage.goto(redirectedDownloadLink, {
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
await downloadPage.close();
|
| 113 |
} catch (err) {
|
| 114 |
console.warn(`Retrying... ${retryAttempts} attempts left`);
|
|
@@ -122,21 +127,21 @@ app.get("/search", async (req, res) => {
|
|
| 122 |
}
|
| 123 |
|
| 124 |
// Extract movie name from the filename in the URL
|
| 125 |
-
const filenameMatch = finalDownloadURL.match(/\/([^\/]+)\.(mp4|mkv|avi)/i);
|
| 126 |
let movieTitle = filenameMatch ? decodeURIComponent(filenameMatch[1]) : "Unknown Movie";
|
| 127 |
|
| 128 |
// **Clean up movie title**
|
| 129 |
movieTitle = movieTitle
|
| 130 |
.replace(/[_\.-]/g, " ") // Replace underscores and hyphens with spaces
|
| 131 |
-
.replace(/\b(BluRay|HD|720p|1080p|480p|fzmovies|net|mp4|mkv|avi)\b/gi, "") // Remove extra words
|
| 132 |
.replace(/\(\s*\)/g, "") // Remove empty parentheses
|
| 133 |
.replace(/\b(\d{4})\b.*\b\1\b/, "$1") // Remove duplicate years
|
| 134 |
.replace(/\s+/g, " ") // Remove extra spaces
|
| 135 |
.replace(/\b[a-f0-9]{32}\b/, "") // Remove hash codes (MD5-like)
|
| 136 |
.trim();
|
| 137 |
|
| 138 |
-
// **Remove everything after .mp4, .mkv,
|
| 139 |
-
const cleanedDownloadURL = finalDownloadURL.match(/(.*\.(mp4|mkv|
|
| 140 |
const finalLink = cleanedDownloadURL ? cleanedDownloadURL[1] : finalDownloadURL;
|
| 141 |
|
| 142 |
console.log(`Cleaned Movie Title: ${movieTitle}`);
|
|
|
|
| 49 |
// Step 1: Get first movie result (title & page link)
|
| 50 |
const movieData = await page.evaluate(() => {
|
| 51 |
const firstResult = document.querySelector(".mainbox a");
|
| 52 |
+
return firstResult ? { title: firstResult.innerText.trim(), link: firstResult.href } : null;
|
|
|
|
| 53 |
});
|
| 54 |
|
| 55 |
if (!movieData) {
|
|
|
|
| 58 |
return res.status(404).json({ error: "Movie not found" });
|
| 59 |
}
|
| 60 |
|
| 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
|
|
|
|
| 100 |
return res.status(404).json({ error: "Redirected download link not found" });
|
| 101 |
}
|
| 102 |
|
| 103 |
+
// Step 5: Follow the redirection and PRESERVE session cookies
|
| 104 |
let finalDownloadURL = null;
|
| 105 |
let retryAttempts = 2;
|
| 106 |
|
| 107 |
while (!finalDownloadURL && retryAttempts > 0) {
|
| 108 |
try {
|
| 109 |
const downloadPage = await context.newPage();
|
| 110 |
+
await downloadPage.goto(redirectedDownloadLink, {
|
| 111 |
+
waitUntil: "networkidle",
|
| 112 |
+
timeout: 60000
|
| 113 |
+
});
|
| 114 |
+
|
| 115 |
+
// Extract latest session-authenticated download link
|
| 116 |
+
finalDownloadURL = await downloadPage.evaluate(() => window.location.href);
|
| 117 |
await downloadPage.close();
|
| 118 |
} catch (err) {
|
| 119 |
console.warn(`Retrying... ${retryAttempts} attempts left`);
|
|
|
|
| 127 |
}
|
| 128 |
|
| 129 |
// Extract movie name from the filename in the URL
|
| 130 |
+
const filenameMatch = finalDownloadURL.match(/\/([^\/]+)\.(mp4|mkv|avi|mov)/i);
|
| 131 |
let movieTitle = filenameMatch ? decodeURIComponent(filenameMatch[1]) : "Unknown Movie";
|
| 132 |
|
| 133 |
// **Clean up movie title**
|
| 134 |
movieTitle = movieTitle
|
| 135 |
.replace(/[_\.-]/g, " ") // Replace underscores and hyphens with spaces
|
| 136 |
+
.replace(/\b(BluRay|HD|720p|1080p|480p|fzmovies|net|mp4|mkv|avi|mov)\b/gi, "") // Remove extra words
|
| 137 |
.replace(/\(\s*\)/g, "") // Remove empty parentheses
|
| 138 |
.replace(/\b(\d{4})\b.*\b\1\b/, "$1") // Remove duplicate years
|
| 139 |
.replace(/\s+/g, " ") // Remove extra spaces
|
| 140 |
.replace(/\b[a-f0-9]{32}\b/, "") // Remove hash codes (MD5-like)
|
| 141 |
.trim();
|
| 142 |
|
| 143 |
+
// **Remove everything after .mp4, .mkv, .avi, .mov**
|
| 144 |
+
const cleanedDownloadURL = finalDownloadURL.match(/(.*\.(mp4|mkv|avi|mov))/i);
|
| 145 |
const finalLink = cleanedDownloadURL ? cleanedDownloadURL[1] : finalDownloadURL;
|
| 146 |
|
| 147 |
console.log(`Cleaned Movie Title: ${movieTitle}`);
|