/** * YTMP3 (yttmp3.com.co) YouTube to MP3 & MP4 Converter / Downloader Scraper * Author: Vamz Spectre (Vamx) * Target: yttmp3.com.co (Engine: savetube.vip reverse engineered) * Decryption: AES-128-CBC (Seed Key: C5D58EF67A7584E4A29F6C35BBC4EB12) * * Fitur: * - Direct MP3 audio converter (up to 320kbps) * - Direct MP4 video converter (360p, 480p, 720p, 1080p, 1440p, 2160p) * - Ekstraksi metadata video (title, duration, thumbnail, formats list) * - Dukungan Vamx CDN upload (opsional) * - Output format JSON murni & production-ready untuk Bot WA / Telegram / REST API * * Penggunaan CLI: * node yttmp3.js "https://www.youtube.com/watch?v=dQw4w9WgXcQ" * node yttmp3.js mp3 "https://youtu.be/kJQP7kiw5Fk" * node yttmp3.js mp4 "https://youtu.be/kJQP7kiw5Fk" 720 * node yttmp3.js info "https://youtu.be/kJQP7kiw5Fk" */ const crypto = require("crypto"); const axios = require("axios"); // AES-128-CBC Decryption Key dari bundle Next.js yttmp3.com.co const AES_KEY = Buffer.from("C5D58EF67A7584E4A29F6C35BBC4EB12", "hex"); const DEFAULT_HEADERS = { "Content-Type": "application/json", Origin: "https://yttmp3.com.co", Referer: "https://yttmp3.com.co/", "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", }; /** * 1. Mendapatkan CDN server acak dari savetube */ async function getRandomCdn() { try { const res = await axios.get("https://media.savetube.vip/api/random-cdn", { headers: DEFAULT_HEADERS, timeout: 10000, }); if (res.data && res.data.cdn) { return res.data.cdn; } return "cdn401.savetube.vip"; } catch { return "cdn401.savetube.vip"; } } /** * 2. Dekripsi payload AES-128-CBC dari endpoint /v2/info */ function decryptPayload(base64Data) { try { const rawBuffer = Buffer.from(base64Data.replace(/\s/g, ""), "base64"); if (rawBuffer.length < 16) { throw new Error("Invalid payload: buffer length less than 16 bytes"); } const iv = rawBuffer.subarray(0, 16); const ciphertext = rawBuffer.subarray(16); const decipher = crypto.createDecipheriv("aes-128-cbc", AES_KEY, iv); let decrypted = decipher.update(ciphertext); decrypted = Buffer.concat([decrypted, decipher.final()]); return JSON.parse(decrypted.toString("utf8")); } catch (err) { throw new Error(`Gagal mendekripsi payload YTMP3: ${err.message}`); } } /** * 3. Ambil metadata dan format video dari YouTube URL */ async function getVideoInfo(youtubeUrl, cdnHost = null) { if (!youtubeUrl || typeof youtubeUrl !== "string") { throw new Error("YouTube URL diperlukan"); } const cdn = cdnHost || (await getRandomCdn()); const res = await axios.post( `https://${cdn}/v2/info`, { url: youtubeUrl.trim() }, { headers: DEFAULT_HEADERS, timeout: 20000 } ); const body = res.data; if (!body || body.status === false || !body.data) { throw new Error(body?.message || "Gagal mengambil data video dari YTMP3"); } const videoData = decryptPayload(body.data); return { cdn, data: videoData, }; } /** * 4. Generate URL Download (Audio MP3 atau Video MP4) */ async function getDownloadUrl({ key, titleSlug = "", quality = "128", type = "audio", directUrl = null, cdnHost = null }) { const cdn = cdnHost || (await getRandomCdn()); // Jika format video langsung tersedia dari googlevideo if (directUrl && type !== "audio") { return { status: true, downloadUrl: `${directUrl}&title=${titleSlug || "video"}-ytshorts.savetube.vip`, }; } const downloadType = type === "audio" || quality === "128" ? "audio" : "video"; const postData = { downloadType, quality: String(quality), key, }; const res = await axios.post(`https://${cdn}/download`, postData, { headers: DEFAULT_HEADERS, timeout: 25000, }); const body = res.data; if (!body || body.status === false || !body.data?.downloadUrl) { throw new Error(body?.message || "Gagal mendapatkan download link dari YTMP3"); } return { status: true, downloadUrl: body.data.downloadUrl, }; } /** * 5. Helper Upload ke Vamx CDN (opsional) */ async function uploadToVamxCdn(fileUrl, filename = "media.mp3") { if (!fileUrl || !fileUrl.startsWith("http")) return fileUrl; try { const res = await fetch(fileUrl, { headers: { "User-Agent": DEFAULT_HEADERS["User-Agent"], }, }); if (!res.ok) return fileUrl; const arrayBuffer = await res.arrayBuffer(); const contentType = res.headers.get("content-type") || "application/octet-stream"; const blob = new Blob([arrayBuffer], { type: contentType }); const form = new FormData(); form.append("file", blob, filename); const uploadRes = await fetch("https://cdn.vamxapi.my.id/api/v1/media/upload", { method: "POST", headers: { "x-client-mode": "vamx-cdn", }, body: form, }); const json = await uploadRes.json(); if (json.status && json.result?.media?.url) { return json.result.media.url; } } catch { // Fallback jika upload CDN gagal } return fileUrl; } /** * 6. Download MP3 Langsung dari YouTube URL */ async function downloadMp3(youtubeUrl, options = {}) { const { cdn, data } = await getVideoInfo(youtubeUrl); const dl = await getDownloadUrl({ key: data.key, titleSlug: data.titleSlug, quality: "128", type: "audio", cdnHost: cdn, }); let audioUrl = dl.downloadUrl; let thumbUrl = data.thumbnail; if (options.saveToCdn) { audioUrl = await uploadToVamxCdn(audioUrl, `${data.titleSlug || "audio"}.mp3`); if (thumbUrl) { thumbUrl = await uploadToVamxCdn(thumbUrl, `thumb_${data.id}.webp`); } } return { status: true, title: data.title, id: data.id, duration: data.duration, durationLabel: data.durationLabel, thumbnail: thumbUrl, type: "audio", format: "mp3", quality: "320kbps", downloadUrl: audioUrl, }; } /** * 7. Download MP4 Langsung dari YouTube URL */ async function downloadMp4(youtubeUrl, quality = "720", options = {}) { const { cdn, data } = await getVideoInfo(youtubeUrl); // Cari direct URL jika ada (misal 360p) let directUrl = null; if (data.video_formats && Array.isArray(data.video_formats)) { const match = data.video_formats.find( (f) => String(f.quality) === String(quality) || String(f.height) === String(quality) ); if (match && match.url) { directUrl = match.url; } } const dl = await getDownloadUrl({ key: data.key, titleSlug: data.titleSlug, quality: String(quality), type: "video", directUrl, cdnHost: cdn, }); let videoUrl = dl.downloadUrl; let thumbUrl = data.thumbnail; if (options.saveToCdn) { videoUrl = await uploadToVamxCdn(videoUrl, `${data.titleSlug || "video"}_${quality}p.mp4`); if (thumbUrl) { thumbUrl = await uploadToVamxCdn(thumbUrl, `thumb_${data.id}.webp`); } } return { status: true, title: data.title, id: data.id, duration: data.duration, durationLabel: data.durationLabel, thumbnail: thumbUrl, type: "video", format: "mp4", quality: `${quality}p`, downloadUrl: videoUrl, }; } /** * 8. All-in-one Scraper: Mengambil info lengkap, link MP3, dan link MP4 terbaik */ async function scrapeYttmp3(youtubeUrl, options = {}) { const { cdn, data } = await getVideoInfo(youtubeUrl); // Ambil link MP3 const mp3Dl = await getDownloadUrl({ key: data.key, titleSlug: data.titleSlug, quality: "128", type: "audio", cdnHost: cdn, }); // Tentukan kualitas MP4 default (pilih 720p atau yang tersedia) const availableVideoQualities = (data.video_formats || []).map((f) => String(f.quality || f.height)); const preferredQuality = ["720", "1080", "480", "360"].find((q) => availableVideoQualities.includes(q)) || "720"; let directUrl = null; const matchFmt = (data.video_formats || []).find((f) => String(f.quality || f.height) === preferredQuality); if (matchFmt && matchFmt.url) directUrl = matchFmt.url; const mp4Dl = await getDownloadUrl({ key: data.key, titleSlug: data.titleSlug, quality: preferredQuality, type: "video", directUrl, cdnHost: cdn, }); let audioUrl = mp3Dl.downloadUrl; let videoUrl = mp4Dl.downloadUrl; let thumbUrl = data.thumbnail; if (options.saveToCdn) { audioUrl = await uploadToVamxCdn(audioUrl, `${data.titleSlug || "audio"}.mp3`); videoUrl = await uploadToVamxCdn(videoUrl, `${data.titleSlug || "video"}_${preferredQuality}p.mp4`); if (thumbUrl) { thumbUrl = await uploadToVamxCdn(thumbUrl, `thumb_${data.id}.webp`); } } return { status: true, result: { id: data.id, title: data.title, titleSlug: data.titleSlug, url: data.url, thumbnail: thumbUrl, duration: data.duration, durationLabel: data.durationLabel, mp3: { format: "mp3", quality: "320kbps", downloadUrl: audioUrl, }, mp4: { format: "mp4", quality: `${preferredQuality}p`, downloadUrl: videoUrl, }, availableQualities: { audio: ["128 (MP3 320kbps)"], video: availableVideoQualities.filter((v, i, a) => a.indexOf(v) === i), }, }, }; } // Module Exports if (typeof module !== "undefined" && module.exports) { module.exports = { getRandomCdn, decryptPayload, getVideoInfo, getDownloadUrl, downloadMp3, downloadMp4, scrapeYttmp3, }; } // CLI Execution Handler if (require.main === module) { const args = process.argv.slice(2); if (args.length === 0) { console.log("================================================="); console.log(" YTMP3 (yttmp3.com.co) Scraper CLI"); console.log("================================================="); console.log("Penggunaan:"); console.log(" node yttmp3.js # Download MP3 + MP4 + Info"); console.log(" node yttmp3.js mp3 # Download MP3 saja"); console.log(" node yttmp3.js mp4 [quality]# Download MP4 (default 720)"); console.log(" node yttmp3.js info # Metadata & Format Lengkap"); console.log(""); console.log("Contoh:"); console.log(" node yttmp3.js 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'"); console.log(" node yttmp3.js mp3 'https://youtu.be/kJQP7kiw5Fk'"); console.log(" node yttmp3.js mp4 'https://youtu.be/kJQP7kiw5Fk' 1080"); process.exit(0); } let command = "all"; let targetUrl = ""; let quality = "720"; if (["mp3", "mp4", "info", "all"].includes(args[0].toLowerCase())) { command = args[0].toLowerCase(); targetUrl = args[1]; if (args[2]) quality = args[2]; } else { targetUrl = args[0]; } if (!targetUrl) { console.error("Error: YouTube URL tidak ditemukan."); process.exit(1); } (async () => { try { console.log(`[YTMP3] Memproses: ${targetUrl} ...`); let result; if (command === "mp3") { result = await downloadMp3(targetUrl); } else if (command === "mp4") { result = await downloadMp4(targetUrl, quality); } else if (command === "info") { const { data } = await getVideoInfo(targetUrl); result = { status: true, result: data }; } else { result = await scrapeYttmp3(targetUrl); } console.log("\n[Hasil JSON]:"); console.log(JSON.stringify(result, null, 2)); } catch (err) { console.error("\n[Error]", err.message); process.exit(1); } })(); }