𝗗𝗔π—₯π—₯π—˜π—Ÿπ—Ÿ π— π—¨π—–π—›π—˜π—₯π—œ ⚑ commited on
Commit
64715c2
Β·
unverified Β·
1 Parent(s): b9eb633

Create dl-spotify.js

Browse files
Files changed (1) hide show
  1. 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
+ });