Sylvatica.

Back to Library

Spotify Play

js 1/25/2026
59
import axios from "axios";

const handler = async (conn, m, options) => {
  const { text, usedPrefix, command } = options;

  if (!text) {
    return m.reply(
      `*Example:* ${usedPrefix + command} Watch Billie Eilish`
    );
  }

  const loading = await conn.sendMessage(
    m.chat,
    { text: "*Searching...*" },
    { quoted: m }
  );

  try {
    // search
    const search = await axios.get(
      "https://api.danzy.web.id/api/search/spotify",
      { params: { q: text } }
    );

    const result = search.data?.result;
    if (!result || !result.length) {
      throw new Error("Lagu ngga ketemu");
    }

    // ambil hasil pertama
    const song = result[0];

    // download
    const download = await axios.get(
      "https://api.danzy.web.id/api/download/spotify",
      { params: { url: song.track_url } }
    );

    const dl = download.data?.result;
    if (!dl?.download_url) {
      throw new Error("Gagal dapetin link downloadnya");
    }

    // kirim audionya
    await conn.sendMessage(
      m.chat,
      {
        audio: { url: dl.download_url },
        mimetype: "audio/mpeg",
        fileName: `${dl.title}.mp3`,
        contextInfo: {
          externalAdReply: {
            title: dl.title,
            body: dl.artist,
            thumbnailUrl: dl.image || song.thumbnail,
            sourceUrl: song.track_url,
            mediaType: 1,
            renderLargerThumbnail: true
          }
        }
      },
      { quoted: m }
    );

    await conn.sendMessage(
      m.chat,
      { text: "*success*", edit: loading.key },
      { quoted: m }
    );

  } catch (e) {
    console.error(e);
    await conn.sendMessage(
      m.chat,
      {
        text: `[🍂] ${e.message}`,
        edit: loading.key
      },
      { quoted: m }
    );
  }
};

handler.command = ["spotify", "spotplay"];
handler.category = ["search"];
handler.description = "Cari lagu Spotify";
handler.help = ["spotify <judul lagu>"];
handler.tags = ["search"];
handler.limit = false;
handler.owner = false;

export default handler;