You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
6 years ago
|
const { Command } = require('discord-akairo');
|
||
|
const { MessageEmbed } = require('discord.js');
|
||
|
const fpcalc = require('fpcalc');
|
||
|
const fetch = require('node-fetch');
|
||
|
const youtubedl = require('youtube-dl');
|
||
|
const fs = require('fs');
|
||
|
|
||
|
|
||
|
class musicCommand extends Command {
|
||
|
constructor() {
|
||
|
super('musicMatch', {
|
||
|
aliases: ['musicMatch', 'music', 'shazam', 'soundhound'],
|
||
|
category: 'utility',
|
||
|
quoted: false,
|
||
|
args: [
|
||
|
{
|
||
|
id: 'music',
|
||
|
type: 'string',
|
||
|
match: 'rest'
|
||
|
}
|
||
|
],
|
||
|
description: {
|
||
|
content: 'Find what music it is from attachment or link',
|
||
|
usage: '[file]',
|
||
|
examples: ['[file]']
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
async exec(message,args) {
|
||
|
let link;
|
||
|
let Attachment = (message.attachments).array();
|
||
|
if (!args.music && Attachment[0]) {
|
||
|
link = Attachment[0].url;
|
||
|
} else {
|
||
|
link = args.music;
|
||
|
}
|
||
|
|
||
|
|
||
|
let video = youtubedl(link, ['-x', '--audio-format', 'mp3']);
|
||
|
video.pipe(fs.createWriteStream('./music.mp3'));
|
||
|
video.on('error', function error(err) {
|
||
|
console.log('error 2:', err);
|
||
|
message.channel.send('An error has occured, I can\'t download from the link you provided.');
|
||
|
});
|
||
|
video.on('end', function () {
|
||
|
fpcalc('./music.mp3', function(err, result) {
|
||
|
if (err) throw err;
|
||
|
fetch(`https://api.acoustid.org/v2/lookup?client=LRAhvvxpDu&meta=recordings+releasegroups+compress&duration=${result.duration}&fingerprint=${result.fingerprint}`).then((response) => {
|
||
|
return response.json();
|
||
|
}).then((response) => {
|
||
|
if (!response.results[0])
|
||
|
return message.channel.send('Could not identify the music');
|
||
|
|
||
|
const musicEmbed = new MessageEmbed()
|
||
|
.setColor('#ff9900')
|
||
|
.setTitle('Music found!')
|
||
|
.addField('Title', response.results[0].recordings[0].title, true)
|
||
|
.addField('Artist', response.results[0].recordings[0].artists[0].name, true)
|
||
|
.addField('Album', response.results[0].recordings[0].releasegroups[0].title, true);
|
||
|
|
||
|
|
||
|
message.channel.send(musicEmbed);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = musicCommand;
|