-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCybermus.js
63 lines (50 loc) · 2.08 KB
/
Cybermus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import fs from 'fs';
import acrcloud from 'acrcloud';
import config from '../../config.cjs';
const acr = new acrcloud({
host: 'identify-eu-west-1.acrcloud.com',
access_key: '716b4ddfa557144ce0a459344fe0c2c9',
access_secret: 'Lz75UbI8g6AzkLRQgTgHyBlaQq9YT5wonr3xhFkf'
});
const shazam = async (m, gss) => {
try {
const prefix = config.PREFIX;
const cmd = m.body.startsWith(prefix) ? m.body.slice(prefix.length).split(' ')[0].toLowerCase() : '';
const text = m.body.slice(prefix.length + cmd.length).trim();
const validCommands = ['shazam', 'bonifinder', 'whatmusic'];
if (!validCommands.includes(cmd)) return;
const quoted = m.quoted || {};
if (!quoted || (quoted.mtype !== 'audioMessage' && quoted.mtype !== 'videoMessage')) {
return m.reply('You asked about music. Please provide a quoted audio or video message for identification.');
}
const mime = m.quoted.mimetype;
try {
const media = await m.quoted.download();
const filePath = `./${Date.now()}.mp3`;
fs.writeFileSync(filePath, media);
m.reply('Identifying the music, please wait...');
const res = await acr.identify(fs.readFileSync(filePath));
const { code, msg } = res.status;
if (code !== 0) {
throw new Error(msg);
}
const { title, artists, album, genres, release_date } = res.metadata.music[0];
const txt = `𝚁𝙴𝚂𝚄𝙻𝚃
• 📌 *TITLE*: ${title}
• 👨🎤 𝙰𝚁𝚃𝙸𝚂𝚃: ${artists ? artists.map(v => v.name).join(', ') : 'NOT FOUND'}
• 💾 𝙰𝙻𝙱𝚄𝙼: ${album ? album.name : 'NOT FOUND'}
• 🌐 𝙶𝙴𝙽𝚁𝙴: ${genres ? genres.map(v => v.name).join(', ') : 'NOT FOUND'}
• 📆 RELEASE DATE: ${release_date || 'NOT FOUND'}
`.trim();
fs.unlinkSync(filePath);
m.reply(txt);
} catch (error) {
console.error(error);
m.reply('An error occurred during music identification.');
}
} catch (error) {
console.error('Error:', error);
m.reply('An Error Occurred While Processing The Command.');
}
};
export default shazam;