UNPKG

notmebotz-tools

Version:

Sebuah Tools yang berfungsi untuk mendownload Video atau Foto dari media sosial, serta sebagai tools yang berguna untuk aplikasi kamu seperti untuk BOT

138 lines (119 loc) 5.11 kB
const cheerio = require('cheerio'); async function Tweets(url) { try { const xsaverUrl = `https://www.xsaver.io/download.php?url=${encodeURIComponent(url)}`; const response = await fetch(xsaverUrl, { headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate, br', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1' } }); if (!response.ok) { return { status: response.status, data: { author: "Herza", error: `HTTP ${response.status}: ${response.statusText}` } }; } const html = await response.text(); const $ = cheerio.load(html); const title = $('.video-title').text().trim() || $('.title').text().trim() || $('h1').text().trim() || $('title').text().trim() || 'Unknown Title'; const downloadLinks = []; const linkSelectors = [ 'a[href*="force-save.php"]', 'a[href*="save-url.php"]', 'a[href*="download"]', '.download-link a', '.btn-download' ]; linkSelectors.forEach(selector => { $(selector).each((index, element) => { const href = $(element).attr('href'); const linkText = $(element).text().trim(); if (href) { let type = 'unknown'; let downloadUrl = ''; const urlMatch = href.match(/url=([^&]+)/); if (urlMatch) { try { downloadUrl = decodeURIComponent(urlMatch[1]); } catch (e) { downloadUrl = urlMatch[1]; } } else if (href.startsWith('http')) { downloadUrl = href; } if (linkText.toLowerCase().includes('jpg') || linkText.toLowerCase().includes('jpeg') || linkText.toLowerCase().includes('png') || linkText.toLowerCase().includes('image') || downloadUrl.match(/\.(jpg|jpeg|png|gif|webp)($|\?)/i)) { type = 'image'; } else if (linkText.toLowerCase().includes('mp4') || linkText.toLowerCase().includes('video') || downloadUrl.match(/\.(mp4|avi|mov|wmv|flv|webm)($|\?)/i)) { type = 'video'; } else if (linkText.toLowerCase().includes('audio') || downloadUrl.match(/\.(mp3|wav|m4a|aac)($|\?)/i)) { type = 'audio'; } if (downloadUrl && !downloadLinks.some(link => link.url === downloadUrl)) { downloadLinks.push({ type: type, url: downloadUrl, text: linkText || 'Download', quality: linkText.match(/\d+p/i) ? linkText.match(/\d+p/i)[0] : null }); } } }); }); if (downloadLinks.length === 0) { $('a').each((index, element) => { const href = $(element).attr('href'); const linkText = $(element).text().trim(); if (href && (href.includes('mp4') || href.includes('jpg') || href.includes('jpeg') || href.includes('png'))) { let type = 'unknown'; if (href.match(/\.(jpg|jpeg|png|gif|webp)($|\?)/i)) { type = 'image'; } else if (href.match(/\.(mp4|avi|mov|wmv|flv|webm)($|\?)/i)) { type = 'video'; } downloadLinks.push({ type: type, url: href, text: linkText || 'Download' }); } }); } return { status: 200, data: { author: "Herza", title: title, downloads: downloadLinks.length > 0 ? downloadLinks : [], message: downloadLinks.length === 0 ? 'No download links found' : null } }; } catch (error) { return { status: 500, data: { author: "Herza", error: error.message } }; } } module.exports = { Tweets }