/** * Fake Spotify Canvas - 1:1 Pixel-Accurate Spotify Mobile Player Mockup Generator * Author: Vamz Spectre (VamxAPI) * * Fitur: * - 1:1 Pixel-accurate clone tampilan Spotify Now Playing Mobile (1080 x 2344, 19.5:9) * - Customization lengkap: Cover album/foto, Judul lagu, Nama artis/author, Jam status bar, * Persentase baterai, Judul & Subtitle playlist, Durasi lagu & Current time, State Play/Pause. * - Dynamic Ambient Background: Otomatis mendeteksi warna dominan album cover menggunakan sharp * dan menghasilkan dynamic ambient gradient khas Spotify Mobile. * - High-Resolution typography dengan font Spotify / Poppins (Bold, Medium, Regular). * - Auto-Upload ke Vamx Media CDN (https://cdn.vamxapi.my.id/m/...) untuk bot WhatsApp & Telegram. * * Penggunaan CLI: * curl -sL "https://code.vamxapi.my.id/snippet/raw/fakespotify" -o fakespotify.js * node fakespotify.js --title "Bersenja Gurau" --artist "Raim Laode" --clock "18.21" --battery 18 * node fakespotify.js '{"title":"Sialan","artist":"Juicy Luicy","duration":"3:45","currentTime":"1:20"}' */ const fs = require("fs"); const path = require("path"); const axios = require("axios"); const FormData = require("form-data"); const sharp = require("sharp"); const { Canvas, FontLibrary, loadImage } = require("skia-canvas"); const VAMX_CDN_UPLOAD_ENDPOINT = "https://cdn.vamxapi.my.id/api/v1/media/upload"; // Registrasi Font Spotify (Poppins) const FONT_DIR = "/root/websiteapi/assets/fonts/canvas"; try { if (fs.existsSync(path.join(FONT_DIR, "Poppins-Bold.ttf"))) { FontLibrary.use("SpotifyBold", path.join(FONT_DIR, "Poppins-Bold.ttf")); } if (fs.existsSync(path.join(FONT_DIR, "Poppins-Medium.ttf"))) { FontLibrary.use("SpotifyMedium", path.join(FONT_DIR, "Poppins-Medium.ttf")); } if (fs.existsSync(path.join(FONT_DIR, "Poppins-Regular.ttf"))) { FontLibrary.use("SpotifyRegular", path.join(FONT_DIR, "Poppins-Regular.ttf")); } if (fs.existsSync(path.join(FONT_DIR, "Poppins-SemiBold.ttf"))) { FontLibrary.use("SpotifySemiBold", path.join(FONT_DIR, "Poppins-SemiBold.ttf")); } } catch (e) { // Fallback ke system font jika gagal } /** * Konversi format mm:ss ke detik */ function parseTimeToSeconds(timeStr) { if (!timeStr || typeof timeStr !== "string") return 0; const parts = timeStr.split(":").map(Number); if (parts.length === 2) return parts[0] * 60 + parts[1]; if (parts.length === 3) return parts[0] * 3600 + parts[1] * 60 + parts[2]; return Number(timeStr) || 0; } /** * Upload gambar hasil render ke Vamx Media CDN */ async function uploadToVamxCdn(buffer, filename = "fakespotify.png") { const form = new FormData(); form.append("file", buffer, { filename, contentType: "image/png", }); const response = await axios.post(VAMX_CDN_UPLOAD_ENDPOINT, form, { headers: { ...form.getHeaders(), "x-client-mode": "vamx-cdn", }, timeout: 30000, maxBodyLength: Infinity, maxContentLength: Infinity, }); const mediaUrl = response.data?.data?.media?.url || response.data?.result?.media?.url || response.data?.data?.url; if (response.data && response.data.status && mediaUrl) { return mediaUrl; } throw new Error(response.data?.message || "Gagal mengunggah ke CDN Vamx."); } /** * Mengambil Buffer gambar dari URL atau file lokal */ async function resolveImageBuffer(input) { if (Buffer.isBuffer(input)) return input; if (typeof input === "string") { if (input.startsWith("http://") || input.startsWith("https://")) { const res = await axios.get(input, { responseType: "arraybuffer", timeout: 15000 }); return Buffer.from(res.data); } if (fs.existsSync(input)) { return fs.readFileSync(input); } } return null; } /** * Extract Dominant Color dari album cover menggunakan sharp */ async function extractDominantColor(imageBuffer) { try { const { data } = await sharp(imageBuffer) .resize(1, 1, { fit: "cover" }) .raw() .toBuffer({ resolveWithObject: true }); return [data[0], data[1], data[2]]; } catch { // Default Spotify Warm Ochre/Brown return [118, 48, 28]; } } /** * Generate Fake Spotify Canvas */ async function generateFakeSpotify(options = {}) { const { cover = "/tmp/bd316671-7255-455e-8267-4608ebc5e2ad.jpg", title = "Bersenja Gurau", artist = "Raim Laode", playlistTitle = "Radio Bersenja Gurau", playlistDesc = "Memainkan dari Playlist", duration = "3:14", currentTime = "0:00", clock = "18.21", battery = "18", isPlaying = false, shuffle = true, lyricsTitle = "Pratinjau lirik", uploadCdn = true, } = options; const W = 1080; const H = 2344; const canvas = new Canvas(W, H); const ctx = canvas.getContext("2d"); // 1. Resolve Cover & Dominant Color let coverBuffer = null; try { coverBuffer = await resolveImageBuffer(cover); } catch {} // Fallback dummy cover jika cover tidak ditemukan if (!coverBuffer) { if (fs.existsSync("/tmp/bd316671-7255-455e-8267-4608ebc5e2ad.jpg")) { coverBuffer = fs.readFileSync("/tmp/bd316671-7255-455e-8267-4608ebc5e2ad.jpg"); } else { // Buat square cover placeholder coverBuffer = await sharp({ create: { width: 936, height: 936, channels: 3, background: { r: 120, g: 50, b: 30 }, }, }).jpeg().toBuffer(); } } const [domR, domG, domB] = await extractDominantColor(coverBuffer); // 2. Background Gradient (Ambient Lighting khas Spotify) const bgGrad = ctx.createLinearGradient(0, 0, 0, H); bgGrad.addColorStop(0, `rgb(${domR}, ${domG}, ${domB})`); bgGrad.addColorStop(0.35, `rgb(${Math.floor(domR * 0.7)}, ${Math.floor(domG * 0.7)}, ${Math.floor(domB * 0.7)})`); bgGrad.addColorStop(0.65, `rgb(${Math.floor(domR * 0.25)}, ${Math.floor(domG * 0.25)}, ${Math.floor(domB * 0.25)})`); bgGrad.addColorStop(0.85, "#121212"); bgGrad.addColorStop(1, "#121212"); ctx.fillStyle = bgGrad; ctx.fillRect(0, 0, W, H); // 3. Status Bar (y = 50..90) // Clock (Kiri) ctx.fillStyle = "#ffffff"; ctx.font = "28px SpotifyBold"; ctx.textAlign = "left"; ctx.fillText(String(clock), 60, 78); // Notification / App dots const notifColors = ["#00bcd4", "#26a69a", "#4285f4", "#5c6bc0"]; notifColors.forEach((color, idx) => { ctx.beginPath(); ctx.arc(195 + idx * 26, 70, 7.5, 0, Math.PI * 2); ctx.fillStyle = color; ctx.fill(); }); // Small dot ctx.beginPath(); ctx.arc(195 + notifColors.length * 26 + 10, 70, 3, 0, Math.PI * 2); ctx.fillStyle = "#ffffff"; ctx.fill(); // Status Bar Kanan: VoLTE 4G+ & Signal Bars ctx.font = "22px SpotifyBold"; ctx.textAlign = "right"; ctx.fillText("Vo LTE", 740, 78); ctx.fillText("4G+", 785, 70); // 4 Signal Bars for (let b = 0; b < 4; b++) { const bh = 10 + b * 5; ctx.fillRect(810 + b * 9, 80 - bh, 6, bh); } // Battery Box & Percentage const batX = 875, batY = 52, batW = 68, batH = 34; ctx.strokeStyle = "rgba(255, 255, 255, 0.7)"; ctx.lineWidth = 3; ctx.beginPath(); ctx.roundRect(batX, batY, batW, batH, 8); ctx.stroke(); // Battery Tip (Kanan) ctx.fillStyle = "rgba(255, 255, 255, 0.7)"; ctx.fillRect(batX + batW, batY + 10, 4, 14); // Persentase Baterai const batVal = parseInt(battery, 10) || 18; ctx.fillStyle = batVal <= 20 ? "#ffb703" : "#ffffff"; ctx.font = "20px SpotifyBold"; ctx.textAlign = "center"; ctx.fillText(String(battery).replace("%", ""), batX + batW / 2, batY + 25); // 4. Navigation Header (y = 150..250) // Chevron Down ctx.beginPath(); ctx.moveTo(70, 185); ctx.lineTo(88, 203); ctx.lineTo(106, 185); ctx.strokeStyle = "#ffffff"; ctx.lineWidth = 5; ctx.lineCap = "round"; ctx.lineJoin = "round"; ctx.stroke(); // Subtitle ("Memainkan dari Playlist") ctx.textAlign = "center"; ctx.fillStyle = "rgba(255, 255, 255, 0.75)"; ctx.font = "28px SpotifyRegular"; ctx.fillText(playlistDesc, 540, 182); // Playlist Title ("Radio Bersenja Gurau") ctx.fillStyle = "#ffffff"; ctx.font = "34px SpotifyBold"; ctx.fillText(playlistTitle, 540, 230); // Three dots menu (Kanan) ctx.fillStyle = "#ffffff"; [186, 203, 220].forEach(dy => { ctx.beginPath(); ctx.arc(980, dy, 4.5, 0, Math.PI * 2); ctx.fill(); }); // 5. Album Cover Artwork (y = 368..1304) const coverX = 72; const coverY = 368; const coverSize = 936; const coverRadius = 24; ctx.save(); // Drop Shadow realistis di belakang album art ctx.shadowColor = "rgba(0, 0, 0, 0.65)"; ctx.shadowBlur = 45; ctx.shadowOffsetY = 22; // Load Album Image let coverImg; try { coverImg = await loadImage(coverBuffer); } catch { coverImg = null; } ctx.beginPath(); ctx.roundRect(coverX, coverY, coverSize, coverSize, coverRadius); ctx.clip(); if (coverImg) { ctx.drawImage(coverImg, coverX, coverY, coverSize, coverSize); } else { ctx.fillStyle = `rgb(${domR}, ${domG}, ${domB})`; ctx.fillRect(coverX, coverY, coverSize, coverSize); } ctx.restore(); // 6. Track Details & Action Buttons (y = 1440..1560) ctx.textAlign = "left"; ctx.fillStyle = "#ffffff"; ctx.font = "56px SpotifyBold"; // Truncate jika judul lagu terlalu panjang let displayTitle = title; if (ctx.measureText(displayTitle).width > 580) { while (ctx.measureText(displayTitle + "...").width > 580 && displayTitle.length > 0) { displayTitle = displayTitle.slice(0, -1); } displayTitle += "..."; } ctx.fillText(displayTitle, 72, 1485); ctx.fillStyle = "rgba(255, 255, 255, 0.65)"; ctx.font = "38px SpotifyMedium"; let displayArtist = artist; if (ctx.measureText(displayArtist).width > 580) { while (ctx.measureText(displayArtist + "...").width > 580 && displayArtist.length > 0) { displayArtist = displayArtist.slice(0, -1); } displayArtist += "..."; } ctx.fillText(displayArtist, 72, 1545); // Tombol Cross ✕ (Hide from playlist) const cx = 730, cy = 1505, cs = 22; ctx.beginPath(); ctx.moveTo(cx - cs, cy - cs); ctx.lineTo(cx + cs, cy + cs); ctx.moveTo(cx + cs, cy - cs); ctx.lineTo(cx - cs, cy + cs); ctx.strokeStyle = "#ffffff"; ctx.lineWidth = 6; ctx.lineCap = "round"; ctx.stroke(); // Tombol Plus ⊕ (Add to Liked Songs) const px = 890, py = 1505; ctx.beginPath(); ctx.arc(px, py, 40, 0, Math.PI * 2); ctx.strokeStyle = "#ffffff"; ctx.lineWidth = 5; ctx.stroke(); const ps = 18; ctx.beginPath(); ctx.moveTo(px - ps, py); ctx.lineTo(px + ps, py); ctx.moveTo(px, py - ps); ctx.lineTo(px, py + ps); ctx.lineWidth = 5; ctx.lineCap = "round"; ctx.stroke(); // 7. Progress Seekbar (y = 1640..1700) const barX = 72, barY = 1640, barW = 936, barH = 6; ctx.fillStyle = "rgba(255, 255, 255, 0.25)"; ctx.beginPath(); ctx.roundRect(barX, barY, barW, barH, 3); ctx.fill(); // Hitung played progress ratio const curSec = parseTimeToSeconds(currentTime); const durSec = Math.max(1, parseTimeToSeconds(duration)); let playedRatio = curSec / durSec; if (isNaN(playedRatio) || playedRatio < 0.01) playedRatio = 0.01; if (playedRatio > 1.0) playedRatio = 1.0; // Played bar ctx.fillStyle = "#ffffff"; ctx.beginPath(); ctx.roundRect(barX, barY, Math.max(6, barW * playedRatio), barH, 3); ctx.fill(); // Progress handle thumb dot const thumbX = barX + barW * playedRatio; ctx.beginPath(); ctx.arc(thumbX, barY + barH / 2, 11, 0, Math.PI * 2); ctx.fillStyle = "#ffffff"; ctx.fill(); // Time labels ctx.font = "26px SpotifyMedium"; ctx.fillStyle = "rgba(255, 255, 255, 0.6)"; ctx.textAlign = "left"; ctx.fillText(String(currentTime), 72, 1690); ctx.textAlign = "right"; ctx.fillText(String(duration), 1008, 1690); // 8. Main Controls Row (y = 1840) // Shuffle Button const shX = 100, shY = 1840; ctx.strokeStyle = shuffle ? "#1ed760" : "rgba(255, 255, 255, 0.65)"; ctx.lineWidth = 4.5; ctx.lineCap = "round"; ctx.beginPath(); ctx.moveTo(shX - 24, shY - 14); ctx.lineTo(shX - 8, shY - 14); ctx.lineTo(shX + 8, shY + 14); ctx.lineTo(shX + 24, shY + 14); ctx.stroke(); ctx.beginPath(); ctx.moveTo(shX - 24, shY + 14); ctx.lineTo(shX - 8, shY + 14); ctx.lineTo(shX - 2, shY + 5); ctx.stroke(); ctx.beginPath(); ctx.moveTo(shX + 2, shY - 5); ctx.lineTo(shX + 8, shY - 14); ctx.lineTo(shX + 24, shY - 14); ctx.stroke(); if (shuffle) { ctx.beginPath(); ctx.arc(shX, shY + 30, 4.5, 0, Math.PI * 2); ctx.fillStyle = "#1ed760"; ctx.fill(); } // Previous Button (|◀) const prX = 290, prY = 1840; ctx.fillStyle = "#ffffff"; ctx.fillRect(prX - 26, prY - 24, 6, 48); ctx.beginPath(); ctx.moveTo(prX + 20, prY - 25); ctx.lineTo(prX - 16, prY); ctx.lineTo(prX + 20, prY + 25); ctx.closePath(); ctx.fill(); // Big Play/Pause Button Circle const plX = 540, plY = 1840, plR = 90; ctx.beginPath(); ctx.arc(plX, plY, plR, 0, Math.PI * 2); ctx.fillStyle = "#ffffff"; ctx.fill(); if (isPlaying) { // Pause Icon (dua balok hitam vertikal) ctx.fillStyle = "#000000"; ctx.fillRect(plX - 22, plY - 25, 14, 50); ctx.fillRect(plX + 8, plY - 25, 14, 50); } else { // Play Triangle ctx.beginPath(); ctx.moveTo(plX - 14, plY - 26); ctx.lineTo(plX + 26, plY); ctx.lineTo(plX - 14, plY + 26); ctx.closePath(); ctx.fillStyle = "#000000"; ctx.fill(); } // Next Button (▶|) const nxX = 790, nxY = 1840; ctx.fillStyle = "#ffffff"; ctx.fillRect(nxX + 20, nxY - 24, 6, 48); ctx.beginPath(); ctx.moveTo(nxX - 20, nxY - 25); ctx.lineTo(nxX + 16, nxY); ctx.lineTo(nxX - 20, nxY + 25); ctx.closePath(); ctx.fill(); // Sleep Timer Icon (Stopwatch) const tiX = 975, tiY = 1840; ctx.beginPath(); ctx.arc(tiX, tiY, 26, 0, Math.PI * 2); ctx.strokeStyle = "#ffffff"; ctx.lineWidth = 4.5; ctx.stroke(); ctx.fillRect(tiX - 4, tiY - 34, 8, 7); ctx.beginPath(); ctx.moveTo(tiX, tiY); ctx.lineTo(tiX, tiY - 14); ctx.moveTo(tiX, tiY); ctx.lineTo(tiX + 10, tiY + 6); ctx.strokeStyle = "#ffffff"; ctx.lineWidth = 3.5; ctx.stroke(); // 9. Bottom Icons Row (y = 2070) // Device Connect (Kiri) const devX = 85, devY = 2070; ctx.strokeStyle = "#ffffff"; ctx.lineWidth = 4; ctx.beginPath(); ctx.roundRect(devX - 22, devY - 18, 44, 36, 6); ctx.stroke(); ctx.beginPath(); ctx.arc(devX, devY, 7, 0, Math.PI * 2); ctx.fillStyle = "#ffffff"; ctx.fill(); // Share Icon const shIX = 765, shIY = 2070; const sPts = [ { x: shIX - 14, y: shIY }, { x: shIX + 14, y: shIY - 14 }, { x: shIX + 14, y: shIY + 14 }, ]; ctx.strokeStyle = "#ffffff"; ctx.lineWidth = 3.5; ctx.beginPath(); ctx.moveTo(sPts[1].x, sPts[1].y); ctx.lineTo(sPts[0].x, sPts[0].y); ctx.lineTo(sPts[2].x, sPts[2].y); ctx.stroke(); sPts.forEach(p => { ctx.beginPath(); ctx.arc(p.x, p.y, 6, 0, Math.PI * 2); ctx.fillStyle = "#ffffff"; ctx.fill(); }); // Queue Icon (3 bars horizontal) const qX = 910, qY = 2070; ctx.fillStyle = "#ffffff"; ctx.beginPath(); ctx.roundRect(qX - 22, qY - 14, 44, 5, 2.5); ctx.roundRect(qX - 22, qY - 2, 44, 5, 2.5); ctx.roundRect(qX - 22, qY + 10, 44, 5, 2.5); ctx.fill(); // 10. Bottom Lyrics Preview Banner (y = 2200..2344) const lyrY = 2200; // Kontras dinamis dari dominant color const lyricCardColor = `rgb(${Math.min(255, Math.floor(domR * 1.15) + 20)}, ${Math.floor(domG * 0.45)}, ${Math.floor(domB * 0.45)})`; ctx.fillStyle = lyricCardColor; ctx.beginPath(); ctx.roundRect(40, lyrY, 1000, 200, 32); ctx.fill(); ctx.fillStyle = "#ffffff"; ctx.font = "40px SpotifyBold"; ctx.textAlign = "left"; ctx.fillText(lyricsTitle, 95, lyrY + 70); // Android Bottom Home Bar Pill ctx.fillStyle = "#ffffff"; ctx.beginPath(); ctx.roundRect(540 - 160, 2320, 320, 8, 4); ctx.fill(); // Export Buffer PNG const buffer = await canvas.toBuffer("png"); // Upload ke CDN Vamx jika diaktifkan let cdnUrl = null; if (uploadCdn) { try { cdnUrl = await uploadToVamxCdn(buffer, `fakespotify_${Date.now()}.png`); } catch {} } return { buffer, url: cdnUrl, width: W, height: H, meta: { title, artist, playlistTitle, playlistDesc, duration, currentTime, clock, battery: `${battery}%`, isPlaying, dominantColor: `rgb(${domR}, ${domG}, ${domB})`, }, }; } module.exports = { generateFakeSpotify, extractDominantColor }; // CLI Execution Runner if (require.main === module) { const args = process.argv.slice(2); const options = {}; if (args.length > 0 && args[0].trim().startsWith("{")) { try { Object.assign(options, JSON.parse(args.join(" "))); } catch {} } else { for (let i = 0; i < args.length; i++) { const arg = args[i]; if (arg === "--cover" && args[i + 1]) { options.cover = args[++i]; } else if (arg === "--title" && args[i + 1]) { options.title = args[++i]; } else if (arg === "--artist" && args[i + 1]) { options.artist = args[++i]; } else if (arg === "--playlist" && args[i + 1]) { options.playlistTitle = args[++i]; } else if (arg === "--playlistDesc" && args[i + 1]) { options.playlistDesc = args[++i]; } else if (arg === "--duration" && args[i + 1]) { options.duration = args[++i]; } else if (arg === "--currentTime" && args[i + 1]) { options.currentTime = args[++i]; } else if (arg === "--clock" && args[i + 1]) { options.clock = args[++i]; } else if (arg === "--battery" && args[i + 1]) { options.battery = args[++i]; } else if (arg === "--playing") { options.isPlaying = true; } } } generateFakeSpotify(options) .then((res) => { console.log( JSON.stringify( { status: true, creator: "Vamz Spectre", data: { url: res.url, dimensions: `${res.width}x${res.height}`, track: res.meta.title, artist: res.meta.artist, playlist: res.meta.playlistTitle, duration: res.meta.duration, currentTime: res.meta.currentTime, clock: res.meta.clock, battery: res.meta.battery, buffer_size: `${(res.buffer.length / 1024).toFixed(2)} KB`, }, }, null, 2 ) ); }) .catch((err) => { console.error( JSON.stringify( { status: false, creator: "Vamz Spectre", message: err.message || "Gagal membuat gambar fake spotify canvas.", }, null, 2 ) ); process.exit(1); }); }