downloaderjavascript31076
PlaySpo - Spotify Search & Direct MP3 Downloader
Cari lagu Spotify akurat (Deezer & Apple Music Catalog fallback) dan download audio MP3 hingga 320kbps tanpa akun Spotify Premium.
Vamz Spectre29 Sep 2026669 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/playspo-spotify-downloader" -o playspo-spotify-downloader.js
# 2. Jalankan script
node playspo-spotify-downloader.js
Dependencies npm yang Dibutuhkan:
npm install axiosPanduan Penggunaan:
// Instalasi: npm install axios // Penggunaan CLI: node playspo-spotify-downloader.js "komang raim laode"
playspo-spotify-downloader.js(669 lines)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
/**
* PlaySpo - Spotify Search & Direct MP3 Downloader Scraper (Vamx CDN Only)
* Author: Vamz Spectre (Vamx)
* Target: Spotify Music Search (Deezer & iTunes Catalog) + Multi-Engine MP3 Converter (Savetube VIP & LbServer)
* Storage: 100% Vamx Media CDN (https://cdn.vamxapi.my.id/m/...)
*
* Fitur:
* - Search lagu Spotify akurat & cepat (Deezer Global Music Catalog + Apple Music fallback)
* - Support direct Spotify Track URL (https://open.spotify.com/track/...) maupun Keyword judul lagu
* - Resolusi otomatis metadata resmi (Judul, Artis, Album, Durasi, Cover Art HD)
* - Direct MP3 Download link otomatis (up to 320kbps) tanpa perlu Spotify Premium
* - Multi-engine converter fallback (Savetube VIP AES-128-CBC -> LbServer / SaveNow)
* - 100% VAMX CDN ONLY: Seluruh audio MP3 dan cover image otomatis di-host di Vamx CDN
* - Dilarang keras membocorkan URL vendor pihak ketiga (No raw 3rd-party URLs)
* - Output format JSON murni & production-ready untuk Bot WhatsApp (Baileys), Telegram, & REST API
*
* Penggunaan CLI:
* node playspo.js "Komang Raim Laode"
* node playspo.js "https://open.spotify.com/track/4cOdK2wGLETKBW3PvgPWqT"
* node playspo.js search "Coldplay Yellow"
* node playspo.js download "Bernadya Untungnya"
*/
const crypto = require("crypto");
const https = require("https");
const axios = require("axios");
// Vamx CDN Configuration
const VAMX_CDN_BASE = "https://cdn.vamxapi.my.id";
const VAMX_CDN_UPLOAD_ENDPOINT = `${VAMX_CDN_BASE}/api/v1/media/upload`;
// AES-128-CBC Decryption Key untuk Savetube VIP converter
const SAVETUBE_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",
};
/**
* Format bytes ke format human-readable (KB, MB)
*/
function formatBytes(bytes) {
if (!bytes || isNaN(bytes) || bytes <= 0) return "0 B";
const k = 1024;
const sizes = ["B", "KB", "MB", "GB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
}
/**
* Format detik ke format menit:detik (MM:SS)
*/
function formatDuration(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")}`;
}
/**
* Format milidetik ke MM:SS
*/
function formatDurationMs(ms) {
if (!ms || isNaN(ms)) return "0:00";
return formatDuration(Math.floor(ms / 1000));
}
/**
* Ekstraksi Spotify Track ID dari URL atau ID mentah
*/
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;
}
/**
* Cek apakah input berupa link Spotify
*/
function isSpotifyUrl(input) {
return (
/spotify\.com\/track\//i.test(String(input || "")) ||
/^[a-zA-Z0-9]{22}$/.test(String(input || ""))
);
}
/**
* Upload Buffer / Remote URL ke Vamx CDN
* Mengembalikan objek metadata CDN { id, url, mime, size, checksum, expires_at }
*/
async function uploadToVamxCdn(fileUrlOrBuffer, filename = "media.mp3", mimeType = "audio/mpeg") {
try {
let blob;
if (Buffer.isBuffer(fileUrlOrBuffer)) {
blob = new Blob([fileUrlOrBuffer], { type: mimeType });
} else {
const res = await axios.get(fileUrlOrBuffer, {
responseType: "arraybuffer",
timeout: 45000,
headers: { "User-Agent": DEFAULT_HEADERS["User-Agent"] },
});
blob = new Blob([res.data], { type: mimeType });
}
const form = new FormData();
form.append("file", blob, filename);
const uploadRes = await fetch(VAMX_CDN_UPLOAD_ENDPOINT, {
method: "POST",
headers: { "x-client-mode": "vamx-cdn" },
body: form,
});
const json = await uploadRes.json();
if (json.status && json.result?.media) {
return json.result.media;
}
throw new Error(json.message || "Gagal mengunggah file ke Vamx CDN");
} catch (err) {
throw new Error(`[Vamx CDN Error] ${err.message}`);
}
}
/**
* 1. Resolusi Metadata dari Spotify Track URL / ID (oEmbed & Embed Scraper)
*/
async function getSpotifyTrackInfo(trackUrlOrId) {
const trackId = extractSpotifyTrackId(trackUrlOrId);
const trackUrl = trackId ? `https://open.spotify.com/track/${trackId}` : trackUrlOrId;
let title = "Spotify Audio";
let artist = "Unknown Artist";
let thumbnail = "";
let duration = "-";
let durationMs = 0;
try {
const oembedRes = await axios.get(
`https://open.spotify.com/oembed?url=${encodeURIComponent(trackUrl)}`,
{ timeout: 8000 }
);
if (oembedRes.data) {
title = oembedRes.data.title || title;
thumbnail = oembedRes.data.thumbnail_url || thumbnail;
}
} catch {}
try {
const embedUrl = `https://open.spotify.com/embed/track/${trackId}`;
const embedRes = await axios.get(embedUrl, {
headers: {
"User-Agent": DEFAULT_HEADERS["User-Agent"],
},
timeout: 8000,
});
const html = embedRes.data || "";
const match = html.match(/<script id="__NEXT_DATA__" type="application\/json">({.+?})<\/script>/);
if (match) {
const data = JSON.parse(match[1]);
const entity = data.props?.pageProps?.state?.data?.entity;
if (entity) {
if (entity.name) title = entity.name;
if (Array.isArray(entity.artists) && entity.artists.length > 0) {
artist = entity.artists.map((a) => a.name).join(", ");
}
if (entity.duration) {
durationMs = entity.duration;
duration = formatDurationMs(entity.duration);
}
}
}
} catch {}
return {
id: trackId || "spotify_track",
title,
artist,
duration,
duration_ms: durationMs,
thumbnail,
spotify_url: trackUrl,
};
}
/**
* 2. Search Spotify Tracks (Kombinasi Deezer Global DB & Apple Music Catalog)
*/
async function searchSpotify(query, limit = 10) {
const cleanQ = (query || "").trim();
if (!cleanQ) {
throw new Error("Query pencarian lagu Spotify tidak boleh kosong.");
}
const effectiveLimit = Math.min(Math.max(1, limit || 10), 30);
// Strategy 1: Deezer Global Catalog
try {
const res = await axios.get("https://api.deezer.com/search", {
params: { q: cleanQ, limit: effectiveLimit },
timeout: 8000,
headers: {
"User-Agent": DEFAULT_HEADERS["User-Agent"],
},
});
if (res.data && Array.isArray(res.data.data) && res.data.data.length > 0) {
const tracks = res.data.data.map((item) => {
const id = String(item.id);
const encodedQuery = encodeURIComponent(`${item.title} ${item.artist?.name || ""}`);
return {
id: `sp_${id}`,
title: item.title || "Unknown Title",
artist: item.artist?.name || "Unknown Artist",
album: item.album?.title || "",
duration: formatDuration(Number(item.duration) || 0),
duration_seconds: Number(item.duration) || 0,
thumbnail:
item.album?.cover_big ||
item.album?.cover_medium ||
item.album?.cover ||
item.artist?.picture_medium ||
"",
preview_url: item.preview || null,
spotify_url: `https://open.spotify.com/search/${encodedQuery}`,
};
});
return {
status: true,
creator: "vamxapi",
query: cleanQ,
total: tracks.length,
tracks,
};
}
} catch (err) {}
// Strategy 2: Apple Music Catalog Fallback
try {
const res = await axios.get("https://itunes.apple.com/search", {
params: {
term: cleanQ,
entity: "song",
limit: effectiveLimit,
},
timeout: 8000,
});
if (res.data && Array.isArray(res.data.results) && res.data.results.length > 0) {
const tracks = res.data.results.map((item) => {
const id = String(item.trackId);
const encodedQuery = encodeURIComponent(`${item.trackName} ${item.artistName || ""}`);
const totalSec = Math.floor((Number(item.trackTimeMillis) || 0) / 1000);
return {
id: `sp_${id}`,
title: item.trackName || "Unknown Title",
artist: item.artistName || "Unknown Artist",
album: item.collectionName || "",
duration: formatDuration(totalSec),
duration_seconds: totalSec,
thumbnail: (item.artworkUrl100 || "").replace("100x100bb", "600x600bb"),
preview_url: item.previewUrl || null,
spotify_url: `https://open.spotify.com/search/${encodedQuery}`,
release_date: item.releaseDate ? item.releaseDate.split("T")[0] : undefined,
};
});
return {
status: true,
creator: "vamxapi",
query: cleanQ,
total: tracks.length,
tracks,
};
}
} catch (err) {}
return {
status: false,
creator: "vamxapi",
query: cleanQ,
total: 0,
tracks: [],
};
}
/**
* 3. Search Matching Audio Source on YouTube
*/
async function searchYouTubeAudio(query) {
const cleanQ = (query || "").trim();
const searchUrl = `https://www.youtube.com/results?search_query=${encodeURIComponent(cleanQ + " audio")}`;
try {
const res = await axios.get(searchUrl, {
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",
"Accept-Language": "en-US,en;q=0.9",
},
timeout: 10000,
});
const html = res.data || "";
const match = html.match(/ytInitialData\s*=\s*({.+?});<\/script>/);
if (match) {
const data = JSON.parse(match[1]);
const section =
data.contents?.twoColumnSearchResultsRenderer?.primaryContents?.sectionListRenderer?.contents?.[0]
?.itemSectionRenderer?.contents;
if (Array.isArray(section)) {
for (const item of section) {
if (item.videoRenderer && item.videoRenderer.videoId) {
const v = item.videoRenderer;
return {
id: v.videoId,
title: v.title?.runs?.[0]?.text || "",
duration: v.lengthText?.simpleText || "",
url: `https://www.youtube.com/watch?v=${v.videoId}`,
};
}
}
}
}
} catch {}
// Fallback query tanpa suffix "audio"
try {
const res2 = await axios.get(
`https://www.youtube.com/results?search_query=${encodeURIComponent(cleanQ)}`,
{
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",
"Accept-Language": "en-US,en;q=0.9",
},
timeout: 10000,
}
);
const html2 = res2.data || "";
const match2 = html2.match(/ytInitialData\s*=\s*({.+?});<\/script>/);
if (match2) {
const data = JSON.parse(match2[1]);
const section =
data.contents?.twoColumnSearchResultsRenderer?.primaryContents?.sectionListRenderer?.contents?.[0]
?.itemSectionRenderer?.contents;
if (Array.isArray(section)) {
for (const item of section) {
if (item.videoRenderer && item.videoRenderer.videoId) {
const v = item.videoRenderer;
return {
id: v.videoId,
title: v.title?.runs?.[0]?.text || "",
duration: v.lengthText?.simpleText || "",
url: `https://www.youtube.com/watch?v=${v.videoId}`,
};
}
}
}
}
} catch {}
return null;
}
/**
* 4. Helper Dekripsi Savetube VIP (AES-128-CBC)
*/
function decryptSavetubePayload(base64Data) {
try {
const rawBuffer = Buffer.from(base64Data.replace(/\s/g, ""), "base64");
if (rawBuffer.length < 16) throw new Error("Payload buffer kurang dari 16 bytes");
const iv = rawBuffer.subarray(0, 16);
const ciphertext = rawBuffer.subarray(16);
const decipher = crypto.createDecipheriv("aes-128-cbc", SAVETUBE_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 Savetube payload: ${err.message}`);
}
}
/**
* 5. Converter Engine 1: Savetube VIP
*/
async function convertViaSavetube(videoUrl) {
let cdnHost = "cdn401.savetube.vip";
try {
const cdnRes = await axios.get("https://media.savetube.vip/api/random-cdn", {
headers: DEFAULT_HEADERS,
timeout: 6000,
});
if (cdnRes.data && cdnRes.data.cdn) {
cdnHost = cdnRes.data.cdn;
}
} catch {}
const infoRes = await axios.post(
`https://${cdnHost}/v2/info`,
{ url: videoUrl.trim() },
{ headers: DEFAULT_HEADERS, timeout: 20000 }
);
const body = infoRes.data;
if (!body || body.status === false || !body.data) {
throw new Error(body?.message || "Gagal mengambil data converter Savetube");
}
const videoData = decryptSavetubePayload(body.data);
const dlRes = await axios.post(
`https://${cdnHost}/download`,
{
downloadType: "audio",
quality: "128",
key: videoData.key,
},
{ headers: DEFAULT_HEADERS, timeout: 20000 }
);
const dlBody = dlRes.data;
if (!dlBody || dlBody.status === false || !dlBody.data?.downloadUrl) {
throw new Error(dlBody?.message || "Gagal membuat link download MP3 dari Savetube");
}
return {
rawUrl: dlBody.data.downloadUrl,
quality: "320kbps",
};
}
/**
* 6. Converter Engine 2: LbServer / SaveNow
*/
async function convertViaLbServer(videoUrl) {
const agent = new https.Agent({ rejectUnauthorized: false });
const { data } = await axios.get("https://p.lbserver.xyz/ajax/download.php", {
params: { format: "mp3", audio_quality: "128", url: videoUrl },
httpsAgent: agent,
timeout: 15000,
});
if (!data?.progress_url) throw new Error("Progress URL tidak ditemukan pada LbServer");
for (let i = 0; i < 20; i++) {
const { data: res } = await axios.get(data.progress_url, {
httpsAgent: agent,
timeout: 10000,
});
if (res.progress >= 1000 && res.download_url) {
return {
rawUrl: res.download_url,
quality: "128kbps",
};
}
await new Promise((r) => setTimeout(r, 1200));
}
throw new Error("Timeout saat menunggu konversi LbServer");
}
/**
* 7. Multi-Engine Audio Resolver (Savetube VIP -> LbServer)
*/
async function resolveRawAudioUrl(videoUrl) {
const engines = [
{ name: "Savetube VIP", fn: () => convertViaSavetube(videoUrl) },
{ name: "LbServer", fn: () => convertViaLbServer(videoUrl) },
];
let lastError = null;
for (const eng of engines) {
try {
const res = await eng.fn();
if (res && res.rawUrl) {
return res;
}
} catch (err) {
lastError = err;
}
}
throw new Error(
`Semua converter audio gagal memproses URL. Terakhir: ${lastError?.message || "Unknown error"}`
);
}
/**
* 8. PlaySpo Master Function: Cari lagu sekalian dapatkan link download MP3 di Vamx CDN
* Seluruh output file dipastikan bersumber dari Vamx CDN Only!
*
* @param {string} input - Judul lagu, artis, atau URL Spotify (https://open.spotify.com/track/...)
*/
async function playSpo(input) {
const cleanInput = String(input || "").trim();
if (!cleanInput) {
throw new Error("Parameter judul lagu atau URL Spotify wajib diisi.");
}
let trackMeta = null;
let searchQuery = cleanInput;
// 1. Ekstraksi atau Cari Lagu
if (isSpotifyUrl(cleanInput)) {
trackMeta = await getSpotifyTrackInfo(cleanInput);
searchQuery = `${trackMeta.title} ${trackMeta.artist}`.trim();
} else {
const searchRes = await searchSpotify(cleanInput, 1);
if (searchRes.status && searchRes.tracks.length > 0) {
const top = searchRes.tracks[0];
trackMeta = {
id: top.id,
title: top.title,
artist: top.artist,
album: top.album,
duration: top.duration,
duration_seconds: top.duration_seconds,
thumbnail: top.thumbnail,
spotify_url: top.spotify_url,
};
searchQuery = `${top.title} ${top.artist}`.trim();
} else {
trackMeta = {
id: "sp_" + Date.now(),
title: cleanInput,
artist: "Spotify Audio",
duration: "-",
thumbnail: "",
spotify_url: `https://open.spotify.com/search/${encodeURIComponent(cleanInput)}`,
};
}
}
// 2. Cari audio match di YouTube
const ytMatch = await searchYouTubeAudio(searchQuery);
if (!ytMatch || !ytMatch.url) {
throw new Error(`Audio tidak ditemukan untuk lagu: "${searchQuery}"`);
}
// 3. Konversi ke raw MP3 stream dari upstream engine
const audioConversion = await resolveRawAudioUrl(ytMatch.url);
// 4. UPLOAD MP3 LANGSUNG KE VAMX CDN (Strictly Vamx CDN Only)
const safeFilename = `${trackMeta.title || "spotify"} - ${trackMeta.artist || "audio"}`
.replace(/[^a-zA-Z0-9\s-_]/g, "")
.trim()
.replace(/\s+/g, "_")
.substring(0, 60);
const audioMedia = await uploadToVamxCdn(
audioConversion.rawUrl,
`${safeFilename}.mp3`,
"audio/mpeg"
);
// 5. UPLOAD THUMBNAIL KE VAMX CDN (Jika tersedia gambar)
let cdnThumbnailUrl = "";
if (trackMeta.thumbnail && trackMeta.thumbnail.startsWith("http")) {
try {
const thumbMedia = await uploadToVamxCdn(
trackMeta.thumbnail,
`thumb_${safeFilename}.webp`,
"image/webp"
);
cdnThumbnailUrl = thumbMedia.url;
} catch {
// Jika upload thumbnail gagal, jangan biarkan proses utama crash
cdnThumbnailUrl = "";
}
}
return {
status: true,
creator: "vamxapi",
result: {
id: audioMedia.id,
title: trackMeta.title,
artist: trackMeta.artist,
album: trackMeta.album || undefined,
duration: trackMeta.duration,
duration_seconds: trackMeta.duration_seconds || undefined,
thumbnail: cdnThumbnailUrl,
spotify_url: trackMeta.spotify_url,
download: {
format: "mp3",
quality: audioConversion.quality || "320kbps",
url: audioMedia.url,
size: audioMedia.size,
size_formatted: formatBytes(audioMedia.size),
cdn: "Vamx CDN",
expires_at: audioMedia.expires_at,
},
},
};
}
// Module Exports
if (typeof module !== "undefined" && module.exports) {
module.exports = {
playSpo,
searchSpotify,
getSpotifyTrackInfo,
uploadToVamxCdn,
};
}
// CLI Execution Handler
if (require.main === module) {
const args = process.argv.slice(2);
if (args.length === 0) {
console.log("=========================================================");
console.log(" PlaySpo - Spotify Search & MP3 Downloader Scraper");
console.log(" Storage: 100% Vamx Media CDN Only (cdn.vamxapi.my.id)");
console.log(" Author: Vamz Spectre (Vamx)");
console.log("=========================================================");
console.log("Penggunaan:");
console.log(" node playspo.js <judul_lagu_atau_url> # Cari lagu & download ke Vamx CDN");
console.log(" node playspo.js search <judul_lagu> # Cari list lagu");
console.log(" node playspo.js download <judul_atau_url> # Download MP3 ke Vamx CDN");
console.log("");
console.log("Contoh:");
console.log(" node playspo.js 'Komang Raim Laode'");
console.log(" node playspo.js 'https://open.spotify.com/track/4cOdK2wGLETKBW3PvgPWqT'");
console.log(" node playspo.js search 'Coldplay Yellow'");
console.log(" node playspo.js download 'Bernadya Untungnya'");
process.exit(0);
}
let command = "play";
let targetQuery = "";
const filteredArgs = args.filter((a) => a !== "--json" && a !== "--cdn");
if (["search", "download", "play"].includes(filteredArgs[0].toLowerCase())) {
command = filteredArgs[0].toLowerCase();
targetQuery = filteredArgs.slice(1).join(" ");
} else {
targetQuery = filteredArgs.join(" ");
}
if (!targetQuery) {
console.error("Error: Masukkan judul lagu atau URL Spotify.");
process.exit(1);
}
(async () => {
try {
console.log(`[PlaySpo] Memproses: "${targetQuery}" ...`);
let result;
if (command === "search") {
result = await searchSpotify(targetQuery, 10);
} else {
result = await playSpo(targetQuery);
}
console.log("\n[Hasil JSON]:");
console.log(JSON.stringify(result, null, 2));
} catch (err) {
console.error("\n[Error]", err.message);
process.exit(1);
}
})();
}