wudysoft commited on
Commit
e4c8d93
·
verified ·
1 Parent(s): 7e6bac7

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +52 -31
app.js CHANGED
@@ -29,37 +29,58 @@ app.get('/mediafire', async (req, res) => {
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
 
 
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