music: support urls if they dont have extensions based on content type

This commit is contained in:
Cynthia Foxwell 2022-05-11 12:14:48 -06:00
parent 7c29a4e983
commit 65c9898ee5

View file

@ -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();
@ -537,21 +537,46 @@ command.callback = async function (msg, line) {
queueNext
);
}
} else {
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 {
const url = await youtubeSearch(msg, argStr);
if (url.startsWith("https://youtu.be/")) {
if (url?.startsWith("https://youtu.be/")) {
await enqueue(
msg.guildID,
msg.member.voiceState.channelID,
msg.channel.id,
url,
"yt",
msg.author.id
msg.author.id,
false,
queueNext
);
} else {
return url;
}
}
}
} else {
return "You are not in a voice channel.";
}