Class: Yt::Channel
Overview
Provides methods to interact with YouTube channels.
Instance Attribute Summary collapse
-
#banner_image_url ⇒ String
readonly
The URL for the banner image shown on the channel page on the YouTube website.
-
#comment_count ⇒ <Integer>
readonly
The number of comments for the channel.
-
#custom_url ⇒ <String, nil>
readonly
The path component of the channel’s custom URL.
-
#description ⇒ String
readonly
The channel’s description.
-
#featured_channels_title ⇒ Array<String>
readonly
The IDs of the channels linked in the featured channels module.
-
#hidden_subscriber_count ⇒ <Boolean>
readonly
Whether the channel’s subscriber count is publicly visible.
-
#is_linked ⇒ Boolean
readonly
Whether the channel data identifies a user that is already linked to either a YouTube username or a Google+ account.
-
#keywords ⇒ Array<String>
readonly
The keywords associated with the channel.
-
#long_uploads_status ⇒ String
readonly
Whether the channel is eligible to upload videos that are more than 15 minutes long.
-
#privacy_status ⇒ String
readonly
The privacy status of the channel.
-
#published_at ⇒ Time
readonly
The date and time that the channel was created.
-
#related_playlists ⇒ Hash
readonly
The playlists associated with the channel, such as the channel’s uploaded videos, liked videos, and watch history.
-
#subscriber_count ⇒ <Integer>
readonly
The number of subscribers that the channel has.
-
#thumbnails ⇒ Hash<String, Hash>
readonly
The thumbnails associated with the video.
-
#title ⇒ String
readonly
The channel’s title.
-
#unsubscribed_trailer ⇒ <String, nil>
readonly
If specified, the ID of a public or unlisted video owned by the channel owner that should play in the featured video module in the channel page’s browse view for unsubscribed viewers.
-
#video_count ⇒ <Integer>
readonly
The number of videos uploaded to the channel.
-
#view_count ⇒ <Integer>
readonly
The number of times the channel has been viewed.
Attributes inherited from Resource
Class Method Summary collapse
-
.mine ⇒ Yt::Channel
The channel associated with the YouTube account that provided the authentication token.
Instance Method Summary collapse
-
#canonical_url ⇒ String
The canonical form of the channel’s URL.
-
#like_playlists ⇒ Yt::Relation<Yt::Playlist>
The playlists associated with liked videos.
-
#playlists ⇒ Yt::Relation<Yt::Playlist>
The public playlists of the channel.
-
#thumbnail_url(size = :default) ⇒ String?
Returns the URL of one of the channel’s thumbnail.
-
#vanity_url ⇒ <String] the full channel’s URL (custom or canonical).
<String] the full channel’s URL (custom or canonical).
-
#videos ⇒ Yt::Relation<Yt::Video>
of 500 videos.
Methods inherited from Resource
#id, #initialize, #inspect, #select, where
Constructor Details
This class inherits a constructor from Yt::Resource
Instance Attribute Details
#banner_image_url ⇒ String (readonly)
Returns the URL for the banner image shown on the channel page on the YouTube website. The image is 1060px by 175px.
70 |
# File 'lib/yt/channel.rb', line 70 has_attribute :banner_image_url, in: %i(branding_settings image) |
#comment_count ⇒ <Integer> (readonly)
Returns the number of comments for the channel.
52 |
# File 'lib/yt/channel.rb', line 52 has_attribute :comment_count, in: :statistics, type: Integer |
#custom_url ⇒ <String, nil> (readonly)
Returns the path component of the channel’s custom URL.
23 |
# File 'lib/yt/channel.rb', line 23 has_attribute :custom_url, in: :snippet |
#description ⇒ String (readonly)
Returns the channel’s description.
11 |
# File 'lib/yt/channel.rb', line 11 has_attribute :description, in: :snippet |
#featured_channels_title ⇒ Array<String> (readonly)
Returns the IDs of the channels linked in the featured channels module.
87 |
# File 'lib/yt/channel.rb', line 87 has_attribute :featured_channels_title, in: %i(branding_settings channel) |
#hidden_subscriber_count ⇒ <Boolean> (readonly)
Returns whether the channel’s subscriber count is publicly visible.
61 |
# File 'lib/yt/channel.rb', line 61 has_attribute :hidden_subscriber_count, in: :statistics |
#is_linked ⇒ Boolean (readonly)
Returns whether the channel data identifies a user that is already linked to either a YouTube username or a Google+ account.
37 |
# File 'lib/yt/channel.rb', line 37 has_attribute :is_linked, in: :status |
#keywords ⇒ Array<String> (readonly)
Returns the keywords associated with the channel.
74 75 76 |
# File 'lib/yt/channel.rb', line 74 has_attribute :keywords, in: %i(branding_settings channel) do |keywords| (keywords || '').split ' ' end |
#long_uploads_status ⇒ String (readonly)
“longUploadsUnspecified” is not documented by the YouTube API.
Returns whether the channel is eligible to upload videos that are more than 15 minutes long. Valid values are: “allowed”, “disallowed”, “eligible”, “longUploadsUnspecified”.
44 |
# File 'lib/yt/channel.rb', line 44 has_attribute :long_uploads_status, in: :status |
#privacy_status ⇒ String (readonly)
Returns the privacy status of the channel. Valid values are: “private”, “public”, “unlisted”.
32 |
# File 'lib/yt/channel.rb', line 32 has_attribute :privacy_status, in: :status |
#published_at ⇒ Time (readonly)
Returns the date and time that the channel was created.
15 |
# File 'lib/yt/channel.rb', line 15 has_attribute :published_at, in: :snippet, type: Time |
#related_playlists ⇒ Hash (readonly)
Returns the playlists associated with the channel, such as the channel’s uploaded videos, liked videos, and watch history.
97 |
# File 'lib/yt/channel.rb', line 97 has_attribute :related_playlists, in: :content_details |
#subscriber_count ⇒ <Integer> (readonly)
Returns the number of subscribers that the channel has.
56 |
# File 'lib/yt/channel.rb', line 56 has_attribute :subscriber_count, in: :statistics, type: Integer |
#thumbnails ⇒ Hash<String, Hash> (readonly)
Returns the thumbnails associated with the video.
19 |
# File 'lib/yt/channel.rb', line 19 has_attribute :thumbnails, in: :snippet |
#title ⇒ String (readonly)
Returns the channel’s title.
7 |
# File 'lib/yt/channel.rb', line 7 has_attribute :title, in: :snippet |
#unsubscribed_trailer ⇒ <String, nil> (readonly)
Returns if specified, the ID of a public or unlisted video owned by the channel owner that should play in the featured video module in the channel page’s browse view for unsubscribed viewers.
82 |
# File 'lib/yt/channel.rb', line 82 has_attribute :unsubscribed_trailer, in: %i(branding_settings channel) |
#video_count ⇒ <Integer> (readonly)
Returns the number of videos uploaded to the channel.
65 |
# File 'lib/yt/channel.rb', line 65 has_attribute :video_count, in: :statistics, type: Integer |
#view_count ⇒ <Integer> (readonly)
Returns the number of times the channel has been viewed.
48 |
# File 'lib/yt/channel.rb', line 48 has_attribute :view_count, in: :statistics, type: Integer |
Class Method Details
.mine ⇒ Yt::Channel
Returns the channel associated with the YouTube account that provided the authentication token.
152 153 154 155 156 |
# File 'lib/yt/channel.rb', line 152 def self.mine Relation.new(self) do || get '/youtube/v3/channels', mine: true, part: 'id' end.first end |
Instance Method Details
#canonical_url ⇒ String
Returns the canonical form of the channel’s URL.
100 101 102 |
# File 'lib/yt/channel.rb', line 100 def canonical_url "https://www.youtube.com/channel/#{id}" end |
#like_playlists ⇒ Yt::Relation<Yt::Playlist>
Returns the playlists associated with liked videos. Includes the deprecated favorites if still present.
144 145 146 147 148 |
# File 'lib/yt/channel.rb', line 144 def like_playlists @like_lists ||= Relation.new(Playlist, ids: like_list_ids) do || get '/youtube/v3/playlists', resource_params() end end |
#playlists ⇒ Yt::Relation<Yt::Playlist>
Returns the public playlists of the channel.
136 137 138 139 140 |
# File 'lib/yt/channel.rb', line 136 def playlists @playlists ||= Relation.new(Playlist, channel_id: id) do || get '/youtube/v3/playlists', channel_playlists_params() end end |
#thumbnail_url(size = :default) ⇒ String?
Returns the URL of one of the channel’s thumbnail.
120 121 122 |
# File 'lib/yt/channel.rb', line 120 def thumbnail_url(size = :default) thumbnails.fetch(size.to_s, {})['url'] end |
#vanity_url ⇒ <String] the full channel’s URL (custom or canonical).
Returns <String] the full channel’s URL (custom or canonical).
106 107 108 109 110 111 112 |
# File 'lib/yt/channel.rb', line 106 def vanity_url if custom_url "https://www.youtube.com/#{custom_url}" else canonical_url end end |
#videos ⇒ Yt::Relation<Yt::Video>
For unauthenticated channels, results are constrained to a maximum
of 500 videos.
128 129 130 131 132 133 |
# File 'lib/yt/channel.rb', line 128 def videos @videos ||= Relation.new(Video, channel_id: id, limit: 500) do || items = get '/youtube/v3/search', channel_videos_params() videos_for items, 'id', end end |