Spaces:
Paused
Paused
πππ₯π₯πππ π π¨ππππ₯π β‘
commited on
Create dl-spotify.js
Browse files- plugins/dl-spotify.js +68 -0
plugins/dl-spotify.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { cmd } = require('../command'); // Ensure cmd is properly defined in your project
|
| 2 |
+
|
| 3 |
+
cmd({
|
| 4 |
+
pattern: "spotify", // Command name
|
| 5 |
+
desc: "Download Spotify music by providing a link.",
|
| 6 |
+
category: "downloader",
|
| 7 |
+
use: ".spotify <Spotify URL>",
|
| 8 |
+
react: "π΅", // Added reaction
|
| 9 |
+
filename: __filename
|
| 10 |
+
},
|
| 11 |
+
async (conn, mek, m, { from, quoted, args, reply }) => {
|
| 12 |
+
try {
|
| 13 |
+
// Check if the user provided a URL
|
| 14 |
+
if (!args[0]) {
|
| 15 |
+
return reply("β Please provide a valid Spotify link!");
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
// Define the API URL with the user-provided Spotify URL
|
| 19 |
+
const spotifyUrl = args[0];
|
| 20 |
+
const apiUrl = `https://pikabotzapi.vercel.app/downloader/spotifydl/?apikey=anya-md&url=${spotifyUrl}`;
|
| 21 |
+
|
| 22 |
+
// Fetch data from the API
|
| 23 |
+
const response = await fetch(apiUrl);
|
| 24 |
+
const data = await response.json();
|
| 25 |
+
|
| 26 |
+
// Check if the API returned valid data
|
| 27 |
+
if (data && data.status === true) {
|
| 28 |
+
const {
|
| 29 |
+
title, // Song title
|
| 30 |
+
thumbnail, // URL of the cover image
|
| 31 |
+
artist, // Artist name
|
| 32 |
+
duration, // Duration of the song
|
| 33 |
+
release_date, // Release date
|
| 34 |
+
album, // Album name
|
| 35 |
+
genre, // Genre (type) of music
|
| 36 |
+
audio_url // URL of the audio file
|
| 37 |
+
} = data.result;
|
| 38 |
+
|
| 39 |
+
// Send the music details along with the cover image
|
| 40 |
+
await conn.sendMessage(from, {
|
| 41 |
+
image: { url: thumbnail },
|
| 42 |
+
caption: `π΅ *Spotify Music Details* π΅\n\n` +
|
| 43 |
+
`π *Title* : ${title}\n` +
|
| 44 |
+
`π€ *Artist* : ${artist}\n` +
|
| 45 |
+
`β³ *Duration* : ${duration}\n` +
|
| 46 |
+
`π
*Release Date* : ${release_date}\n` +
|
| 47 |
+
`πΏ *Album* : ${album}\n` +
|
| 48 |
+
`πΆ *Genre* : ${genre}\n\n` +
|
| 49 |
+
`π§ *SUBZERO MD DOWNLOADING*...`
|
| 50 |
+
}, { quoted: mek });
|
| 51 |
+
|
| 52 |
+
// Send the audio file
|
| 53 |
+
await conn.sendMessage(from, {
|
| 54 |
+
audio: { url: audio_url },
|
| 55 |
+
mimetype: 'audio/mpeg',
|
| 56 |
+
fileName: `${title}.mp3`
|
| 57 |
+
}, { quoted: mek });
|
| 58 |
+
|
| 59 |
+
} else {
|
| 60 |
+
// Handle errors if the API fails to return valid data
|
| 61 |
+
reply("β Unable to fetch the details. Please check the Spotify link.");
|
| 62 |
+
}
|
| 63 |
+
} catch (e) {
|
| 64 |
+
// Catch and log any errors during the execution
|
| 65 |
+
console.error(e);
|
| 66 |
+
await reply('β An error occurred while processing your request.');
|
| 67 |
+
}
|
| 68 |
+
});
|