| const axios = require('axios'); |
| const cheerio = require('cheerio'); |
| const crypto = require('crypto'); |
|
|
| async function twitterDownloader(url) { |
| try { |
| const urlParams = new URLSearchParams(url.split('?')[1]); |
| const tweetUrl = urlParams.get('url') || url; |
| const decodedUrl = decodeURIComponent(tweetUrl); |
|
|
| const timestamp = Math.floor(Date.now() / 1000); |
| const hash = crypto.createHash('md5'); |
| hash.update(timestamp.toString() + 'ssstwitter'); |
| const tt = hash.digest('hex'); |
|
|
| const postData = new URLSearchParams({ |
| 'id': decodedUrl, |
| 'locale': 'en', |
| 'tt': tt, |
| 'ts': timestamp.toString(), |
| 'source': 'form' |
| }); |
|
|
| const { data: html } = await axios.post('https://ssstwitter.com/', postData, { |
| headers: { |
| 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', |
| 'HX-Request': 'true', |
| 'HX-Target': 'target', |
| 'HX-Current-URL': 'https://ssstwitter.com/en-2', |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', |
| 'Origin': 'https://ssstwitter.com', |
| 'Referer': 'https://ssstwitter.com/en-2' |
| } |
| }); |
|
|
| const $ = cheerio.load(html); |
| const title = $('h2').first().text().trim(); |
| const downloads = []; |
|
|
| $('.download-btn').each((i, elem) => { |
| const $elem = $(elem); |
| const downloadUrl = $elem.attr('href'); |
| const qualityText = $elem.find('span').text().trim(); |
| const quality = qualityText.replace('Download', '').trim(); |
|
|
| if (downloadUrl && downloadUrl.startsWith('http')) { |
| downloads.push({ |
| quality: quality, |
| url: downloadUrl |
| }); |
| } |
| }); |
|
|
| const mediaType = downloads.length > 0 ? 'video' : 'unknown'; |
| const hdDownload = downloads.find(d => d.quality.includes('HD')) || downloads[0]; |
|
|
| return { |
| title: title || 'Twitter Media', |
| mediaType: mediaType, |
| downloads: downloads, |
| hdUrl: hdDownload ? hdDownload.url : null, |
| hdQuality: hdDownload ? hdDownload.quality : null |
| }; |
|
|
| } catch (error) { |
| throw new Error(error.message); |
| } |
| } |
|
|
| const handler = async (req, res) => { |
| try { |
| const { url } = req.query; |
| if (!url) { |
| return res.status(400).json({ |
| success: false, |
| error: 'Missing required parameter: url' |
| }); |
| } |
| const result = await twitterDownloader(url); |
| res.json({ |
| author: "Herza", |
| success: true, |
| msg: result |
| }); |
| } catch (error) { |
| res.status(500).json({ |
| success: false, |
| error: error.message |
| }); |
| } |
| }; |
|
|
| module.exports = { |
| name: 'Twitter DL', |
| description: 'Download Twitter/X Video and Images', |
| type: 'GET', |
| routes: ['api/download/twitter'], |
| tags: ['downloader', 'tools', 'misc'], |
| parameters: ['url', 'key'], |
| enabled: true, |
| main: ['Downloader'], |
| handler |
| }; |