Spaces:
Running
Running
Update plugins/fbdl.js
Browse files- plugins/fbdl.js +32 -18
plugins/fbdl.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
-
const
|
| 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
|
| 15 |
headless: true,
|
| 16 |
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
| 17 |
});
|
| 18 |
|
| 19 |
-
const
|
| 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 |
-
|
| 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: '
|
| 45 |
timeout: 60000
|
| 46 |
});
|
| 47 |
|
| 48 |
-
await
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
await textarea.fill(url);
|
| 52 |
|
| 53 |
-
await page.
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
await downloadButton.click();
|
| 57 |
|
| 58 |
-
await
|
| 59 |
|
| 60 |
try {
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
} catch (e) {
|
| 64 |
console.log('Download button not found, but may have captured URL');
|
| 65 |
}
|
| 66 |
|
| 67 |
-
await
|
| 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('
|
| 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 |
};
|