From 0a1474887d262e202cd284d4518da04dbcca2725 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Wed, 16 Jan 2019 00:29:10 +0100 Subject: [PATCH] Only support mp3 wav mp4 webm --- commands/utility/musicMatch.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/commands/utility/musicMatch.js b/commands/utility/musicMatch.js index 471227b5..6659f784 100644 --- a/commands/utility/musicMatch.js +++ b/commands/utility/musicMatch.js @@ -31,12 +31,18 @@ class musicCommand extends Command { async exec(message,args) { let link; let Attachment = (message.attachments).array(); + + + if (!args.music && Attachment[0]) { + if (!Attachment[0].url.endsWith('mp3' || 'wav' || 'mp4' || 'webm')) + return message.channel.send('Only mp3,wav,mp4 and webm are supported'); link = Attachment[0].url; } else { link = args.music; + if (!link.endsWith('mp3' || 'wav' || 'mp4' || 'webm')) + return message.channel.send('Only mp3,wav,mp4 and webm are supported'); } - let video = youtubedl(link, ['-x', '--audio-format', 'mp3']); video.pipe(fs.createWriteStream('./music.mp3')); @@ -53,12 +59,17 @@ class musicCommand extends Command { if (!response.results[0]) return message.channel.send('Could not identify the music'); + let time = response.results[0].recordings[0].duration; + let minutes = Math.floor(time / 60); + let seconds = time - minutes * 60; + 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); + .addField('Album', response.results[0].recordings[0].releasegroups[0].title, true) + .addField('Duration', `${minutes}:${seconds}`); message.channel.send(musicEmbed);