Update app.js
Browse files
app.js
CHANGED
|
@@ -28,86 +28,38 @@ app.get('/mediafire', async (req, res) => {
|
|
| 28 |
}
|
| 29 |
});
|
| 30 |
|
| 31 |
-
// Function to handle MediaFire download info extraction
|
| 32 |
async function mediafire(url) {
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
if (fileNameMatch) {
|
| 65 |
-
jsonResult.fileName = fileNameMatch[1];
|
| 66 |
-
}
|
| 67 |
-
if (downloadLinkMatch) {
|
| 68 |
-
jsonResult.downloadLink = downloadLinkMatch[1];
|
| 69 |
-
}
|
| 70 |
-
if (fileSizeMatch) {
|
| 71 |
-
jsonResult.fileSize = fileSizeMatch[1];
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
return jsonResult;
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
// Function to fetch the MediaFire page and extract data
|
| 78 |
-
async function data(url) {
|
| 79 |
-
const browser = await chromium.launch({ headless: true });
|
| 80 |
-
const context = await browser.newContext({
|
| 81 |
-
userAgent: 'Mozilla/5.0 (Linux; Android 6.0; iris50) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36'
|
| 82 |
-
});
|
| 83 |
-
const page = await context.newPage();
|
| 84 |
-
|
| 85 |
-
try {
|
| 86 |
-
await page.goto(url);
|
| 87 |
-
const downloadInfo = await page.evaluate(() => {
|
| 88 |
-
const fileNameElement = document.querySelector('.dl-btn-label');
|
| 89 |
-
const fileName = fileNameElement ? fileNameElement.textContent.trim() : '';
|
| 90 |
-
const downloadLinkElement = document.querySelector('#downloadButton');
|
| 91 |
-
const downloadLink = downloadLinkElement ? downloadLinkElement.href : '';
|
| 92 |
-
const fileSizeText = downloadLinkElement ? downloadLinkElement.textContent : '';
|
| 93 |
-
const sizeMatch = fileSizeText.match(/\$([^)]+)\$/);
|
| 94 |
-
const fileSize = sizeMatch ? sizeMatch[1] : '';
|
| 95 |
-
|
| 96 |
-
return {
|
| 97 |
-
fileName: fileName,
|
| 98 |
-
downloadLink: downloadLink,
|
| 99 |
-
fileSize: fileSize
|
| 100 |
-
};
|
| 101 |
-
});
|
| 102 |
-
|
| 103 |
-
return downloadInfo;
|
| 104 |
-
} catch (error) {
|
| 105 |
-
console.error('Error:', error);
|
| 106 |
-
throw new Error('Failed to fetch or parse the MediaFire page');
|
| 107 |
-
} finally {
|
| 108 |
-
await browser.close();
|
| 109 |
-
}
|
| 110 |
-
}
|
| 111 |
|
| 112 |
const PORT = process.env.PORT || 7860;
|
| 113 |
|
|
|
|
| 28 |
}
|
| 29 |
});
|
| 30 |
|
|
|
|
| 31 |
async function mediafire(url) {
|
| 32 |
+
const browser = await chromium.launch({ headless: true });
|
| 33 |
+
const context = await browser.newContext({
|
| 34 |
+
userAgent: 'Mozilla/5.0 (Linux; Android 6.0; iris50) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36'
|
| 35 |
+
});
|
| 36 |
+
const page = await context.newPage();
|
| 37 |
+
try {
|
| 38 |
+
await page.goto(url);
|
| 39 |
+
const downloadInfo = await page.evaluate(() => {
|
| 40 |
+
const fileNameElement = document.querySelector('.dl-btn-label');
|
| 41 |
+
const fileName = fileNameElement ? fileNameElement.textContent.trim() : '';
|
| 42 |
+
const downloadLinkElement = document.querySelector('#downloadButton');
|
| 43 |
+
const downloadLink = downloadLinkElement ? downloadLinkElement.href : '';
|
| 44 |
+
const fileSizeText = downloadLinkElement ? downloadLinkElement.textContent : '';
|
| 45 |
+
const sizeMatch = fileSizeText.match(/\\$([^)]+)\\$/);
|
| 46 |
+
const fileSize = sizeMatch ? sizeMatch[1] : '';
|
| 47 |
+
|
| 48 |
+
return {
|
| 49 |
+
fileName: fileName,
|
| 50 |
+
downloadLink: downloadLink,
|
| 51 |
+
fileSize: fileSize
|
| 52 |
+
};
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
return downloadInfo;
|
| 56 |
+
} catch (error) {
|
| 57 |
+
console.error("Error:", error.response ? error.response.data : error.message);
|
| 58 |
+
return { success: false, message: error.message };
|
| 59 |
+
} finally {
|
| 60 |
+
await browser.close();
|
| 61 |
+
}
|
| 62 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
const PORT = process.env.PORT || 7860;
|
| 65 |
|