| const axios = require('axios'); | |
| async function fbdl(url) { | |
| if (!url) { | |
| return { | |
| author: "Herza", | |
| success: false, | |
| error: "URL is required" | |
| }; | |
| } | |
| try { | |
| const verifyResponse = await axios.post('https://fdownloader.net/api/userverify', | |
| `url=${encodeURIComponent(url)}`, | |
| { | |
| headers: { | |
| 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
| 'Accept': '*/*', | |
| 'X-Requested-With': 'XMLHttpRequest' | |
| } | |
| } | |
| ); | |
| if (!verifyResponse.data.success) { | |
| return { | |
| author: "Herza", | |
| success: false, | |
| error: 'User verification failed' | |
| }; | |
| } | |
| const token = verifyResponse.data.token; | |
| const currentTime = Math.floor(Date.now() / 1000); | |
| const k_exp = currentTime + 300; | |
| const searchResponse = await axios.post('https://v3.fdownloader.net/api/ajaxSearch', | |
| `k_exp=${k_exp}&k_token=${token.split('.')[2]}&q=${encodeURIComponent(url)}&lang=en&web=fdownloader.net&v=v2&w=&cftoken=${token}`, | |
| { | |
| headers: { | |
| 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
| 'Accept': '*/*' | |
| } | |
| } | |
| ); | |
| const htmlData = searchResponse.data.data; | |
| const titleMatch = htmlData.match(/<h3>(.+?)<\/h3>/); | |
| const durationMatch = htmlData.match(/<p>(\d+:\d+)<\/p>/); | |
| const thumbnailMatch = htmlData.match(/src="(https:\/\/scontent[^"]+)"/); | |
| const hdMatch = htmlData.match(/href="(https:\/\/dl\.snapcdn\.app\/download\?token=[^"]+)"[^>]*title="Download 720p \(HD\)"/); | |
| const sdMatch = htmlData.match(/href="(https:\/\/dl\.snapcdn\.app\/download\?token=[^"]+)"[^>]*title="Download 360p \(SD\)"/); | |
| return { | |
| author: 'Herza', | |
| success: true, | |
| data: { | |
| title: titleMatch ? titleMatch[1] : 'Facebook Video', | |
| duration: durationMatch ? durationMatch[1] : '0:00', | |
| thumbnail: thumbnailMatch ? thumbnailMatch[1].replace(/&/g, '&') : null, | |
| downloads: { | |
| hd: hdMatch ? hdMatch[1] : null, | |
| sd: sdMatch ? sdMatch[1] : null | |
| } | |
| } | |
| }; | |
| } catch (error) { | |
| return { | |
| author: 'Herza', | |
| success: false, | |
| error: error.message | |
| }; | |
| } | |
| } | |
| const handler = async (req, res) => { | |
| try { | |
| const { url } = req.query; | |
| if (!url) { | |
| return res.status(400).json({ | |
| author: "Herza", | |
| success: false, | |
| error: 'Missing required parameter: url' | |
| }); | |
| } | |
| const result = await fbdl(url); | |
| res.json(result); | |
| } catch (error) { | |
| res.status(500).json({ | |
| author: "Herza", | |
| success: false, | |
| error: error.message | |
| }); | |
| } | |
| }; | |
| module.exports = { | |
| name: 'Facebook DL', | |
| description: 'Download Facebook Video', | |
| type: 'GET', | |
| routes: ['api/download/fbdl'], | |
| tags: ['downloader', 'tools', 'misc'], | |
| parameters: ['url', 'key'], | |
| enabled: true, | |
| main: ['Downloader'], | |
| handler | |
| }; |