How to use the ytdl-core.validateURL function in ytdl-core

To help you get started, we’ve selected a few ytdl-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LenoxBot / LenoxBot / src / commands / Music / play.js View on Github external
}).then((connection) => {
			// Play the video.
			try {
				if (!current_audio) return message.channel.sendLocale('MUSIC_UNABLETOPLAYAUDIO');
				
				const dispatcher =/*!music_settings.stream_mode ?*/ connection.play(ytdl.validateURL(current_audio.url) ? ytdl(current_audio.url, { filter: 'audioonly' }) : current_audio.url, { volume: music_settings.volume / 100 });

				connection.once('failed', (reason) => {
					console.error(`Connection failed: ${reason.toString()}`);
					if (message && message.channel) message.channel.send(reason.toString());
					try {
						if (connection) connection.disconnect();
					} catch (err) {
						console.error(err.stack ? err.stack : err.toString());
					};
				});
				
				connection.once('error', (err) => {
					console.error(`Connection error: ${err.stack ? err.stack : err.toString()}`);
					if (message && message.channel) message.channel.sendLocale('MUSIC_CONNECTIONERROR', [err.toString()]);
					if (queue.length) {
						if (music_settings.loop && !current_audio.repeat) {
github LenoxBot / LenoxBot / src / commands / Music / play.js View on Github external
/* 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
			}
			// search for builtin radio name or youtube video
			//otherwise it's a search query for youtube
		}

		if (music_settings.queue.length === 1 || !this._getVoiceConnection(message)) await this._executeQueue(message, music_settings.queue);
github Aveek-Saha / ytdx / src / renderer / components / LandingPage.vue View on Github external
checkURL(link) {
        const that = this
        this.formats = []
        if(ytdl.validateURL(link)){
          if(this.url.split("?")[0] != "https://www.youtube.com/playlist"){
            this.playlist = false;
            this.list = []

          }
          const info = ytdl.getInfo(link, (err, data) =>{
            console.log(data.title);
            that.name = data.title
            data.formats.forEach(format => {
              if(format.resolution)
                that.formats.push([format.container, format.resolution])
            });
          })
        }
        else if(this.url.split("?")[0] == "https://www.youtube.com/playlist") {
          this.playlist = true;
github omgimanerd / audio-spatializer / server.js View on Github external
app.post('/stream/:videoId', (request, response) => {
  const videoId = request.params.videoId
  const videoUrl = `https://www.youtube.com/watch?v=${videoId}`
  if (!ytdl.validateURL(videoUrl)) {
    response.send({ success: false })
  } else {
    ytdl(videoUrl, { filter: format => format.container === 'mp4' })
      .pipe(response)
  }
})
github LenoxBot / LenoxBot / src / commands / Music / play.js View on Github external
			const videos = await crawl(query).filter((video) => video.title && video.uri && ytdl.validateURL(video.uri));
			if (!videos.length) throw message.language.get('MUSIC_UNABLETOFINDVIDEO');
github onhernandes / soundman / api / lib / youtube / youtube.js View on Github external
function Youtube (music) {
  if (!yt.validateURL(music.url)) {
    throw new Error(`Given music URL is invalid!`)
  }

  this.url = music.url
  this.music = music
  this.video_id = yt.getURLVideoID(music.url)
}