YouTube Channel Info NodeJS Documentation
This library is designed to receive channel data from YouTube without accessing the official API.
This method has several advantages:
- No API key is required, which you should put next to your code;
- No restrictions on key usage (1 million quota)
But there are also disadvantages:
- Data acquisition time increases by many times;
- Any change to the YouTube DOM entails non-working methods of this library.
You must consider this before you use YouTube Channel Info
Installation
npm i yt-channel-info --save
Usage
const ytch = require('yt-channel-info')
import ytch from 'yt-channel-info'
API
getChannelInfo(payload)
- payload (Object) (Required) - An object containing the various options
- channelId (String) (Required) - The channel ID to get info from
- channelIdType (Integer) (Optional) - Grabs newest comments when
true
. Grabs top comments when false
0
= Default value used by the module. It will try all url types in the order channel -> user -> name1
= A channel id that is used with https://www.youtube.com/channel/channelId
urls2
= A user id that is used with https://www.youtube.com/user/channelId
urls3
= A name id that is used with https://www.youtube.com/c/channelId
urls
- httpsAgent (Object) (Optional) - Defines Proxy data in an object like https proxy agent. Allows to specify host, port, protocol, authentication (see section Proxy)
const payload = {
channelId: 'UCXuqSBlHAE6Xw-yeJA0Tunw',
channelIdType: 0,
httpsAgent: agent
}
ytch.getChannelInfo(payload).then((response) => {
if (!response.alertMessage) {
console.log(response)
} else {
console.log('Channel could not be found.')
}
}).catch((err) => {
console.log(err)
})
{
author: String,
authorId: String,
authorUrl: String,
authorBanners: Array[Object],
authorThumbnails: Array[Object],
subscriberText: String,
subscriberCount: Integer,
description: String,
isFamilyFriendly: Boolean,
relatedChannels: {
items: Array[Object],
continuation: String
},
allowedRegions: Array[String],
isVerified: Boolean,
isOfficialArtist: Boolean,
tags: Array[String],
channelIdType: Number,
channelTabs: Array[String],
alertMessage: String,
channelLinks: {
primaryLinks: Array[Object],
secondaryLinks: Array[Object]
}
}
getChannelVideos(payload)
Grabs videos from a given channel ID.
- payload (Object) (Required) - An object containing the various options
- channelId (String) (Required) - The channel ID to get videos from
- sortBy (String) (Optional) - How videos will be sorted
newest
- Grabs videos from a channel sorted by newest / most recently uploaded (Default option if none given)oldest
- Grabs videos from a channel sorted by oldest videospopular
- Grabs videos from a channel sorted by the most popular (Highest amount of views)
- channelIdType (Integer) (Optional) - Same definition as 'channelIdType' in
getChannelInfo()
- httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
const payload = {
channelId: 'UCXuqSBlHAE6Xw-yeJA0Tunw',
sortBy: 'newest',
channelIdType: 0
}
ytch.getChannelVideos(payload).then((response) => {
if (!response.alertMessage) {
console.log(response)
} else {
console.log('Channel could not be found.')
}
}).catch((err) => {
console.log(err)
})
{
items: Array[Object],
continuation: String,
channelIdType: Number,
alertMessage: String,
}
getChannelVideosMore(payload)
Grabs more videos within a channel. Uses the continuation string returned from getChannelVideos()
or from past calls to getChannelVideosMore()
.
Grabs videos from a given channel ID.
- payload (Object) (Required) - An object containing the various options
- continuation (String) (Required) - The continuation string from
getChannelVideos()
or from past calls to getChannelVideosMore()
. - httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
const payload = {
continuation: '4qmFsgK9ARIYVUNYdXFTQmxIQUU2WHcteWVKQTBUdW53GqABRWdsd2JHRjViR2x6ZEhNZ0FYcG1VVlZzVUdFeGF6VlNiVkoyV1ZjNWJHVnNUbGhTUmxwWVZrVm9kR1ZHYTNoVU1EVnJUVWR3ZFdNd05VVmFSVVo0Vm10NGRsVnJWa2haYkd4dVUyNXZlbEpxUW5WT1YxRjNXbGhyTkZKcVVqVmhibEpXVkVVNWNtSkdUbnBaYXpWWVUxZDNNMVpSdUFFQQ%3D%3D',
}
ytch.getChannelVideosMore(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
items: Array[Object],
continuation: String
}
getChannelPlaylistInfo(payload)
Grabs playlist information of a given channel ID.
payload (Object) (Required)
- An object containing the various options
- channelId (String) (Required) - The channel ID to grab playlists from
- sortBy (String) (Optional) - 'last' sort by last updated or 'newest' sort by creation date
last
- Grabs playlists from a channel sorted by the most recently updated playlist (Default option if none given)oldest
- Grabs playlists from a channel sorted by the creation date (oldest first)newest
- Grabs playlists from a channel sorted by the creation date (newest first)
- httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
- channelIdType (Integer) (Optional) - Same definition as 'channelIdType' in
getChannelInfo()
const payload = {
channelId: 'UCXuqSBlHAE6Xw-yeJA0Tunw',
sortBy: 'last',
}
ytch.getChannelPlaylistInfo(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
items: Array[Object],
continuation: String
channelIdType: Number,
}
getChannelPlaylistsMore(payload)
Grabs more playlists within a channel. Uses the continuation string returned from getChannelPlaylists()
or from past calls to getChannelPlaylistsMore()
.
- payload (Object) (Required) - An object containing the various options
- continuation (String) (Required) - The continuation string from
getChannelPlaylists()
or from past calls to getChannelPlaylistsMore()
. - httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
const payload = {
continuation: '4qmFsgK9ARIYVUNYdXFTQmxIQUU2WHcteWVKQTBUdW53GqABRWdsd2JHRjViR2x6ZEhNZ0FYcG1VVlZzVUdFeGF6VlNiVkoyV1ZjNWJHVnNUbGhTUmxwWVZrVm9kR1ZHYTNoVU1EVnJUVWR3ZFdNd05VVmFSVVo0Vm10NGRsVnJWa2haYkd4dVUyNXZlbEpxUW5WT1YxRjNXbGhyTkZKcVVqVmhibEpXVkVVNWNtSkdUbnBaYXpWWVUxZDNNMVpSdUFFQQ%3D%3D'
}
ytch.getChannelPlaylistsMore(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
items: Array[Object],
continuation: String
}
searchChannel(payload)
Searchs for videos and playlists of a given channelId based on the given query
- payload (Object) (Required) - An object containing the various options
- channelId (String) (Required) - The channel you want to search
- query (String) (Required) - The query you want to use
- httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
- channelIdType (Integer) (Optional) - Same definition as 'channelIdType'
getChannelInfo()
const payload = {
channelId: 'UCXuqSBlHAE6Xw-yeJA0Tunw',
query: 'linux'
}
ytch.searchChannel(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
items: Array[Object],
continuation: String
}
searchChannelMore(payload)
Grabs more search results within a channel. Uses the continuation string returned from searchChannel()
or from past calls to searchChannelMore()
.
- payload (Object) (Required) - An object containing the various options
- continuation (String) (Required) - The continuation string from
searchChannel()
or from past calls to searchChannelMore()
. - httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
const payload = {
continuation: '4qmFsgK9ARIYVUNYdXFTQmxIQUU2WHcteWVKQTBUdW53GqABRWdsd2JHRjViR2x6ZEhNZ0FYcG1VVlZzVUdFeGF6VlNiVkoyV1ZjNWJHVnNUbGhTUmxwWVZrVm9kR1ZHYTNoVU1EVnJUVWR3ZFdNd05VVmFSVVo0Vm10NGRsVnJWa2haYkd4dVUyNXZlbEpxUW5WT1YxRjNXbGhyTkZKcVVqVmhibEpXVkVVNWNtSkdUbnBaYXpWWVUxZDNNMVpSdUFFQQ%3D%3D'
}
ytch.searchChannelMore(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
items: Array[Object],
continuation: String
}
getRelatedChannelsMore(payload)
Grabs more related channels within a channel. Uses the relatedChannelsContinuation string returned from getChannelInfo()
or from past calls to getRelatedChannelsMore()
.
- payload (Object) (Required) - An object containing the various options
- continuation (String) (Required) - The continuation string from
getChannelInfo()
or from past calls to getRelatedChannelsMore()
. - httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
const payload = {
continuation: '4qmFsgKlARIYVUNtOUs2cmJ5OThXOEppZ0xvWk9oNkZRGlhFZ2hqYUdGdWJtVnNjeGdESUFBd0FUZ0I2Z01vUTJkQlUwZG9iMWxXVlU1M1pXdHNVR1ZzUW5saE1IaGhXWHBhWm1SV1NsSldWazQyVG5wa1VnJTNEJTNEmgIuYnJvd3NlLWZlZWRVQ205SzZyYnk5OFc4SmlnTG9aT2g2RlFjaGFubmVsczE1Ng%3D%3D'
}
ytch.getRelatedChannelsMore(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
items: Array[Object],
continuation: String
}
getChannelCommunityPosts(payload)
Searches for all posts on the community page of a given channelId based on the given query.
- payload (Object) (Required) - An object containing the various options
- channelId (String) (Required) - The channel ID to get community posts from
- channelIdType (Integer) (Optional) - Same definition as 'channelIdType' for
getChannelInfo()
- httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
const payload = {
channelId: 'UCXuqSBlHAE6Xw-yeJA0Tunw'
}
ytch.getChannelCommunityPosts(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
items: Array[Object],
continuation: String,
innerTubeApi: String,
channelIdType: Number,
}
getChannelStats(payload)
Gets the stats of a channel
- payload (Object) (Required) - An object containing the various options
- channelId (String) (Required) - The channel ID to get stats from
- channelIdType (Integer) (Optional) - Same definition as
channelIdType
in getChannelInfo()
- httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
const payload = {
channelId: 'UCXuqSBlHAE6Xw-yeJA0Tunw'
}
ytch.getChannelStats(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
joinedDate: Integer,
viewCount: Integer,
location: String
}
getChannelCommunityPostsMore(payload)
Grabs more search results within a channel community page. Uses the continuation and innerTubeApi strings returned from getChannelCommunityPosts()
or from past calls to getChannelCommunityPostsMore()
.
- payload (Object) (Required) - An object containing the various options
- continuation (String) (Required) - The continuation string from
getChannelCommunityPosts()
or from past calls to getChannelCommunityPostsMore()
. - innterTubeApi (String) (Required) - The innerTubeApi string from
getChannelCommunityPosts()
or from past calls to getChannelCommunityPostsMore()
. - httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in
getChannelInfo()
const payload = {
continuation: '4qmFsgK9ARIYVUNYdXFTQmxIQUU2WHcteWVKQTBUdW53GqABRWdsd2JHRjViR2x6ZEhNZ0FYcG1VVlZzVUdFeGF6VlNiVkoyV1ZjNWJHVnNUbGhTUmxwWVZrVm9kR1ZHYTNoVU1EVnJUVWR3ZFdNd05VVmFSVVo0Vm10NGRsVnJWa2haYkd4dVUyNXZlbEpxUW5WT1YxRjNXbGhyTkZKcVVqVmhibEpXVkVVNWNtSkdUbnBaYXpWWVUxZDNNMVpSdUFFQQ%3D%3D',
innerTubeApi: 'JNDJSGJHASJ44DSHGDNLGMHA6FSFas5faF5'
}
ytch.getChannelCommunityPostsMore(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
items: Array[Object],
continuation: String,
innerTubeApi: String
}
getChannelHome(payload)
Searchs for videos and playlists of a given channelId based on the given query
- payload (Object) (Required) - An object containing the various options
- channelId (String) (Required) - The channel you want to search
- channelIdType (Integer) (Optional) - defined as for
getChannelInfo()
- httpsAgent (Object) (Optional) - defined as for
getChannelInfo()
const payload = {
channelId: 'UCXuqSBlHAE6Xw-yeJA0Tunw',
}
ytch.getChannelHome(payload).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
{
featuredVideo: {
type: 'video',
title: String,
videoId: String,
author: String,
authorId: String,
videoThumbnails: [],
viewCountText: String,
viewCount: Number,
publishedText: String,
durationText: undefined,
lengthSeconds: 0,
liveNow: Boolean,
premier: Boolean,
premium: Boolean
},
items: Array[Object],
}
Community Posts Format
The objects in the array of community posts all follow a basic structure but vary drastically in the postContent field of the object.
-httpsAgent
defined as for getChannelInfo()
postData = {
postText: String,
postId: String,
author: String,
authorThumbnails: Array[Object],
publishedText: String,
voteCount: String,
postContent: Object,
commentCount: String
}
imagePostContent = {
type: 'image',
content: Array[Object]
}
pollPostContent = {
type: 'poll',
content: {
choices: Array[String],
totalVotes: String
}
}
videoPostContent = {
type: 'video',
content: {
videoId: String,
title: String,
description: String,
publishedText: String,
lengthText: String,
viewCountText: String,
ownerBadges: Object,
author: String,
thumbnails: Array[Object]
}
}
playlistPostContent = {
type: 'playlist',
content: {
playlistId: String,
title: String,
playlistVideoRenderer: Array[Object],
videoCountText: String,
ownerBadges: Array[Object],
author: String,
thumbnails: Array[Object]
}
}
Proxy (HTTP Agent)
In order to use a proxy, you have to provide an assembled HTTP Agent. This can be achieved via additional packages like https-proxy-agent:
import HttpsProxyAgent from 'https-proxy-agent';
const proxy = 'http://127.0.0.1:10003';
const httpAgent = HttpsProxyAgent(proxy);
Tests
Tests and code standards are still in the process of being created. Check back later for information on how tests should be performed.
Contribution
PRs are welcome. Testing and coding guidlines are still in the works so I will try to get those created at a later point. Try to keep similar code syntax to the rest of the code.
Credits
This is a fork of the youtube-grabber-js
module created by OlegRom4ig
View the original project on NPM or GitLab
License
You have explicit permission to use this project as stated in the terms of the ISC license.