Skip to content

Commit

Permalink
change file check from thenable to async
Browse files Browse the repository at this point in the history
  • Loading branch information
200percentmicky committed Jun 7, 2023
1 parent 2a58a3d commit 7b1b115
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/listeners/addSong.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ module.exports = class ListenerAddSong extends Listener {

// Check if ffprobe can find any any additional metadata if none is available.
if (this.client.utils.hasExt(song.url)) {
await ffprobe(song.url, { path: ffprobeStatic.path }).then(info => {
if (song.metadata?.isRadio) return;
try {
const info = await ffprobe(song.url, { path: ffprobeStatic.path });

// Ffmpeg parses images as videos with just one single frame. So, to check
// whether the file is a video or an audio file, the best way would be to
Expand All @@ -83,17 +83,20 @@ module.exports = class ListenerAddSong extends Listener {
// will be checked instead.
if (!info.streams[0].duration || info.streams[0].codec_name === 'ansi') {
this.client.ui.reply(message, 'error', 'The attachment must be an audio or a video file.');
return queue.songs.pop();
if (queue.songs.length === 1) return this.client.player.stop(guild);
else return queue.songs.pop();
}

const time = Math.floor(info.streams[0].duration);
song.isFile = true;
song.duration = time;
song.formattedDuration = toColonNotation(time + '000');
song.codec = `${info.streams[0].codec_long_name} (\`${info.streams[0].codec_name}\`)`;
}).catch(() => {
} catch {
this.client.ui.reply(message, 'error', 'Invalid data was provided while processing the file, or the file is not supported.');
});
if (queue.songs.length === 1) return this.client.player.stop(guild);
else return queue.songs.pop();
}
}

// Stupid fix to make sure that the queue doesn't break.
Expand Down

0 comments on commit 7b1b115

Please sign in to comment.