From 4d8d129f84b1ecf885dfd2fd05d67d8bbf263445 Mon Sep 17 00:00:00 2001 From: White Shadow Ofc Date: Tue, 23 Apr 2024 08:37:06 +0530 Subject: [PATCH] =?UTF-8?q?[=20Jessi-md=20V-=205.0.0=E2=98=87=20]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/itunes.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 plugins/itunes.js diff --git a/plugins/itunes.js b/plugins/itunes.js new file mode 100644 index 00000000..ea1773b9 --- /dev/null +++ b/plugins/itunes.js @@ -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;