ntah
const https = require('https');
const querystring = require('querystring');
const cheerio = require('cheerio');
async function Twmate(url) {
if (!url || typeof url !== 'string') throw new TypeError('URL tidak valid');
const postData = querystring.stringify({ page: url, ftype: 'all', ajax: '1' });
const options = {
hostname: 'twmate.com',
port: 443,
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Accept': '*/*',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Mobile Safari/537.36',
'Referer': 'https://twmate.com/',
'Content-Length': Buffer.byteLength(postData)
}
};
const html = await new Promise((resolve, reject) => {
const req = https.request(options, res => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => resolve(data));
});
req.on('error', reject);
req.write(postData);
req.end();
});
const $ = cheerio.load(html);
const result = {};
const title = $('.video-info h4').text().trim() || null;
const thumb = $('.thumb-container img').attr('src') || null;
const duration = $('.video-info p span').first().text().replace('Duration :', '').trim() || null;
const likes = $('.video-info p span').eq(1).text().replace('Likes :', '').trim() || null;
if (title) result.title = title;
if (thumb) result.thumb = thumb;
if (duration) result.duration = duration;
if (likes) result.likes = likes;
const videoRows = $('table.files-table tbody tr');
const imageCards = $('.card.icard');
const gifEls = $('video source, img.card_media');
const media = [];
if (videoRows.length > 0) {
videoRows.each((_, el) => {
const quality = $(el).find('td').eq(0).text().trim();
const type = $(el).find('td').eq(1).text().trim();
const link = $(el).find('a').attr('href');
if (link) media.push({ mediaType: 'video', quality, type, link });
});
result.type = 'video';
}
if (imageCards.length > 0) {
imageCards.each((_, el) => {
const imgSrc = $(el).find('img').attr('src');
$(el).find('a.btn-dl').each((_, a) => {
const link = $(a).attr('href');
const size = $(a).text().replace('Download', '').trim();
if (imgSrc && link) media.push({ mediaType: 'image', preview: imgSrc, size, link });
});
});
result.type = result.type === 'video' ? 'mixed' : 'image';
}
if (gifEls.length > 0) {
gifEls.each((_, el) => {
const src = $(el).attr('src') || $(el).attr('data-src');
if (src) media.push({ mediaType: 'gif', link: src });
});
result.type = result.type === 'video' || result.type === 'image' ? 'mixed' : 'gif';
}
result.media = media;
return result;
}
return Twmate("url")