Update app.js
Browse files
app.js
CHANGED
|
@@ -29,37 +29,58 @@ app.get('/mediafire', async (req, res) => {
|
|
| 29 |
});
|
| 30 |
|
| 31 |
async function mediafire(url) {
|
| 32 |
-
|
| 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 |
const PORT = process.env.PORT || 7860;
|
| 65 |
|
|
|
|
| 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 |
+
|
| 38 |
+
try {
|
| 39 |
+
await page.goto(url);
|
| 40 |
+
|
| 41 |
+
let downloadInfo = await page.evaluate(() => {
|
| 42 |
+
const fileName = document.querySelector('.dl-btn-label')?.textContent?.trim() || '';
|
| 43 |
+
const downloadLink = document.querySelector('#downloadButton')?.href || '';
|
| 44 |
+
const fileSizeText = document.querySelector('#downloadButton')?.textContent || '';
|
| 45 |
+
const sizeMatch = fileSizeText.match(/\$([^)]+)\$/);
|
| 46 |
+
const fileSize = sizeMatch ? sizeMatch[1] : '';
|
| 47 |
+
|
| 48 |
+
// Ambil informasi meta
|
| 49 |
+
const metaTags = Array.from(document.querySelectorAll('meta')).reduce((acc, meta) => {
|
| 50 |
+
const name = meta.getAttribute('name') || meta.getAttribute('property');
|
| 51 |
+
const content = meta.getAttribute('content');
|
| 52 |
+
if (name && content) acc[name] = content;
|
| 53 |
+
return acc;
|
| 54 |
+
}, {});
|
| 55 |
+
|
| 56 |
+
return {
|
| 57 |
+
fileName,
|
| 58 |
+
downloadLink,
|
| 59 |
+
fileSize,
|
| 60 |
+
meta: metaTags,
|
| 61 |
+
};
|
| 62 |
+
});
|
| 63 |
+
|
| 64 |
+
// Jika tautan unduhan tidak valid, buka tautan baru
|
| 65 |
+
if (!downloadInfo.downloadLink.startsWith('https://down')) {
|
| 66 |
+
await page.goto(downloadInfo.downloadLink);
|
| 67 |
+
|
| 68 |
+
const updatedInfo = await page.evaluate(() => {
|
| 69 |
+
const downloadLink = document.querySelector('#downloadButton')?.href || '';
|
| 70 |
+
return { downloadLink };
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
downloadInfo.downloadLink = updatedInfo.downloadLink;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
return downloadInfo;
|
| 77 |
+
} catch (error) {
|
| 78 |
+
console.error('Error:', error.message);
|
| 79 |
+
return { success: false, message: error.message };
|
| 80 |
+
} finally {
|
| 81 |
+
await browser.close();
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
|
| 85 |
const PORT = process.env.PORT || 7860;
|
| 86 |
|