-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66fc1e3
commit 4d8d129
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import fetch from 'node-fetch'; | ||
|
||
let itunesHandler = async (m, { conn, text }) => { | ||
if (!text) throw 'Please provide a song name'; | ||
|
||
try { | ||
let res = await fetch(`https://api.popcat.xyz/itunes?q=${encodeURIComponent(text)}`); | ||
|
||
if (!res.ok) { | ||
throw new Error(`API request failed with status ${res.status}`); | ||
} | ||
|
||
let json = await res.json(); | ||
|
||
console.log('JSON response:', json); | ||
|
||
let songInfo = | ||
`*Song Information:*\n | ||
• *Name:* ${json.name}\n | ||
• *Artist:* ${json.artist}\n | ||
• *Album:* ${json.album}\n | ||
• *Release Date:* ${json.release_date}\n | ||
• *Price:* ${json.price}\n | ||
• *Length:* ${json.length}\n | ||
• *Genre:* ${json.genre}\n | ||
• *URL:* ${json.url}`; | ||
|
||
// Check if thumbnail is present, then send it with songInfo as caption | ||
if (json.thumbnail) { | ||
await conn.sendFile(m.chat, json.thumbnail, 'thumbnail.jpg', songInfo, m); | ||
} else { | ||
m.reply(songInfo); | ||
} | ||
|
||
} catch (error) { | ||
console.error(error); | ||
// Handle the error appropriately | ||
} | ||
}; | ||
|
||
itunesHandler.help = ['itunes']; | ||
itunesHandler.tags = ['tools']; | ||
itunesHandler.command = /^(itunes)$/i; | ||
|
||
export default itunesHandler; |