(sock, message, args, context)
| 39 | description: 'Identify a song from audio or video', |
| 40 | usage: '.shazam (reply to audio or video)', |
| 41 | async handler(sock, message, args, context) { |
| 42 | const chatId = context.chatId || message.key.remoteJid; |
| 43 | try { |
| 44 | const media = getAudioOrVideo(message); |
| 45 | if (!media) { |
| 46 | return await sock.sendMessage(chatId, { text: '⚠️ *RESPOND TO AN AUDIO OR VIDEO*' }, { quoted: message }); |
| 47 | } |
| 48 | const buffer = await downloadMedia(media.msg, media.type); |
| 49 | const tmpDir = path.join(process.cwd(), 'tmp'); |
| 50 | if (!fs.existsSync(tmpDir)) |
| 51 | fs.mkdirSync(tmpDir, { recursive: true }); |
| 52 | const tmpPath = path.join(tmpDir, `${Date.now()}${media.ext}`); |
| 53 | fs.writeFileSync(tmpPath, buffer); |
| 54 | const res = await acr.identify(fs.readFileSync(tmpPath)); |
| 55 | fs.unlinkSync(tmpPath); |
| 56 | const { code, msg } = res.status; |
| 57 | if (code !== 0) |
| 58 | throw msg; |
| 59 | const music = res.metadata.music?.[0]; |
| 60 | if (!music) |
| 61 | throw new Error('No match found'); |
| 62 | const text = ` |
| 63 | 𝚁𝙴𝚂𝚄𝙻𝚃 |
| 64 | • 📌 *TITLE*: ${music.title || 'NOT FOUND'} |
| 65 | • 👨🎤 *ARTIST*: ${music.artists?.map((a) => a.name).join(', ') || 'NOT FOUND'} |
| 66 | • 💾 *ALBUM*: ${music.album?.name || 'NOT FOUND'} |
| 67 | • 🌐 *GENRE*: ${music.genres?.map((g) => g.name).join(', ') || 'NOT FOUND'} |
| 68 | • 📆 *RELEASE DATE*: ${music.release_date || 'NOT FOUND'} |
| 69 | `.trim(); |
| 70 | await sock.sendMessage(chatId, { text }, { quoted: message }); |
| 71 | } |
| 72 | catch (err) { |
| 73 | console.error('[SHZ]', err); |
| 74 | await sock.sendMessage(chatId, { text: `❌ Error: ${err}` }, { quoted: message }); |
| 75 | } |
| 76 | } |
| 77 | }; |
nothing calls this directly
no test coverage detected