Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!suffix) {
return msg.channel.send(musicbot.note("fail", "No video specified!"));
}
if (musicbot.getQueue(msg.guild.id).songs.length >= musicbot.maxQueueSize && musicbot.maxQueueSize !== 0) {
return msg.channel.send(musicbot.note("fail", "Maximum queue size reached!"));
}
let searchstring = suffix.trim();
if (searchstring.includes("youtu.be/") || searchstring.includes("youtube.com/")) {
if (searchstring.includes("&")) {
searchstring = searchstring.split("&")[0];
}
if (searchstring.includes("watch") || searchstring.includes("youtu.be/")) {
// Youtube video url detected:
msg.channel.send(musicbot.note("search", "Get song from Youtube url~"));
ytdl.getBasicInfo(searchstring, {}, (err, info) => {
if (err) {
return msg.channel.send(musicbot.note("fail", "Something went wrong fetching the video!"));
}
const queue = musicbot.getQueue(msg.guild.id);
const video = {};
video.url = info.video_url;
video.channelTitle = info.author.name;
video.channelURL = info.author.channel_url || info.author.user_url;
video.requester = msg.author.id;
video.position = queue.songs ? queue.songs.length : 0;
video.queuedOn = new Date().toLocaleDateString(musicbot.dateLocal, {"weekday": "long", "hour": "numeric"});
if (musicbot.requesterName) {
video.requesterAvatarURL = msg.author.displayAvatarURL;
}
queue.songs.push(video);
if (queue.songs.length === 1 || !baseClient.voiceConnections.find((val) => val.channel.guild.id === msg.guild.id)) {
async function fetchVideoFromSingle(videoUrl: string): Promise {
try {
const { title, video_id } = await getBasicInfo(videoUrl);
return [createVideoEntity(title, video_id)];
} catch (error) {
return [];
}
}
return new Promise((resolve, reject) => {
ytdl.getBasicInfo(searchString, {}, (err, info) => {
if (err) {
return reject(new Error("Something went wrong fetching the song!"));
}
const song = new Song();
song.title = info.title;
song.url = info.video_url;
song.artist = info.author.name;
song.src = Song.srcType.YT;
return resolve([song]);
});
});
}