YouTube

YouTube

The YouTube API module

Constructor

new YouTube(key)

Source:
Parameters:
Name Type Description
key string The YouTube Data API v3 key to use

Members

(nullable) key :string

The YouTube Data API v3 key
Source:
Type:
  • string

Methods

getChannel(url, optionsopt) → {Promise.<?Channel>}

Get a channel by URL or ID
Source:
Parameters:
Name Type Attributes Default Description
url string The channel URL or ID
options Object <optional>
{} Options to request with the channel.
Returns:
Type:
Promise.<?Channel>
Example
API.getChannel('https://www.youtube.com/channel/UC477Kvszl9JivqOxN1dFgPQ')
 .then(channel => {
   if (channel) console.log(`The channel's title is ${channel.title}`);
   else console.log('channel not found :(');
 })
 .catch(console.error);

getChannelByID(id, optionsopt) → {Promise.<?Channel>}

Get a channel by ID
Source:
Parameters:
Name Type Attributes Default Description
id string The channel ID
options Object <optional>
{} Options to request with the channel.
Returns:
Type:
Promise.<?Channel>
Example
API.getChannelByID('UC477Kvszl9JivqOxN1dFgPQ')
 .then(channel => {
   if (channel) console.log(`The channel's title is ${channel.title}`);
   else console.log('channel not found :(');
 })
 .catch(console.error);

getPlaylist(url, optionsopt) → {Promise.<?Playlist>}

Get a playlist by URL or ID
Source:
Parameters:
Name Type Attributes Default Description
url string The playlist URL or ID
options Object <optional>
{} Options to request with the playlist.
Returns:
Type:
Promise.<?Playlist>
Example
API.getPlaylist('https://www.youtube.com/playlist?list=PLuY9odN8x9puRuCxiddyRzJ3F5jR-Gun9')
 .then(playlist => {
   if (playlist) console.log(`The playlist's title is ${playlist.title}`);
   else console.log('playlist not found :(');
 })
 .catch(console.error);

getPlaylistByID(id, optionsopt) → {Promise.<?Playlist>}

Get a playlist by ID
Source:
Parameters:
Name Type Attributes Default Description
id string The playlist ID
options Object <optional>
{} Options to request with the playlist.
Returns:
Type:
Promise.<?Playlist>
Example
API.getPlaylistByID('PL2BN1Zd8U_MsyMeK8r9Vdv1lnQGtoJaSa')
 .then(playlist => {
   if (playlist) console.log(`The playlist's title is ${playlist.title}`);
   else console.log('playlist not found :(');
 })
 .catch(console.error);

getVideo(url, optionsopt) → {Promise.<?Video>}

Get a video by URL or ID
Source:
Parameters:
Name Type Attributes Default Description
url string The video URL or ID
options Object <optional>
{} Options to request with the video.
Returns:
Type:
Promise.<?Video>
Example
API.getVideo('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
 .then(video => {
   if (video) console.log(`The video's title is ${video.title}`);
   else console.log('video not found :(');
 })
 .catch(console.error);

getVideoByID(id, optionsopt) → {Promise.<?Video>}

Get a video by ID
Source:
Parameters:
Name Type Attributes Default Description
id string The video ID
options Object <optional>
{} Options to request with the video.
Returns:
Type:
Promise.<?Video>
Example
API.getVideoByID('3odIdmuFfEY')
 .then(video => {
   if (video) console.log(`The video's title is ${video.title}`);
   else console.log('video not found :(');
 })
 .catch(console.error);
Search YouTube for videos, playlists, and channels
Source:
Parameters:
Name Type Attributes Default Description
query string The string to search for
limit number <optional>
5 Maximum results to obtain
options Object <optional>
Additional options to pass to the API request
Returns:
Type:
Promise.<Array.<(Video|Playlist|Channel|null)>>
Example
API.search('Centuries')
 .then(results => {
   console.log(`I got ${results.length} results`);
 })
 .catch(console.error);

searchChannels(query, limitopt, optionsopt) → {Promise.<Array.<Channel>>}

Search YouTube for channels
Source:
Parameters:
Name Type Attributes Default Description
query string The string to search for
limit number <optional>
5 Maximum results to obtain
options Object <optional>
Additional options to pass to the API request
Returns:
Type:
Promise.<Array.<Channel>>
Example
API.searchChannels('Centuries')
 .then(results => {
   console.log(`I got ${results.length} channels`);
 })
 .catch(console.error);

searchPlaylists(query, limitopt, optionsopt) → {Promise.<Array.<Playlist>>}

Search YouTube for playlists
Source:
Parameters:
Name Type Attributes Default Description
query string The string to search for
limit number <optional>
5 Maximum results to obtain
options Object <optional>
Additional options to pass to the API request
Returns:
Type:
Promise.<Array.<Playlist>>
Example
API.searchPlaylists('Centuries')
 .then(results => {
   console.log(`I got ${results.length} playlists`);
 })
 .catch(console.error);

searchVideos(query, limitopt, optionsopt) → {Promise.<Array.<Video>>}

Search YouTube for videos
Source:
Parameters:
Name Type Attributes Default Description
query string The string to search for
limit number <optional>
5 Maximum results to obtain
options Object <optional>
Additional options to pass to the API request
Returns:
Type:
Promise.<Array.<Video>>
Example
API.searchVideos('Centuries')
 .then(results => {
   console.log(`I got ${results.length} videos`);
 })
 .catch(console.error);