maylinejix commited on
Commit
2d2f9de
·
verified ·
1 Parent(s): 9c0c535

Update plugins/fbdl.js

Browse files
Files changed (1) hide show
  1. plugins/fbdl.js +32 -18
plugins/fbdl.js CHANGED
@@ -1,6 +1,10 @@
1
- const { chromium } = require('playwright');
2
  const axios = require('axios');
3
 
 
 
 
 
4
  async function fbdl(url) {
5
  if (!url) {
6
  return {
@@ -11,16 +15,14 @@ async function fbdl(url) {
11
  }
12
 
13
  try {
14
- const browser = await chromium.launch({
15
  headless: true,
16
  args: ['--no-sandbox', '--disable-setuid-sandbox']
17
  });
18
 
19
- const context = await browser.newContext({
20
- userAgent: 'Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.7444.171 Mobile Safari/537.36'
21
- });
22
 
23
- const page = await context.newPage();
24
 
25
  let downloadUrl = null;
26
  let apiResponse = null;
@@ -41,30 +43,40 @@ async function fbdl(url) {
41
  });
42
 
43
  await page.goto('https://www.hitube.io/id/facebook-video-download', {
44
- waitUntil: 'networkidle',
45
  timeout: 60000
46
  });
47
 
48
- await page.waitForTimeout(2000);
 
 
 
 
 
 
 
49
 
50
- const textarea = await page.locator('textarea[aria-label="Tempelkan tautan di sini"]');
51
- await textarea.fill(url);
52
 
53
- await page.waitForTimeout(1500);
 
 
 
54
 
55
- const downloadButton = await page.locator('button.search-btn:has-text("Download")');
56
- await downloadButton.click();
57
 
58
- await page.waitForTimeout(12000);
59
 
60
  try {
61
- const downloadFotoDiv = await page.locator('div.flex:has-text("Download Foto")').first();
62
- await downloadFotoDiv.waitFor({ state: 'visible', timeout: 30000 });
 
 
63
  } catch (e) {
64
  console.log('Download button not found, but may have captured URL');
65
  }
66
 
67
- await page.waitForTimeout(2000);
68
 
69
  await browser.close();
70
 
@@ -75,6 +87,7 @@ async function fbdl(url) {
75
  data: {
76
  url: downloadUrl,
77
  type: 'image/jpeg',
 
78
  apiResponse: apiResponse
79
  }
80
  };
@@ -87,7 +100,7 @@ async function fbdl(url) {
87
  };
88
 
89
  } catch (error) {
90
- console.log('Playwright failed, trying API fallback...');
91
  return await fbdlAPI(url);
92
  }
93
  }
@@ -126,6 +139,7 @@ async function fbdlAPI(url) {
126
  data: {
127
  url: downloadUrl,
128
  type: 'image/jpeg',
 
129
  token: token
130
  }
131
  };
 
1
+ const puppeteer = require('puppeteer');
2
  const axios = require('axios');
3
 
4
+ function wait(ms) {
5
+ return new Promise(resolve => setTimeout(resolve, ms));
6
+ }
7
+
8
  async function fbdl(url) {
9
  if (!url) {
10
  return {
 
15
  }
16
 
17
  try {
18
+ const browser = await puppeteer.launch({
19
  headless: true,
20
  args: ['--no-sandbox', '--disable-setuid-sandbox']
21
  });
22
 
23
+ const page = await browser.newPage();
 
 
24
 
25
+ await page.setUserAgent('Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.7444.171 Mobile Safari/537.36');
26
 
27
  let downloadUrl = null;
28
  let apiResponse = null;
 
43
  });
44
 
45
  await page.goto('https://www.hitube.io/id/facebook-video-download', {
46
+ waitUntil: 'networkidle2',
47
  timeout: 60000
48
  });
49
 
50
+ await wait(2000);
51
+
52
+ await page.waitForSelector('textarea[aria-label="Tempelkan tautan di sini"]', {
53
+ visible: true,
54
+ timeout: 10000
55
+ });
56
+
57
+ await page.type('textarea[aria-label="Tempelkan tautan di sini"]', url);
58
 
59
+ await wait(1500);
 
60
 
61
+ await page.waitForSelector('button.search-btn', {
62
+ visible: true,
63
+ timeout: 10000
64
+ });
65
 
66
+ await page.click('button.search-btn');
 
67
 
68
+ await wait(12000);
69
 
70
  try {
71
+ await page.waitForSelector('div.flex:has-text("Download Foto")', {
72
+ visible: true,
73
+ timeout: 30000
74
+ });
75
  } catch (e) {
76
  console.log('Download button not found, but may have captured URL');
77
  }
78
 
79
+ await wait(2000);
80
 
81
  await browser.close();
82
 
 
87
  data: {
88
  url: downloadUrl,
89
  type: 'image/jpeg',
90
+ method: 'puppeteer',
91
  apiResponse: apiResponse
92
  }
93
  };
 
100
  };
101
 
102
  } catch (error) {
103
+ console.log('Puppeteer failed, trying API fallback...', error.message);
104
  return await fbdlAPI(url);
105
  }
106
  }
 
139
  data: {
140
  url: downloadUrl,
141
  type: 'image/jpeg',
142
+ method: 'api',
143
  token: token
144
  }
145
  };