Created
December 9, 2025 09:29
-
-
Save Reyz2902/b02bac101c6579738d6d99c5b9f8b392 to your computer and use it in GitHub Desktop.
Uploaded via Theresa
This file contains hidden or 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
| const axios = require('axios'); | |
| const FormData = require('form-data'); | |
| const fs = require('fs'); | |
| const { | |
| tmpdir | |
| } = require('os'); | |
| const { | |
| join | |
| } = require('path'); | |
| /** | |
| * Identifies a song from an audio file using the Aha-Music (doreso.com) API. | |
| * @param {string} path Path to the audio file. | |
| * @returns {Promise<object>} The API response. | |
| */ | |
| async function aha_music(path) { | |
| const form = new FormData(); | |
| // Using a stream is more memory-efficient for file uploads | |
| form.append('file', fs.createReadStream(path)); | |
| form.append('sample_size', 118784); | |
| const { | |
| data | |
| } = await axios.post( | |
| 'https://api.doreso.com/humming', | |
| form, { | |
| headers: { | |
| ...form.getHeaders(), | |
| 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36', | |
| 'accept': 'application/json, text/plain, */*', | |
| 'origin': 'https://www.aha-music.com', | |
| 'referer': 'https://www.aha-music.com/' | |
| }, | |
| maxBodyLength: Infinity, | |
| maxContentLength: Infinity | |
| } | |
| ); | |
| return data; | |
| } | |
| let handler = async (m, { | |
| conn | |
| }) => { | |
| const q = m.quoted ? m.quoted : m; | |
| const mime = (q.msg || q).mimetype || ''; | |
| if (!/audio/.test(mime)) { | |
| return conn.sendMessage(m.chat, { | |
| text: 'Please reply to an audio message to find the song.' | |
| }, { | |
| quoted: m | |
| }); | |
| } | |
| m.react('š¶'); | |
| let tmpPath; | |
| try { | |
| const media = await q.download(); | |
| tmpPath = join(tmpdir(), `${Date.now()}.mp3`); | |
| await fs.promises.writeFile(tmpPath, media); | |
| const result = await aha_music(tmpPath); | |
| if (result && result.data && result.data.title) { | |
| const { | |
| title, | |
| artists | |
| } = result.data; | |
| const caption = `šµ *Song Found!*\n\n*Title:* ${title}\n*Artist:* ${artists}`; | |
| await conn.sendMessage(m.chat, { | |
| text: caption | |
| }, { | |
| quoted: m | |
| }); | |
| m.react('ā '); | |
| } else { | |
| await conn.sendMessage(m.chat, { | |
| text: 'Could not identify the song. The audio might be too short or unclear.' | |
| }, { | |
| quoted: m | |
| }); | |
| m.react('ā'); | |
| } | |
| } catch (e) { | |
| console.error(e); | |
| await conn.sendMessage(m.chat, { | |
| text: 'An error occurred while processing your request.' | |
| }, { | |
| quoted: m | |
| }); | |
| m.react('ā'); | |
| } finally { | |
| // Clean up the temporary file | |
| if (tmpPath && fs.existsSync(tmpPath)) { | |
| fs.unlinkSync(tmpPath); | |
| } | |
| } | |
| }; | |
| handler.command = ['findsong', 'whatsong', 'shazam']; | |
| handler.help = ['findsong']; | |
| handler.tags = ['tools']; | |
| handler.description = 'Find the title of a song by replying to an audio message.'; | |
| module.exports = handler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment