/** * ======================================================== * Name: Shopee Video Downloader (No Watermark & Clean HD) * * Cara Download: * curl -sL "https://code.vamxapi.my.id/snippet/raw/shopee-video-downloader" -o shopee-video-downloader.js * * Cara Eksekusi: * node shopee-video-downloader.js get "https://shopee.co.id/universal-link/video/..." * node shopee-video-downloader.js download "https://shopee.co.id/universal-link/video/..." * * Author: Vamz Spectre * Source: https://vamxapi.my.id * ======================================================== */ const fs = typeof require !== "undefined" ? require("fs") : null; const path = typeof require !== "undefined" ? require("path") : null; const API_BASE = "https://ferramentasdaweb.com.br/baixar-video-shopee/api"; const DEFAULT_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", Accept: "application/json, text/plain, */*", Referer: "https://ferramentasdaweb.com.br/baixar-video-shopee/", }; /** * 1. Ambil Informasi & Link Download Video Shopee (Clean / No-WM & Watermark) */ async function getVideoInfo(shopeeUrl) { const cleanUrl = (shopeeUrl || "").trim(); if (!cleanUrl) { throw new Error("URL video Shopee wajib disertakan!"); } const endpoint = `${API_BASE}/info.php?url=${encodeURIComponent(cleanUrl)}`; const res = await fetch(endpoint, { method: "GET", headers: DEFAULT_HEADERS, }); if (!res.ok) { throw new Error(`Gagal menghubungi server ekstraktor: HTTP ${res.status}`); } const data = await res.json(); if (data.error) { throw new Error(data.error); } return { status: true, input_url: cleanUrl, title: data.title || "Shopee Video", thumbnail: data.thumbnail || null, clean_url: data.clean_url || null, video_url: data.video_url || null, download_id: data.download_id || null, }; } /** * 2. Download dan simpan video Shopee ke file lokal */ async function downloadVideo(shopeeUrl, outputPath = "") { const info = await getVideoInfo(shopeeUrl); const targetVideoUrl = info.clean_url || info.video_url; if (!targetVideoUrl) { throw new Error("URL video tidak tersedia untuk diunduh."); } const fileName = outputPath || `shopee_${info.download_id || Date.now()}_${Date.now().toString().slice(-4)}.mp4`; const resolvedPath = path.resolve(process.cwd(), fileName); const res = await fetch(targetVideoUrl, { headers: { "User-Agent": DEFAULT_HEADERS["User-Agent"], Referer: "https://shopee.co.id/", }, }); if (!res.ok) { throw new Error(`Gagal mengunduh file media: HTTP ${res.status}`); } const arrayBuffer = await res.arrayBuffer(); fs.writeFileSync(resolvedPath, Buffer.from(arrayBuffer)); return { status: true, title: info.title, thumbnail: info.thumbnail, saved_to: resolvedPath, file_size_bytes: arrayBuffer.byteLength, is_clean: Boolean(info.clean_url), }; } /** * Universal Scraper Dispatcher */ async function shopeeDownloader(command, ...rest) { const clean = (command || "").trim(); if (!clean) { throw new Error("Parameter input (sub-command atau URL video Shopee) wajib disertakan!"); } const lower = clean.toLowerCase(); if (lower === "get" || lower === "info") { const targetUrl = rest.join(" ").trim(); if (!targetUrl) throw new Error("Format: node shopee-video-downloader.js get "); return await getVideoInfo(targetUrl); } if (lower === "download" || lower === "dl") { const targetUrl = rest[0]; const outputFile = rest[1] || ""; if (!targetUrl) throw new Error("Format: node shopee-video-downloader.js download [nama_file.mp4]"); return await downloadVideo(targetUrl, outputFile); } // Jika langsung memasukkan URL Shopee if (clean.startsWith("http://") || clean.startsWith("https://")) { return await getVideoInfo(clean); } throw new Error(`Sub-command "${command}" tidak dikenali. Gunakan "get" atau "download".`); } // CommonJS safe export if (typeof module !== "undefined" && module.exports) { module.exports = { shopeeDownloader, getVideoInfo, downloadVideo, default: shopeeDownloader, }; } /** * CLI Runner: * node shopee-video-downloader.js get "https://shopee.co.id/universal-link/video/..." * node shopee-video-downloader.js download "https://shopee.co.id/universal-link/video/..." */ const cliArgs = process.argv.slice(2); const mainCommand = cliArgs[0] ? cliArgs[0].trim() : null; async function runCli() { if (!mainCommand) { console.log( JSON.stringify( { status: false, message: "Sub-command belum ditentukan.", usage: { get: "node shopee-video-downloader.js get ", download: "node shopee-video-downloader.js download [nama_file.mp4]", }, examples: [ 'node shopee-video-downloader.js get "https://shopee.co.id/universal-link/video/..."', 'node shopee-video-downloader.js download "https://shopee.co.id/universal-link/video/..." video.mp4', ], }, null, 2 ) ); process.exit(1); } const res = await shopeeDownloader(mainCommand, ...cliArgs.slice(1)); console.log(JSON.stringify(res, null, 2)); } if (process.argv[1]) { runCli().catch((err) => { console.error(JSON.stringify({ status: false, error: err.message }, null, 2)); process.exit(1); }); }