Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -105,15 +105,16 @@ app.get("/api/direct", async (req, res) => {
|
|
| 105 |
browser = await puppeteer.launch({ headless: true, args: ["--no-sandbox"] });
|
| 106 |
const page = await browser.newPage();
|
| 107 |
|
|
|
|
| 108 |
await page.setUserAgent(
|
| 109 |
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
|
| 110 |
-
"(KHTML, like Gecko) Chrome/
|
| 111 |
);
|
| 112 |
|
| 113 |
-
// Step 1:
|
| 114 |
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 115 |
|
| 116 |
-
// Step 2:
|
| 117 |
const intermediate = await page.evaluate(() => {
|
| 118 |
const btn = document.querySelector("span.wildbutton");
|
| 119 |
if (!btn) return null;
|
|
@@ -127,16 +128,24 @@ app.get("/api/direct", async (req, res) => {
|
|
| 127 |
return res.status(404).json({ status: false, error: "Download link not found" });
|
| 128 |
}
|
| 129 |
|
| 130 |
-
// Step 3:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
let finalUrl = null;
|
| 132 |
page.on("response", (response) => {
|
| 133 |
-
if (response.status() === 302 || response.status() ===
|
| 134 |
-
const
|
| 135 |
-
if (
|
| 136 |
}
|
| 137 |
});
|
| 138 |
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
if (!finalUrl) {
|
| 142 |
return res.status(500).json({ status: false, error: "Final URL not found" });
|
|
@@ -145,7 +154,7 @@ app.get("/api/direct", async (req, res) => {
|
|
| 145 |
res.json({
|
| 146 |
status: true,
|
| 147 |
intermediate,
|
| 148 |
-
direct: finalUrl
|
| 149 |
});
|
| 150 |
} catch (err) {
|
| 151 |
res.status(500).json({ status: false, error: err.message });
|
|
|
|
| 105 |
browser = await puppeteer.launch({ headless: true, args: ["--no-sandbox"] });
|
| 106 |
const page = await browser.newPage();
|
| 107 |
|
| 108 |
+
// Set user agent
|
| 109 |
await page.setUserAgent(
|
| 110 |
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
|
| 111 |
+
"(KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
|
| 112 |
);
|
| 113 |
|
| 114 |
+
// Step 1: Go to main page
|
| 115 |
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 116 |
|
| 117 |
+
// Step 2: Extract the onclick link
|
| 118 |
const intermediate = await page.evaluate(() => {
|
| 119 |
const btn = document.querySelector("span.wildbutton");
|
| 120 |
if (!btn) return null;
|
|
|
|
| 128 |
return res.status(404).json({ status: false, error: "Download link not found" });
|
| 129 |
}
|
| 130 |
|
| 131 |
+
// Step 3: Set cookies (if any) from the current page
|
| 132 |
+
const cookies = await page.cookies();
|
| 133 |
+
await page.setCookie(...cookies);
|
| 134 |
+
|
| 135 |
+
// Step 4: Intercept response to catch final redirect URL
|
| 136 |
let finalUrl = null;
|
| 137 |
page.on("response", (response) => {
|
| 138 |
+
if (response.status() === 302 || response.status() === 301) {
|
| 139 |
+
const location = response.headers()['location'];
|
| 140 |
+
if (location && location.includes("dlws")) finalUrl = location;
|
| 141 |
}
|
| 142 |
});
|
| 143 |
|
| 144 |
+
// Step 5: Navigate to intermediate URL with headers
|
| 145 |
+
await page.goto(intermediate, {
|
| 146 |
+
waitUntil: "networkidle2",
|
| 147 |
+
timeout: 60000,
|
| 148 |
+
});
|
| 149 |
|
| 150 |
if (!finalUrl) {
|
| 151 |
return res.status(500).json({ status: false, error: "Final URL not found" });
|
|
|
|
| 154 |
res.json({
|
| 155 |
status: true,
|
| 156 |
intermediate,
|
| 157 |
+
direct: finalUrl,
|
| 158 |
});
|
| 159 |
} catch (err) {
|
| 160 |
res.status(500).json({ status: false, error: err.message });
|