MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/itunes.js:7–51  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

5 description: 'Get detailed information about a song from iTunes',
6 usage: '.itunes <song name>',
7 async handler(sock, message, args, context) {
8 const chatId = context.chatId || message.key.remoteJid;
9 const text = args.join(' ').trim();
10 if (!text) {
11 await sock.sendMessage(chatId, {
12 text: '*Please provide a song name.*\nExample: `.itunes Blinding Lights`',
13 quoted: message
14 });
15 return;
16 }
17 try {
18 const url = `https://api.popcat.xyz/itunes?q=${encodeURIComponent(text)}`;
19 const res = await fetch(url);
20 if (!res.ok)
21 throw new Error(`API request failed with status ${res.status}`);
22 const json = await res.json();
23 const songInfo = `
24🎵 *${json.name || 'N/A'}*
25👤 *Artist:* ${json.artist || 'N/A'}
26💿 *Album:* ${json.album || 'N/A'}
27📅 *Release Date:* ${json.release_date || 'N/A'}
28💰 *Price:* ${json.price || 'N/A'}
29⏱️ *Length:* ${json.length || 'N/A'}
30🎼 *Genre:* ${json.genre || 'N/A'}
31🔗 *URL:* ${json.url || 'N/A'}
32 `.trim();
33 if (json.thumbnail) {
34 await sock.sendMessage(chatId, {
35 image: { url: json.thumbnail },
36 caption: songInfo,
37 quoted: message
38 });
39 }
40 else {
41 await sock.sendMessage(chatId, { text: songInfo, quoted: message });
42 }
43 }
44 catch (error) {
45 console.error('iTunes Command Error:', error);
46 await sock.sendMessage(chatId, {
47 text: '❌ An error occurred while fetching the song info. Please try again later.',
48 quoted: message
49 });
50 }
51 }
52};

Callers

nothing calls this directly

Calls 1

jsonMethod · 0.80

Tested by

no test coverage detected