From 65c9898ee5ca5d208b09f81d419a9552b73f0dc4 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Wed, 11 May 2022 12:14:48 -0600 Subject: [PATCH] music: support urls if they dont have extensions based on content type --- src/modules/music.js | 47 +++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/modules/music.js b/src/modules/music.js index 8daf39d..4785bc8 100644 --- a/src/modules/music.js +++ b/src/modules/music.js @@ -215,7 +215,7 @@ async function enqueue( highWaterMark: 1 << 25, }); } else if (type == "sc") { - if (url.startsWith("sc:")) + if (url?.startsWith("sc:")) url = url.replace(/^sc:/, "https://soundcloud.com/"); const client_id = await getSoundcloudClientID(); @@ -538,18 +538,43 @@ command.callback = async function (msg, line) { ); } } else { - const url = await youtubeSearch(msg, argStr); - if (url.startsWith("https://youtu.be/")) { - await enqueue( - msg.guildID, - msg.member.voiceState.channelID, - msg.channel.id, - url, - "yt", - msg.author.id + if (argStr.match(/https?:\/\//)) { + const contentType = await fetch(argStr).then((res) => + res.headers.get("Content-Type") ); + if ( + contentType.startsWith("audio/") || + contentType.startsWith("video/") + ) { + await enqueue( + msg.guildID, + msg.member.voiceState.channelID, + msg.channel.id, + argStr, + "file", + msg.author.id, + false, + queueNext + ); + } else { + return "Unsupported content type."; + } } else { - return url; + const url = await youtubeSearch(msg, argStr); + if (url?.startsWith("https://youtu.be/")) { + await enqueue( + msg.guildID, + msg.member.voiceState.channelID, + msg.channel.id, + url, + "yt", + msg.author.id, + false, + queueNext + ); + } else { + return url; + } } } } else {