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
1 changed files with 36 additions and 11 deletions

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();
@ -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 {