class Yt::Channel
Provides methods to interact with YouTube channels. @see developers.google.com/youtube/v3/docs/channels
Public Class Methods
@return [Yt::Channel] the channel associated with the YouTube account
that provided the authentication token.
# File lib/yt/channel.rb, line 160 def self.mine Relation.new(self) do |options| get '/youtube/v3/channels', mine: true, part: 'id' end.first end
Public Instance Methods
@return [String] the canonical form of the channel’s URL.
# File lib/yt/channel.rb, line 100 def canonical_url "https://www.youtube.com/channel/#{id}" end
@return [Yt::Relation<Yt::Group>] the analytics groups of the channel. @see developers.google.com/youtube/analytics/v1/reference/groups
# File lib/yt/channel.rb, line 137 def groups @groups ||= Relation.new(Group) do |options| get '/youtube/analytics/v1/groups', mine: true end end
@return [Yt::Relation<Yt::Playlist>] the playlists associated with
liked videos. Includes the deprecated favorites if still present.
# File lib/yt/channel.rb, line 152 def like_playlists @like_lists ||= Relation.new(Playlist, ids: like_list_ids) do |options| get '/youtube/v3/playlists', resource_params(options) end end
@return [Yt::Relation<Yt::Playlist>] the public playlists of the channel.
# File lib/yt/channel.rb, line 144 def playlists @playlists ||= Relation.new(Playlist, channel_id: id) do |options| get '/youtube/v3/playlists', channel_playlists_params(options) end end
Returns the URL of one of the channel’s thumbnail. @param [Symbol, String] size The size of the channel’s thumbnail. @return [String] if size
is :default
, the URL of a 88x88px image. @return [String] if size
is :medium
, the URL of a 240x240px image. @return [String] if size
is :high
, the URL of a 800x800px image. @return [nil] if the size
is none of the above.
# File lib/yt/channel.rb, line 120 def thumbnail_url(size = :default) thumbnails.fetch(size.to_s, {})['url'] end
@return [<String] the full channel’s URL (custom or canonical). @see support.google.com/youtube/answer/2657968
# File lib/yt/channel.rb, line 106 def vanity_url if custom_url "https://www.youtube.com/#{custom_url}" else canonical_url end end
@return [Yt::Relation<Yt::Video>] the public videos of the channel. @note For unauthenticated channels, results are constrained to a maximum of 500 videos. @see developers.google.com/youtube/v3/docs/search/list#channelId
# File lib/yt/channel.rb, line 128 def videos @videos ||= Relation.new(Video, channel_id: id, limit: 500) do |options| items = get '/youtube/v3/search', channel_videos_params(options) videos_for items, 'id', options end end
Private Instance Methods
# File lib/yt/channel.rb, line 168 def like_list_ids names = %w(likes favorites) related_playlists.select{|name,_| names.include? name}.values end