← back to browse
goat command

spotify

No description

0
views
0
likes
0
installs
raw source
const axios = require("axios");

/**
 * ๐Ÿ”ด ROOT FIX
 * GoatBot V2 DOES NOT auto-create handleReply
 */
if (!global.client.handleReply) {
  global.client.handleReply = [];
}

module.exports = {
  config: {
    name: "spotify",
    version: "1.1.0",
    author: "April Manalo (auto-download fix by Grok)",
    role: 0,
    category: "music",
    guide: "-spotify <song name>"
  },

  // ==========================
  // START COMMAND - AUTO DOWNLOAD FIRST RESULT
  // ==========================
  onStart: async function ({ api, event, args }) {
    try {
      const { threadID } = event;
      const query = args.join(" ").trim();

      if (!query) {
        return api.sendMessage(
          "โš ๏ธ Usage: -spotify <song name>\nExample: -spotify perfect ed sheeran",
          threadID
        );
      }

      await api.sendMessage("๐Ÿ”Ž Searching Spotify for the best match...", threadID);

      // Search Spotify
      const searchRes = await axios.get(
        "https://norch-project.gleeze.com/api/spotify",
        { params: { q: query } }
      );

      const songs = searchRes.data?.results;

      if (!songs || songs.length === 0) {
        return api.sendMessage("โŒ No results found for your query.", threadID);
      }

      // Awtomatikong kunin ang PINAKAUNANG result
      const song = songs[0];

      await api.sendMessage(
        `โœ… Found & Downloading:\n๐ŸŽต ${song.title}\n๐Ÿ‘ค ${song.artist}\nโฑ ${song.duration}`,
        threadID
      );

      if (!song.spotify_url) {
        return api.sendMessage("โŒ Error: Spotify URL not found.", threadID);
      }

      // Download ang track
      const dlRes = await axios.get(
        "https://norch-project.gleeze.com/api/spotify-dl-v2",
        { params: { url: song.spotify_url } }
      );

      const track = dlRes.data?.trackData?.[0];

      if (!track || !track.download_url) {
        return api.sendMessage("โŒ Failed to get download link.", threadID);
      }

      // Send cover image + title
      if (track.image) {
        await api.sendMessage(
          {
            body: `๐ŸŽง ${track.name}\n๐Ÿ‘ค ${track.artists}\n\nEnjoy your music! ๐ŸŽถ`,
            attachment: await global.utils.getStreamFromURL(track.image)
          },
          threadID
        );
      }

      // Send ang MP3 file
      await api.sendMessage(
        {
          body: "๐Ÿ“ Here's your audio file:",
          attachment: await global.utils.getStreamFromURL(track.download_url)
        },
        threadID
      );

      await api.sendMessage("โœ… Download complete! ๐ŸŽ‰", threadID);

    } catch (err) {
      console.error("[SPOTIFY ERROR]", err);
      api.sendMessage("โŒ Something went wrong while downloading. Try again later.", event.threadID);
    }
  }
};

View raw file