/** * ======================================================== * 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(/
\s*

(.*?)<\/h1>/i) || html.match(/(.*?)<\/title>/i); const title = titleMatch ? titleMatch[1].trim() : 'Untitled Album'; const dateMatch = html.match(/<p>\s*Created\s+(.*?)\s*<\/p>/i); const createdAt = dateMatch ? dateMatch[1].trim() : null; let description = ''; const descMatch = html.match( /<div class="title">[\s\S]*?<p>[^<]*<\/p>\s*<p>(.*?)<\/p>/i ); if (descMatch && descMatch[1].trim()) { description = descMatch[1].trim(); } const files = []; const linkRegex = /<a[^>]+href=[\x27"](https?:\/\/files\.catbox\.moe\/([^\x27"\s>]+))[\x27"][^>]*>([\s\S]*?)<\/a>/gi; let match; const seenUrls = new Set(); while ((match = linkRegex.exec(html)) !== null) { const fileUrl = match[1]; const filename = match[2]; const innerHtml = match[3] || ''; if (seenUrls.has(fileUrl)) continue; seenUrls.add(fileUrl); let thumbUrl = null; const thumbMatch = innerHtml.match( /src=[\x27"](https?:\/\/files\.catbox\.moe\/thumbs\/[^\x27"\s>]+)[\x27"]/i ); if (thumbMatch) { thumbUrl = thumbMatch[1]; } files.push({ filename, url: fileUrl, thumbnail: thumbUrl, ext: path.extname(filename).toLowerCase().replace('.', ''), mime_type: getMimeType(filename) }); } return { status: true, code, album_url: albumUrl, title, created_at: createdAt, description: description || null, total_files: files.length, files }; } /** * Inspect file metadata on Catbox or Litterbox */ async function inspectFile(fileUrl) { const cleanUrl = (fileUrl || '').trim(); if (!cleanUrl.startsWith('http://') && !cleanUrl.startsWith('https://')) { throw new Error(`URL file tidak valid: "${fileUrl}"`); } const res = await fetch(cleanUrl, { method: 'GET', headers: { Range: 'bytes=0-0', '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' } }); const isAlive = res.status === 200 || res.status === 206; const contentType = res.headers.get('content-type') || 'application/octet-stream'; const rangeHeader = res.headers.get('content-range') || ''; const totalMatch = rangeHeader.match(/\/(\d+)/); const size = totalMatch ? parseInt(totalMatch[1], 10) : parseInt(res.headers.get('content-length') || '0', 10); const filename = path.basename(new URL(cleanUrl).pathname); const isLitter = cleanUrl.includes('litter.catbox.moe'); return { status: true, alive: isAlive, http_code: res.status, url: cleanUrl, filename, host: isLitter ? 'litter.catbox.moe' : 'files.catbox.moe', service: isLitter ? 'litterbox (temporary)' : 'catbox (permanent)', content_type: contentType, size_bytes: size, size_formatted: formatBytes(size), last_modified: res.headers.get('last-modified') || null }; } /** * Universal Scraper Dispatcher */ async function catbox(commandOrInput, options = {}) { const input = (commandOrInput || '').trim(); if (!input) { throw new Error( 'Parameter input URL, file path, atau album ID wajib disertakan!' ); } if (options.action === 'album') return await getAlbum(input); if (options.action === 'inspect') return await inspectFile(input); if (options.action === 'upload') return await uploadFile(input, options); if (options.action === 'url') return await uploadUrl(input, options); if (input.includes('catbox.moe/c/')) { return await getAlbum(input); } if ( input.includes('files.catbox.moe/') || input.includes('litter.catbox.moe/') ) { return await inspectFile(input); } if (input.startsWith('http://') || input.startsWith('https://')) { return await uploadUrl(input, options); } if (fs.existsSync(input)) { return await uploadFile(input, options); } if (/^[a-zA-Z0-9]{5,8}$/.test(input)) { try { return await getAlbum(input); } catch {} } throw new Error( `Input tidak dikenali sebagai URL, album code, ataupun file lokal: "${input}"` ); } export { catbox, uploadFile, uploadUrl, uploadToCatbox, uploadToLitterbox, getAlbum, inspectFile, formatBytes, getMimeType }; export default catbox; /** * CLI Runner: * 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" */ const cliArgs = process.argv.slice(2); const mainArg = cliArgs[0] ? cliArgs[0].trim() : null; async function runCli() { if (!mainArg) { console.log( JSON.stringify( { status: false, message: 'Parameter belum ditentukan.', usage: 'node catbox-moe-scraper.js <url_atau_filepath> [options]', features: [ 'Upload file lokal ke Catbox permanent (files.catbox.moe) with proxy bypass', 'Upload temporary ke Litterbox (--litterbox)', 'Re-hosting URL remote ke Catbox', 'Scraping album Catbox (https://catbox.moe/c/{id})', 'Inspect metadata & size file Catbox (Range streaming)' ], examples: [ 'node catbox-moe-scraper.js "/path/to/gambar.jpg"', 'node catbox-moe-scraper.js "https://catbox.moe/c/8xw6g4"', 'node catbox-moe-scraper.js "https://example.com/audio.mp3"', 'node catbox-moe-scraper.js "/path/to/file.zip" --litterbox --time=24h' ] }, null, 2 ) ); process.exit(1); } const options = {}; for (let i = 1; i < cliArgs.length; i++) { const arg = cliArgs[i]; if (arg === '--catbox') options.service = 'catbox'; if (arg === '--litterbox') options.service = 'litterbox'; if (arg.startsWith('--time=')) options.time = arg.split('=')[1]; if (arg.startsWith('--userhash=')) options.userhash = arg.split('=')[1]; } const res = await catbox(mainArg, options); console.log(JSON.stringify(res, null, 2)); } if ( process.argv[1] && (process.argv[1].endsWith('catbox-moe-scraper.js') || process.argv[1].endsWith('catbox-moe-scraper.mjs') || process.argv[1].endsWith('catbox-moe-scraper.cjs')) ) { runCli().catch((err) => { console.error( JSON.stringify({ status: false, error: err.message }, null, 2) ); process.exit(1); }); }