/** * ======================================================== * Name: Catbox.moe & Litterbox Scraper & Uploader Engine (Non-API) * * Cara Download: * curl -sL "https://code.vamxapi.my.id/snippet/raw/catbox-moe-scraper" -o catbox-moe-scraper.js * * Cara Eksekusi: * node catbox-moe-scraper.js "https://catbox.moe/c/8xw6g4" * node catbox-moe-scraper.js "/root/sample_struk.png" * node catbox-moe-scraper.js "https://httpbin.org/image/png" * node catbox-moe-scraper.js "https://files.catbox.moe/00koca.jpg" * * Author: Vamz Spectre * Source: https://vamxapi.my.id * ======================================================== */ import fs from 'node:fs'; import path from 'node:path'; import os from 'node:os'; import { execFileSync } from 'node:child_process'; const CATBOX_API = 'https://catbox.moe/user/api.php'; const LITTERBOX_API = 'https://litterbox.catbox.moe/resources/internals/api.php'; const MIME_MAP = { '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png', '.gif': 'image/gif', '.webp': 'image/webp', '.svg': 'image/svg+xml', '.bmp': 'image/bmp', '.ico': 'image/x-icon', '.mp4': 'video/mp4', '.webm': 'video/webm', '.mkv': 'video/x-matroska', '.avi': 'video/x-msvideo', '.mov': 'video/quicktime', '.mp3': 'audio/mpeg', '.wav': 'audio/wav', '.ogg': 'audio/ogg', '.m4a': 'audio/mp4', '.pdf': 'application/pdf', '.zip': 'application/zip', '.rar': 'application/x-rar-compressed', '.7z': 'application/x-7z-compressed', '.tar': 'application/x-tar', '.gz': 'application/gzip', '.json': 'application/json', '.txt': 'text/plain', '.csv': 'text/csv', '.html': 'text/html', '.xml': 'text/xml' }; const BACKUP_PROXIES = [ '45.195.91.219:8080', '103.165.155.22:2016', '157.15.67.175:3125', '103.176.96.23:8080' ]; /** * Format bytes into human-readable string */ function formatBytes(bytes) { if (!bytes || bytes <= 0) return '0 B'; const k = 1024; const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; } /** * Detect MIME type from file name or extension */ function getMimeType(filename) { const ext = path.extname(filename || '').toLowerCase(); return MIME_MAP[ext] || 'application/octet-stream'; } /** * Fetch fresh proxy list from proxyscrape API for IP datacenter bypass */ async function getLiveProxies() { try { const res = await fetch( 'https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=5000&country=all&ssl=yes&anonymity=all', { signal: AbortSignal.timeout(4000) } ); if (!res.ok) throw new Error('Proxy API unavailable'); const text = await res.text(); const list = text.split('\n').map((l) => l.trim()).filter(Boolean); return list.length ? list : BACKUP_PROXIES; } catch { return BACKUP_PROXIES; } } /** * Upload directly to Catbox.moe (Permanent Storage, Max 200MB) * Includes automated proxy tunnel bypass against datacenter 412 IP blocks. */ async function uploadToCatbox(fileBuffer, filename = 'upload.bin', userhash = '') { const mimeType = getMimeType(filename); // 1. Coba upload direct via Node native fetch try { const blob = new Blob([fileBuffer], { type: mimeType }); const form = new FormData(); form.append('reqtype', 'fileupload'); if (userhash) form.append('userhash', userhash); form.append('fileToUpload', blob, filename); const res = await fetch(CATBOX_API, { method: 'POST', headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', Origin: 'https://catbox.moe', Referer: 'https://catbox.moe/' }, body: form }); const responseText = (await res.text()).trim(); if (res.ok && responseText.startsWith('http')) { return { namefile: filename, link: responseText, duration: 'permanent' }; } } catch {} // 2. Jika IP datacenter/VPS terblokir (Invalid uploader), lakukan bypass via residential proxy pool const tempPath = path.join(os.tmpdir(), `catbox_${Date.now()}_${filename}`); fs.writeFileSync(tempPath, fileBuffer); try { const liveProxies = await getLiveProxies(); const proxies = [...BACKUP_PROXIES, ...liveProxies]; for (const proxy of proxies.slice(0, 8)) { try { const curlArgs = [ '-x', `http://${proxy}`, '--connect-timeout', '3', '-m', '8', '-s', '-F', 'reqtype=fileupload', ...(userhash ? ['-F', `userhash=${userhash}`] : []), '-F', `fileToUpload=@${tempPath}`, CATBOX_API ]; const output = execFileSync('curl', curlArgs, { encoding: 'utf8', timeout: 10000 }).trim(); if (output.startsWith('http')) { return { namefile: filename, link: output, duration: 'permanent' }; } } catch {} } } finally { try { if (fs.existsSync(tempPath)) fs.unlinkSync(tempPath); } catch {} } throw new Error('Gagal mengupload ke Catbox.moe (semua jalur bypass ditolak atau storage penuh).'); } /** * Upload buffer or blob to Litterbox (Catbox Temporary Storage, Max 1GB) */ async function uploadToLitterbox(fileBuffer, filename = 'upload.bin', time = '72h') { const validTimes = ['1h', '12h', '24h', '72h']; const expiryTime = validTimes.includes(time) ? time : '72h'; const mimeType = getMimeType(filename); const blob = new Blob([fileBuffer], { type: mimeType }); const form = new FormData(); form.append('reqtype', 'fileupload'); form.append('time', expiryTime); form.append('fileToUpload', blob, filename); const res = await fetch(LITTERBOX_API, { method: 'POST', headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', Origin: 'https://litterbox.catbox.moe', Referer: 'https://litterbox.catbox.moe/' }, body: form }); const responseText = (await res.text()).trim(); if (!res.ok || !responseText.startsWith('http')) { throw new Error(`Litterbox upload failed (${res.status}): ${responseText || res.statusText}`); } return { namefile: filename, link: responseText, duration: expiryTime }; } /** * Universal File Uploader */ async function uploadFile(input, options = {}) { let fileBuffer; let filename = options.filename; if (typeof input === 'string') { if (!fs.existsSync(input)) { throw new Error(`File lokal tidak ditemukan: "${input}"`); } fileBuffer = fs.readFileSync(input); if (!filename) { filename = path.basename(input); } } else if (Buffer.isBuffer(input) || input instanceof Uint8Array) { fileBuffer = Buffer.from(input); if (!filename) { filename = `upload_${Date.now()}.bin`; } } else { throw new Error('Input file harus berupa path string atau Buffer.'); } const service = (options.service || 'catbox').toLowerCase(); const time = options.time || '72h'; const userhash = options.userhash || ''; // Mode Litterbox Temporary (hanya jika diminta eksplisit) if (service === 'litterbox') { return await uploadToLitterbox(fileBuffer, filename, time); } // Default: Catbox Permanent (files.catbox.moe) try { return await uploadToCatbox(fileBuffer, filename, userhash); } catch (err) { // Jika Catbox benar-benar gagal total dan options.allowFallback diaktifkan if (options.fallback === true || options.service === 'auto') { const litterRes = await uploadToLitterbox(fileBuffer, filename, time); return { namefile: litterRes.namefile, link: litterRes.link, duration: litterRes.duration }; } throw err; } } /** * Re-host remote file URL directly to Catbox */ async function uploadUrl(remoteUrl, options = {}) { const cleanUrl = (remoteUrl || '').trim(); if (!cleanUrl.startsWith('http://') && !cleanUrl.startsWith('https://')) { throw new Error(`URL remote tidak valid: "${remoteUrl}"`); } const res = await fetch(cleanUrl, { headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' } }); if (!res.ok) { throw new Error(`Gagal mengunduh file remote (${res.status}): ${cleanUrl}`); } const arrayBuf = await res.arrayBuffer(); const buffer = Buffer.from(arrayBuf); let filename = options.filename; if (!filename) { try { const parsed = new URL(cleanUrl); const urlBase = path.basename(parsed.pathname); if (urlBase && urlBase.includes('.')) { filename = urlBase; } } catch {} } if (!filename) { const contentType = res.headers.get('content-type') || ''; let ext = '.bin'; for (const [key, val] of Object.entries(MIME_MAP)) { if (contentType.includes(val)) { ext = key; break; } } filename = `remote_${Date.now()}${ext}`; } return await uploadFile(buffer, { ...options, filename }); } /** * Scrape Catbox Album collection (https://catbox.moe/c/{shortcode}) */ async function getAlbum(albumUrlOrCode) { let code = (albumUrlOrCode || '').trim(); if (code.includes('catbox.moe/c/')) { const match = code.match(/catbox\.moe\/c\/([a-zA-Z0-9]+)/); if (match) code = match[1]; } if (!code || !/^[a-zA-Z0-9]+$/.test(code)) { throw new Error(`Kode album Catbox tidak valid: "${albumUrlOrCode}"`); } const albumUrl = `https://catbox.moe/c/${code}`; const res = await fetch(albumUrl, { headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' } }); if (!res.ok) { throw new Error(`Album "${code}" tidak ditemukan atau server error (${res.status})`); } const html = await res.text(); const titleMatch = html.match(/