/** * Spotdown - Spotify Music Downloader & Metadata Scraper * Author: Vamz Spectre (VamxAPI) * * Fitur: * - Download musik Spotify ke format audio jernih (up to 320kbps) * - Support direct Spotify Track URL (https://open.spotify.com/track/...) * - Support pencarian langsung dengan judul lagu / nama artis * - Resolusi metadata resmi Spotify (Judul, Artis, Album, Durasi, Cover HD) * - Didukung Vamx High-Speed Native Stream & Deezer Music Catalog * - Output format JSON murni & production-ready untuk bot WhatsApp & API * * Penggunaan CLI: * curl -sL "https://code.vamxapi.my.id/snippet/raw/spotdown" -o spotdown.js * node spotdown.js "https://open.spotify.com/track/4cOdK2wGLETKBW3PvgPWqT" * node spotdown.js "Komang Raim Laode" */ const axios = require("axios"); const DEFAULT_HEADERS = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", Accept: "application/json, text/plain, */*", }; const VAMX_API_URL = process.env.VAMX_API_URL || "https://vamxapi.my.id"; const VAMX_INTERNAL_URL = "http://127.0.0.1:10319"; const VAMX_MASTER_KEY = "vamx_live_admin_master_key"; /** * Format detik ke format menit:detik (MM:SS) */ function formatSeconds(sec) { if (!sec || isNaN(sec)) return "0:00"; const m = Math.floor(sec / 60); const s = Math.floor(sec % 60); return `${m}:${s.toString().padStart(2, "0")}`; } /** * Ekstraksi Track ID dari URL Spotify */ function extractSpotifyTrackId(input) { if (!input) return null; const str = String(input).trim(); if (/^[a-zA-Z0-9]{22}$/.test(str)) return str; const match = str.match(/track\/([a-zA-Z0-9]{22})/i); return match ? match[1] : null; } /** * Mengambil metadata resmi track Spotify via oEmbed & Web Embed */ async function getSpotifyMeta(trackUrlOrId) { const trackId = extractSpotifyTrackId(trackUrlOrId); const trackUrl = trackId ? `https://open.spotify.com/track/${trackId}` : trackUrlOrId; let title = "Spotify Music"; let artist = "Unknown Artist"; let album = ""; let thumbnail = ""; let duration = "-"; // 1. Coba oEmbed resmi Spotify try { const { data } = await axios.get( `https://open.spotify.com/oembed?url=${encodeURIComponent(trackUrl)}`, { headers: DEFAULT_HEADERS, timeout: 8000 } ); if (data?.title) title = data.title; if (data?.thumbnail_url) thumbnail = data.thumbnail_url; } catch {} // 2. Coba Spotify Embed State if (trackId) { try { const { data: html } = await axios.get( `https://open.spotify.com/embed/track/${trackId}`, { headers: DEFAULT_HEADERS, timeout: 8000 } ); const match = html.match(/