Note: This package is a copy of https://github.com/RemyK888/quick-yt-search
The QuickYtSearch is a simple way to find videos, playlists and channels on YouTube and get informations about them.
Basic Stuff
const QuickYtSearch = require('easy-youtube-searcher');
const YoutubeSearcher = new QuickYtSearch({
YtApiKey: 'Your key here',
});
Note: The YouTube API key is required.
Find YouTube video
YoutubeSearcher.getVideo('some video').then(video => {
});
Find YouTube playlist
YoutubeSearcher.getPlaylist('some playlist').then(playlist => {
});
Find YouTube channel
YoutubeSearcher.getChannel('some channel').then(channel => {
});
Check video URL
if(YoutubeSearcher.isVideoUrl('some video url') === true) {
console.log('OMG, it\'s a video');
} else {
console.log('NOPE');
};
Check playlist URL
if(YoutubeSearcher.isPlaylistUrl('some playlist url') === true) {
console.log('OMG, it\'s a playlist');
} else {
console.log('NOPE');
};
Check channel URL
if(YoutubeSearcher.isChannelUrl('some channel url') === true) {
console.log('OMG, it\'s a channel');
} else {
console.log('NOPE');
};
Video properties
Video.channelId,
Video.channelTitle,
Video.defaultThumbnail,
Video.description,
Video.highThumbnail,
Video.id,
Video.liveBroadcastContent,
Video.mediumThumbnail,
Video.publishedAt,
Video.publishedTime,
Video.title,
Video.url
Playlist properties
Playlist.channelId,
Playlist.channelTitle,
Playlist.defaultThumbnail,
Playlist.description,
Playlist.highThumbnail,
Playlist.id,
Playlist.liveBroadcastContent,
Playlist.mediumThumbnail,
Playlist.publishedAt,
Playlist.publishedTime,
Playlist.title,
Playlist.url
Channel properties
Channel.createdAt,
Channel.createdTime,
Channel.defaultThumbnail,
Channel.description,
Channel.highThumbnail,
Channel.id,
Channel.liveBroadcastContent,
Channel.mediumThumbnail,
Channel.title,
Channel.url
Code example (with Discord bot, using discord.js and ytdl-core)
const QuickYtSearch = require('easy-youtube-searcher');
const Discord = require('discord.js');
const ytdl = require('ytdl-core');
const client = new Discord.Client({ disableMentions: 'everyone' });
const YoutubeSearcher = new QuickYtSearch({
YtApiKey: 'Some YouTube Api key',
});
const config = {
token: 'Some Discord bot token',
prefix: '!'
};
client.on('message', async message => {
if (message.content.startsWith(config.prefix + 'play')) {
if (message.member.voice.channel) {
let args = message.content.split(' ').slice(1).join(' ');
if (!args) {
message.reply('No args inserted.');
};
message.member.voice.channel.join()
.then(connection => {
if (YoutubeSearcher.isVideoUrl(args) === false) {
YoutubeSearcher.getVideo(args).then(video => {
const volume = { volume: 0.5 };
const dispatcher = connection.play(ytdl(video.url, { filter: 'audioonly' }, volume));
message.reply('Now playing ' + video.url);
dispatcher.on("end", () => {
message.reply('End of the song.');
message.member.voice.channel.leave();
dispatcher.end();
});
});
} else {
const volume = { volume: 0.5 };
const dispatcher = connection.play(ytdl(args, { filter: 'audioonly' }, volume));
message.reply('Now playing ' + args);
dispatcher.on("end", () => {
message.reply('End of the song.')
message.member.voice.channel.leave();
dispatcher.end();
});
};
});
} else {
message.reply('You need to join a voice channel.');
};
};
});
client.login(config.token);
Note: This package is not affiliated with YouTube Inc.