Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async run(message, [query]) {
const music_settings = message.guildSettings.get('music');
moment.locale(message.guildSettings.get('momentLanguage'));
if (!this._getVoiceChannel(message)) return message.channel.sendLocale('MUSIC_NOTINVOICECHANNEL');
/* Planned Removal */
/*for (let i = 0; i < message.client.provider.getGuild(message.guild.id, 'musicchannelblacklist').length; i++) {
if (voiceChannel.id === message.client.provider.getGuild(message.guild.id, 'musicchannelblacklist')[i]) return message.reply(lang.play_blacklistchannel);
}*/
/* Planned Removal */
if ((ytdl.validateURL(query) || ytdl.validateID(query)) && !query.includes(' ')) { // youtube video
/**
* @property { videoId, url, title, description, owner, channelId, thumbnailUrl, embedURL, datePublished, genre, paid, unlisted, isFamilyFriendly, duration, views, regionsAllowed, dislikeCount, likeCount, channelThumbnailUrl, commentCount }
*/
this._pushToQueue(message, await this._getYoutubeVideoInfo(ytdl.getVideoID(query)));
} else if ((regexes.youtube_playlist.test(query) || (query.length >= 20 && query.length <= 34)) && !query.includes(' ') && decodeURIComponent(query).includes('/playlist?list=')) { // youtube playlist
await message.send({ embed: { description: message.language.get('LOADING_MESSAGE'), color: 7506394 } });
const videos = (await this._getYoutubePlaylistVideos(query)).map((info) => this._pushToQueue(message, info, { is_playlist: true }));
await message.send({ embed: { description: message.language.get('MUSIC_ADDEDNUMITEMSTOQUEUE', videos.length), color: 7506394 } });
} else if (!query.includes(' ') && regexes.domain_name.test(query) && !ytdl.validateURL(query)) { // radio stream
const track = new StreamTrack(message, query);
await track._autoFill();
this._pushToQueue(message, track, { is_stream: true })
//this._pushToQueue(message, { url: query, duration: Infinity }, { is_stream: true });
} else { // play from stream [only supports youtube and radio streams currently]
if (query.toLowerCase().startsWith('yt:')) {
await this._searchForYoutubeVideo(message, query.replace(/^yt\:/i, '')); // if query starts with `yt:` search for youtube video
} else {
await this._searchForYoutubeVideo(message, query); // if none match default to youtube
}
match ( video : string, subtitles : YoutubeSubtitleResult[] ) : YoutubeSubtitleResult {
const id = ytdl.getVideoID( video );
let result = this.findLanguage( this.languages, subtitles );
if ( result ) {
// console.log( result );
return {
language: result.lang_code,
url: `${ this.downloadEndpoint }?lang=${ result.lang_code }&v=${ id }&fmt=${ this.format }`,
format: this.format
}
}
let englishLanguage = this.findLanguage( [ 'en', 'en-US', 'en-UK' ], subtitles );
let original = ( englishLanguage || subtitles[ 0 ] ).lang_code;
let results = '';
await video_queue.map((video, index) => results += `\n${index + 1}. [${escapeMarkdown(video.title)}](${video.uri})`);
if (video_queue.length > 1) {
await message.prompt({
embed: {
color: 0x43B581,
description: message.language.get('MULTIPLE_ITEMS_FOUND_PROMPT', results)
}
}).then(async (choices) => {
if (choices.content.toLowerCase() === message.language.get('ANSWER_CANCEL_PROMPT') || !parseInt(choices.content)) return message.sendLocale('MESSAGE_PROMPT_CANCELLED');
const answer = video_queue[parseInt(choices.content) - 1];
if (parseInt(choices.content) - 1 < 0 || parseInt(choices.content) - 1 > video_queue.length - 1) return message.sendLocale('MESSAGE_PROMPT_CANCELLED');
return this._pushToQueue(message, await this._getYoutubeVideoInfo(ytdl.getVideoID(answer.uri)));
}).catch(console.error);
} else if (video_queue.length === 1) {
return this._pushToQueue(message, await this._getYoutubeVideoInfo(ytdl.getVideoID(video_queue[0].uri)));
}
}
}).then(async (choices) => {
if (choices.content.toLowerCase() === message.language.get('ANSWER_CANCEL_PROMPT') || !parseInt(choices.content)) return message.sendLocale('MESSAGE_PROMPT_CANCELLED');
const answer = video_queue[parseInt(choices.content) - 1];
if (parseInt(choices.content) - 1 < 0 || parseInt(choices.content) - 1 > video_queue.length - 1) return message.sendLocale('MESSAGE_PROMPT_CANCELLED');
return this._pushToQueue(message, await this._getYoutubeVideoInfo(ytdl.getVideoID(answer.uri)));
}).catch(console.error);
} else if (video_queue.length === 1) {
async list ( video : string ) : Promise {
const id = ytdl.getVideoID( video );
const response = await got( this.listEndpoint + '&v=' + id );
const xml = await this.xml( response.body );
if ( !xml.transcript_list.track ) {
return [];
}
return xml.transcript_list.track.map( o => o.$ );
}