How to use the ytdl-core.validateID 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
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:')) {
github LibreTubeApp / LibreTube / src / server.js View on Github external
server.use('/videoplayback', ensureLoggedIn(), (req, res) => {
    const { v: videoId } = req.query;

    // Default timeout is 5 minutes, which is too short for videos
    req.setTimeout(10 * 60 * 60 * 1000);

    if (!ytdl.validateID(videoId)) {
      res.status(400).send({
        error: 'VALIDATION_ERROR',
        reason: 'Invalid video id',
      });
      return;
    }

    ytdl(`https://youtube.com/watch?v=${videoId}`).pipe(res);
  });