/** * ===================================================================== * Downr AIO Multi-Platform Media Downloader Engine (50+ Platforms) * Resolves media links: TikTok, Facebook, Instagram, YouTube, * Twitter/X, Pinterest, CapCut, Threads, dsb. * * Author : Vamz Spectre / VamxAPI * Official Website : https://vamxapi.my.id * Target Reference : https://downr.org * License : MIT * ===================================================================== */ const axios = require("axios"); const vm = require("node:vm"); // ------------------------------------------------------------- // 1. TIKTOK & DOUYIN RESOLVER (TikWM Engine) // ------------------------------------------------------------- async function scrapeTikTok(url) { const apiUrl = "https://www.tikwm.com/api/?url=" + encodeURIComponent(url) + "&hd=1"; const res = await fetch(apiUrl, { 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", }, }); const data = await res.json(); if (data.code === 0 && data.data) { const d = data.data; const formats = [ d.hdplay ? { quality: "HD (No-Watermark)", type: "video", extension: "mp4", downloadUrl: d.hdplay } : null, d.play ? { quality: "SD (No-Watermark)", type: "video", extension: "mp4", downloadUrl: d.play } : null, d.music ? { quality: "Audio (MP3)", type: "audio", extension: "mp3", downloadUrl: d.music } : null, ].filter(Boolean); return { platform: "tiktok", title: d.title || "TikTok Video", author: d.author?.nickname || d.author?.unique_id, thumbnail: d.cover, duration: d.duration, formatsCount: formats.length, formats, }; } throw new Error("Gagal mengambil media TikTok: " + (data.msg || "Server sibuk")); } // ------------------------------------------------------------- // 2. FACEBOOK RESOLVER (SnapSave Engine) // ------------------------------------------------------------- async function scrapeFacebook(url) { const form = new URLSearchParams(); form.append("url", url); const { data } = await axios.post("https://snapsave.app/action.php?lang=id", form, { headers: { origin: "https://snapsave.app", referer: "https://snapsave.app/id", "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", }, timeout: 25000, }); const ctx = { window: {}, document: { getElementById: () => ({ innerHTML: "", value: "" }) }, console: console, eval: (res) => res, }; vm.createContext(ctx); const decoded = vm.runInContext(data, ctx); if (typeof decoded !== "string") { throw new Error("Gagal mendekode respon Facebook."); } const regex = /https:\/\/d\.rapidcdn\.app\/v2\?[^"'\s\\]+/g; const matches = decoded.match(regex); const formats = []; if (matches && matches.length > 0) { const unique = [...new Set(matches)]; unique.forEach((u, i) => { formats.push({ quality: i === 0 ? "HD" : "SD", type: "video", extension: "mp4", downloadUrl: u.replace(/&/g, "&"), }); }); } if (formats.length === 0) { throw new Error("Video tidak ditemukan atau link Facebook bersifat privat."); } return { platform: "facebook", title: "Facebook Video", formatsCount: formats.length, formats, }; } // ------------------------------------------------------------- // 3. YOUTUBE RESOLVER (SnapYT Engine) // ------------------------------------------------------------- async function scrapeYouTube(url) { const homeRes = await axios.get("https://www.snapyt.app/", { headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", }, timeout: 10000, }); const matchNonce = homeRes.data.match(/var\s+VD_NONCE\s*=\s*"([^"]+)"/i) || homeRes.data.match(/"nonce":"([^"]+)"/i); const nonce = matchNonce ? matchNonce[1] : "0f42e361f0"; const form = new URLSearchParams(); form.append("action", "process_video_url"); form.append("video_url", url); form.append("security", nonce); const procRes = await axios.post("https://www.snapyt.app/wp-admin/admin-ajax.php", form.toString(), { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", Origin: "https://www.snapyt.app", Referer: "https://www.snapyt.app/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", }, timeout: 20000, }); if (!procRes.data?.success || !procRes.data?.data?.redirect) { throw new Error(procRes.data?.data || "SnapYT tidak dapat memproses video YouTube ini."); } const redirectUrl = procRes.data.data.redirect; const previewRes = await axios.get(redirectUrl, { headers: { Referer: "https://www.snapyt.app/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", }, timeout: 20000, }); const previewHtml = previewRes.data; const titleMatch = previewHtml.match(/]*>([\s\S]*?)<\/h1>/i) || previewHtml.match(/class="[^"]*video-title[^"]*"[^>]*>([\s\S]*?)<\//i); const title = titleMatch ? titleMatch[1].replace(/<[^>]+>/g, "").trim() : "YouTube Video"; const formats = []; const optRegex = /]+)>/gi; let optMatch; while ((optMatch = optRegex.exec(previewHtml)) !== null) { const attrs = optMatch[1]; const urlMatch = attrs.match(/data-url="([^"]+)"/i) || attrs.match(/data-direct="([^"]+)"/i); const labelMatch = attrs.match(/data-label="([^"]+)"/i); const kindMatch = attrs.match(/data-kind="([^"]+)"/i); const extMatch = attrs.match(/data-ext="([^"]+)"/i); if (urlMatch && labelMatch) { const directUrl = urlMatch[1].replace(/&/g, "&"); const label = labelMatch[1]; const ext = extMatch ? extMatch[1] : "mp4"; const isAudio = (kindMatch && kindMatch[1].includes("audio")) || label.includes("MP3") || label.includes("M4A"); formats.push({ quality: label, type: isAudio ? "audio" : "video", extension: ext, downloadUrl: directUrl, }); } } if (formats.length === 0) { throw new Error("Gagal mengekstrak opsi resolusi video YouTube."); } return { platform: "youtube", title, formatsCount: formats.length, formats, }; } // ------------------------------------------------------------- // 4. PINTEREST RESOLVER (Direct Pin & Video Scraper) // ------------------------------------------------------------- async function scrapePinterest(url) { let target = url.trim(); if (target.includes("pin.it/")) { const resHead = await fetch(target, { method: "HEAD", redirect: "follow" }); target = resHead.url || target; } const res = await fetch(target, { headers: { "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1", }, }); const html = await res.text(); const ogTitleMatch = html.match(/ 0) { const bestMp4 = mp4List.find((u) => u.includes("720w") || u.includes("expMp4")) || mp4List[0]; formats.push({ quality: "HD Video", type: "video", extension: "mp4", downloadUrl: bestMp4.replace(/\\u002F/g, "/").replace(/\\/g, ""), }); } const ogImageMatch = html.match(/ ({})); if (data.code === 0 && data.data) { const d = data.data; return { platform: "threads", title: d.title || "Threads Post", formatsCount: 1, formats: [ { quality: "HD Video/Post", type: "video", extension: "mp4", downloadUrl: d.play || d.hdplay, }, ], }; } throw new Error("Gagal mengambil media Threads."); } // ------------------------------------------------------------- // 7. UNIVERSAL AIO FALLBACK (YouTube, Vimeo, Reddit, SoundCloud, dsb.) // ------------------------------------------------------------- async function scrapeUniversalAIO(url) { // Gunakan engine 9xbuddy AIO reverse-engineered const { scrapeAIO } = await import("./aio-scraper.js").catch(() => ({})); if (scrapeAIO) { const aioRes = await scrapeAIO(url, { saveToCdn: false }); if (aioRes && aioRes.formats && aioRes.formats.length > 0) { return { platform: aioRes.type || "universal", title: aioRes.title || "Media File", formatsCount: aioRes.formats.length, formats: aioRes.formats.map((f) => ({ quality: f.quality, type: f.type, extension: f.ext, downloadUrl: f.url, })), }; } } throw new Error("Platform belum didukung atau link privat."); } // ------------------------------------------------------------- // MAIN ENTRY POINT: downr() // ------------------------------------------------------------- async function downr(url) { if (!url || typeof url !== "string") { return { status: false, code: 400, creator: "vamxapi", message: "Parameter URL wajib diisi.", }; } const cleanUrl = url.trim(); try { let resultData = null; // 1. TikTok & Douyin if (/tiktok\.com|douyin\.com/i.test(cleanUrl)) { resultData = await scrapeTikTok(cleanUrl); } // 2. Facebook else if (/facebook\.com|fb\.watch|fb\.com/i.test(cleanUrl)) { resultData = await scrapeFacebook(cleanUrl); } // 3. YouTube else if (/youtu\.be|youtube\.com/i.test(cleanUrl)) { resultData = await scrapeYouTube(cleanUrl); } // 4. Pinterest else if (/pinterest\.com|pin\.it/i.test(cleanUrl)) { resultData = await scrapePinterest(cleanUrl); } // 5. CapCut else if (/capcut\.com|capcutshare\.com/i.test(cleanUrl)) { resultData = await scrapeCapCut(cleanUrl); } // 6. Threads else if (/threads\.net/i.test(cleanUrl)) { resultData = await scrapeThreads(cleanUrl); } // 7. Instagram else if (/instagram\.com/i.test(cleanUrl)) { // Coba TikWM Threads/IG bridge atau fallback try { resultData = await scrapeTikTok(cleanUrl); } catch { resultData = await scrapeUniversalAIO(cleanUrl); } } // 8. Platform Lainnya (Vimeo, Reddit, SoundCloud, dsb.) else { resultData = await scrapeUniversalAIO(cleanUrl); } return { status: true, code: 200, creator: "vamxapi", result: { url: cleanUrl, ...resultData, }, }; } catch (error) { return { status: false, code: 500, creator: "vamxapi", message: error.message || "Terjadi kesalahan internal pada scraper Downr.", }; } } if (typeof module !== "undefined" && module.exports) { module.exports = { downr, downloadMedia: downr, }; } // Eksekusi CLI jika dipanggil langsung via terminal if (require.main === module) { const args = process.argv.slice(2); if (!args[0]) { console.log("Usage: node downr-media-downloader.js "); console.log('Contoh 1: node downr-media-downloader.js "https://www.youtube.com/watch?v=dQw4w9WgXcQ"'); console.log('Contoh 2: node downr-media-downloader.js "https://www.facebook.com/watch/?v=10153231379946729"'); console.log('Contoh 3: node downr-media-downloader.js "https://pin.it/7x3..."'); process.exit(1); } downr(args[0]) .then((res) => { console.log(JSON.stringify(res, null, 2)); }) .catch((err) => { console.error("Error:", err.message); }); }