/** * VidSave (vidsave.com / vidssave.com) Universal Video & Audio Downloader * Author: Vamz Spectre / VamxAPI * * Scraper & Downloader engine reverse-engineered dari VidSave API: * - Multi-platform: YouTube (144p - 4K 2160p, MP3 Audio), TikTok, Instagram, Facebook, Twitter/X, Pinterest, Threads, Reddit, Dailymotion * - AES CBC Decryption engine terintegrasi untuk reverse backend token * - Server-Sent Events (SSE) download progress & link resolution * - Tanpa dependency eksternal (menggunakan native Node.js crypto & fetch) * * Cara Penggunaan CLI: * 1. Download file: * curl -sL "https://code.vamxapi.my.id/snippet/raw/vidsave" -o vidsave.js * * 2. Eksekusi: * node vidsave.js "" (Download video standar) * node vidsave.js "" parse (Hanya parse info video & list kualitas) * node vidsave.js "" 1080p (Download kualitas spesifik) * node vidsave.js "" audio (Download audio MP3) */ const crypto = require("crypto"); const AES_KEYS = [ "4c9b7d2e".repeat(3) + "4c9b7d21", "rz18efAXUbdiaO7k" ]; const BASE_API = "https://api.vidssave.com/api/contentsite_api"; const SSE_BASE = "https://api.vidssave.com/sse/contentsite_api"; const DEFAULT_HEADERS = { "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", "Referer": "https://vidssave.com/", "Origin": "https://vidssave.com", "Content-Type": "application/x-www-form-urlencoded" }; /** * Decrypt ZeroPadding AES CBC cipher */ function decryptAES(cipherTextB64) { const cleanB64 = cipherTextB64.trim(); for (const keyStr of AES_KEYS) { try { const key = Buffer.from(keyStr, "utf8"); const iv = Buffer.from(keyStr.slice(0, 16), "utf8"); const decipher = crypto.createDecipheriv( key.length === 32 ? "aes-256-cbc" : "aes-128-cbc", key, iv ); decipher.setAutoPadding(false); const decrypted = Buffer.concat([ decipher.update(Buffer.from(cleanB64, "base64")), decipher.final() ]); let end = decrypted.length; while (end > 0 && decrypted[end - 1] === 0) end--; const text = decrypted.slice(0, end).toString("utf8"); return JSON.parse(text); } catch { // Coba key berikutnya } } throw new Error("Gagal melakukan dekripsi respon AES dari VidSave"); } /** * Request helper ke API VidSave */ async function requestApi(path, data = {}) { const payload = { hostname: "vidssave.com", auth: "4c9b7d21", domain: "api-ak.vidssave.com", ...data }; const body = new URLSearchParams(payload).toString(); const res = await fetch(`${BASE_API}/${path}`, { method: "POST", headers: DEFAULT_HEADERS, body }); if (!res.ok) { throw new Error(`HTTP error ${res.status}: ${res.statusText}`); } const json = await res.json(); if (json.status !== 1) { throw new Error(json.msg || json.message || `VidSave API error status ${json.status}`); } if (typeof json.data === "string") { return decryptAES(json.data); } return json.data; } /** * Parse metadata media dari URL */ async function parse(videoUrl) { if (!videoUrl) throw new Error("URL video tidak boleh kosong"); const data = await requestApi("media/parse", { origin: "source", link: videoUrl }); return { status: true, title: data.title || "Video", duration: data.duration || 0, durationFormatted: data.duration ? Math.floor(data.duration / 60) + ":" + String(data.duration % 60).padStart(2, "0") : null, thumbnail: data.thumbnail || "", resources: (data.resources || []).map(r => ({ quality: r.quality, format: r.format, type: r.type, size: r.size || 0, sizeFormatted: r.size ? (r.size / (1024 * 1024)).toFixed(2) + " MB" : null, resourceContent: r.resource_content })) }; } /** * Generate direct download URL via task SSE */ async function getDownloadLink(resourceContent, format = "") { const postData = { request: resourceContent, no_encrypt: 1 }; if (format) postData.output = format.toLowerCase(); const dlData = await requestApi("media/download", postData); const taskId = dlData.task_id; if (!taskId) throw new Error("Tidak menemukan task_id dari server VidSave"); const sseUrl = `${SSE_BASE}/media/download_query?auth=20250901majwlqo&domain=api-ak.vidssave.com&task_id=${encodeURIComponent( taskId )}&download_domain=vidssave.com&origin=content_site`; const sseRes = await fetch(sseUrl, { headers: { "User-Agent": DEFAULT_HEADERS["User-Agent"], "Referer": DEFAULT_HEADERS["Referer"], "Accept": "text/event-stream" } }); const reader = sseRes.body.getReader(); const decoder = new TextDecoder(); let downloadRedirect = null; let sseInfo = null; while (true) { const { done, value } = await reader.read(); if (done) break; const chunk = decoder.decode(value); for (const line of chunk.split("\n")) { if (line.startsWith("data:")) { try { const parsed = JSON.parse(line.slice(5).trim()); if (parsed.download_link) { downloadRedirect = parsed.download_link; sseInfo = parsed; break; } } catch {} } } if (downloadRedirect) break; } if (!downloadRedirect) { throw new Error("Koneksi SSE selesai tanpa menghasilkan tautan download"); } // Ambil redirect lokasi CDN asli (HTTP 302) const redRes = await fetch(downloadRedirect, { redirect: "manual", headers: { "User-Agent": DEFAULT_HEADERS["User-Agent"] } }); const directUrl = redRes.headers.get("location") || downloadRedirect; return { downloadUrl: directUrl, fileSize: sseInfo ? sseInfo.filesize : null, fileSizeFormatted: sseInfo && sseInfo.filesize ? (sseInfo.filesize / (1024 * 1024)).toFixed(2) + " MB" : null }; } /** * Download wrapper: parse lalu otomatis request download link */ async function download(videoUrl, options = {}) { const info = await parse(videoUrl); let target = null; if (typeof options === "string") { if (options.toLowerCase() === "audio" || options.toLowerCase() === "mp3") { target = info.resources.find(r => r.type === "audio"); } else { target = info.resources.find( r => r.quality.toLowerCase() === options.toLowerCase() ); } } else if (options && typeof options === "object") { if (options.quality) { target = info.resources.find( r => r.quality.toLowerCase() === options.quality.toLowerCase() ); } if (!target && options.type) { target = info.resources.find( r => r.type.toLowerCase() === options.type.toLowerCase() ); } } if (!target) { target = info.resources.find(r => r.type === "video") || info.resources[0]; } if (!target) throw new Error("Tidak ada resource video/audio yang tersedia untuk diunduh"); const dl = await getDownloadLink(target.resourceContent, target.format); return { status: true, title: info.title, duration: info.duration, durationFormatted: info.durationFormatted, thumbnail: info.thumbnail, selected: { quality: target.quality, format: target.format, type: target.type }, downloadUrl: dl.downloadUrl, fileSize: dl.fileSize, fileSizeFormatted: dl.fileSizeFormatted, availableFormats: info.resources.map(r => ({ quality: r.quality, format: r.format, type: r.type, sizeFormatted: r.sizeFormatted })) }; } module.exports = { parse, getDownloadLink, download }; // CLI Runner if (require.main === module) { (async () => { const args = process.argv.slice(2); const videoUrl = args[0]; const modeOrQuality = args[1]; if (!videoUrl) { console.log( JSON.stringify( { status: false, message: "Gunakan: node vidsave.js [quality|audio|parse]", examples: [ "node vidsave.js \"https://www.youtube.com/watch?v=dQw4w9WgXcQ\"", "node vidsave.js \"https://www.youtube.com/watch?v=dQw4w9WgXcQ\" parse", "node vidsave.js \"https://www.youtube.com/watch?v=dQw4w9WgXcQ\" 1080p", "node vidsave.js \"https://www.youtube.com/watch?v=dQw4w9WgXcQ\" audio" ] }, null, 2 ) ); process.exit(1); } try { let result; if (modeOrQuality === "parse") { result = await parse(videoUrl); } else { result = await download(videoUrl, modeOrQuality); } console.log(JSON.stringify(result, null, 2)); } catch (err) { console.error( JSON.stringify( { status: false, error: err.message }, null, 2 ) ); process.exit(1); } })(); }