Skip to content

Channel

gatecrasher777 edited this page Apr 14, 2023 · 5 revisions

Channel

Methods

constructor

const channel = ytcog.Channel(session, channelOptions);

session is an instance of a ytcog.Session
channelOptions is a user defined object explained below

fetch

fetch() initiates the collection of metadata/results. fetch() provides the opportunity to change channel options prior to execution. fetch() will continue to fetch results until it matches or exceeds the desired quantity of results or there are no more results to collect.

channel.fetch([channelOptions]);

continued

continued() must be preceded by a fetch() method. continued() will fetch extra results. It can be called repeatedly.

channel.continued();

Properties

Channel objects can have the following properties. Channel objects created from results, in particular, may have many properties undefined, giving only default values, until such time as a channel.fetch() is performed on it.

channel.status      (string) The result of the last fetch(), continued() or download(): Either OK, NOK or ERROR
channel.reason      (string) The reason for status NOK or ERROR. Can report 'No results'.
channel.updated     (number) Timestamp of last fetch.
channel.data        (string) or [(string)] The raw YouTube data fetched.
channel.transferred (number) Cumulative number of bytes of incoming data (compressed with gzip library). 
channel.debugOn     (boolean) default is false. Set to true to get error information in the console. 
channel.results     ([Item]) Array of objects fetched by the last fetch()/continued() cycle. 
channel.videos      ([Video]) Accumulated array of video objects found so far.
channel.playlists   ([Playlist]) Accumulated array of playlist objects found so far.
channel.channels    ([Channel]) Accumulated array of related channel objects found so far.
channel.videoCount  (number) number of online videos of a channel (if known, -1 if unknown).
channel.views       (number) Number of channel views
channel.subscribers (number) Number of subscribers
channel.joined      (number) Timestamp of when the channel began
channel.profiled    (number) Timestamp of last profile (order:'about') fetch
channel.latest      (number) Timestamp of newest video on the channel.
channel.author      (string) Displayed name of channel
channel.description (string) Description of channel
channel.thumbnail   (string) Thumbnail url of the channel logo/avatar
channel.country     (string) Country of origin of the channel
channel.tags        ([strings]) Array of tags to identify the channel contents
channel.quantity    (number) The number of results collected
channel.page        (number) Last page number of raw data collected on the last fetch()/continued() cycle. 

Options

channelOptions is an object with the following properties:

Required:

id:            (24 character string commencing with 'UC') the channel id;  Required in constructor.  
               Can be omitted in subsequent option updates.

Optional:

items:         (string) items to be returned: 
                * videos                videos from the channel
                * shorts                short videos from the channel (< 1 minute)
                * playlists             playlists from the channel
                * channels              related channels
                * about                 extra metadata for the channel (joined date, country etc.)
                * search                search for videos within the channel (must provide a query)

order:         (string) the order in which YouTube delivers the results: 
                * new                   newest to oldest (default) (videos/playlists)
                * old                   oldest to newest (videos)
                * views                 most to least views (videos)
                * updated               most recently to least recently updated (playlists)  

quantity:      (number) the desired number of videos. If available the actual number of results will  
               match or exceed this number. (default: 60)  

query:         search a channel using a search term. By default no query is defined.

Examples:

Collect extra channel properties with an 'about' request

{
     id: 'UCG5qGWdu8nIRZqJ_GgDwQ-w',
     items: 'about' 
}

120 videos from "Premier League" ordered by most views

{
     id: 'UCG5qGWdu8nIRZqJ_GgDwQ-w',
     items: 'videos',
     order: 'views',
     quantity: 120 
}

50 videos from "Premier League" that match the search term "Chelsea"

{
     id: 'UCG5qGWdu8nIRZqJ_GgDwQ-w',
     items: 'search',
     quantity: 50,  
     query: 'Chelsea' 
}

100 most recently updated playlists from "Premier League"

{
     id: 'UCG5qGWdu8nIRZqJ_GgDwQ-w',
     items: 'playlists',
     order: 'updated',
     quantity: 100
}

Tip: The most reliable way to extract all videos (of any length) after a specific date is to use a search request with the special mask: after:yyyy-mm-dd. This is because some channels have "videos" only, some have "shorts" only, and some have both "videos" and "shorts". Provide a sufficiently large quantity to encompass the required timeframe.

{
     id: 'UCG5qGWdu8nIRZqJ_GgDwQ-w',
     items: 'search',
     quantity: 500,  
     query: 'after:2023-03-31'
}

Tip: An excellent resource for YouTube search operators: 50+ advanced YouTube search operators

Clone this wiki locally