Class: Yt::Channel

Inherits:
Resource show all
Defined in:
lib/yt/channel.rb

Overview

Provides methods to interact with YouTube channels.

Instance Attribute Summary collapse

Attributes inherited from Resource

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#id, #initialize, #inspect, #select, where

Constructor Details

This class inherits a constructor from Yt::Resource

Instance Attribute Details

Returns the URL for the banner image shown on the channel page on the YouTube website. The image is 1060px by 175px.

Returns:

  • (String)

    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.

Returns:

  • (<Integer>)

    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.

Returns:

  • (<String, nil>)

    the path component of the channel’s custom URL.


23
# File 'lib/yt/channel.rb', line 23

has_attribute :custom_url, in: :snippet

#descriptionString (readonly)

Returns the channel’s description.

Returns:

  • (String)

    the channel’s description.


11
# File 'lib/yt/channel.rb', line 11

has_attribute :description, in: :snippet

Returns the IDs of the channels linked in the featured channels module.

Returns:

  • (Array<String>)

    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.

Returns:

  • (<Boolean>)

    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_linkedBoolean (readonly)

Returns whether the channel data identifies a user that is already linked to either a YouTube username or a Google+ account.

Returns:

  • (Boolean)

    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

#keywordsArray<String> (readonly)

Returns the keywords associated with the channel.

Returns:

  • (Array<String>)

    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_statusString (readonly)

Note:

“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”.

Returns:

  • (String)

    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_statusString (readonly)

Returns the privacy status of the channel. Valid values are: “private”, “public”, “unlisted”.

Returns:

  • (String)

    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_atTime (readonly)

Returns the date and time that the channel was created.

Returns:

  • (Time)

    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

Returns the playlists associated with the channel, such as the channel's uploaded videos, liked videos, and watch history.

Returns:

  • (Hash)

    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.

Returns:

  • (<Integer>)

    the number of subscribers that the channel has.


56
# File 'lib/yt/channel.rb', line 56

has_attribute :subscriber_count, in: :statistics, type: Integer

#thumbnailsHash<String, Hash> (readonly)

Returns the thumbnails associated with the video.

Returns:

  • (Hash<String, Hash>)

    the thumbnails associated with the video.


19
# File 'lib/yt/channel.rb', line 19

has_attribute :thumbnails, in: :snippet

#titleString (readonly)

Returns the channel’s title.

Returns:

  • (String)

    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.

Returns:

  • (<String, nil>)

    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.

Returns:

  • (<Integer>)

    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.

Returns:

  • (<Integer>)

    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

.mineYt::Channel

Returns the channel associated with the YouTube account that provided the authentication token.

Returns:

  • (Yt::Channel)

    the channel associated with the YouTube account that provided the authentication token.


160
161
162
163
164
# 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

Instance Method Details

#canonical_urlString

Returns the canonical form of the channel’s URL.

Returns:

  • (String)

    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

#groupsYt::Relation<Yt::Group>

Returns the analytics groups of the channel.

Returns:

  • (Yt::Relation<Yt::Group>)

    the analytics groups of the channel.

See Also:


137
138
139
140
141
# File 'lib/yt/channel.rb', line 137

def groups
  @groups ||= Relation.new(Group) do |options|
    get '/youtube/analytics/v1/groups', mine: true
  end
end

#like_playlistsYt::Relation<Yt::Playlist>

Returns the playlists associated with liked videos. Includes the deprecated favorites if still present.

Returns:

  • (Yt::Relation<Yt::Playlist>)

    the playlists associated with liked videos. Includes the deprecated favorites if still present.


152
153
154
155
156
# 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

#playlistsYt::Relation<Yt::Playlist>

Returns the public playlists of the channel.

Returns:

  • (Yt::Relation<Yt::Playlist>)

    the public playlists of the channel.


144
145
146
147
148
# 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

#thumbnail_url(size = :default) ⇒ String?

Returns the URL of one of the channel’s thumbnail.

Parameters:

  • size (Symbol, String) (defaults to: :default)

    The size of the channel’s thumbnail.

Returns:

  • (String)

    if size is :default, the URL of a 88x88px image.

  • (String)

    if size is :medium, the URL of a 240x240px image.

  • (String)

    if size is :high, the URL of a 800x800px image.

  • (nil)

    if the size is none of the above.


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).

Returns:

  • (<String] the full channel’s URL (custom or canonical).)

    <String] the full channel’s URL (custom or canonical).

See Also:


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

#videosYt::Relation<Yt::Video>

Note:

For unauthenticated channels, results are constrained to a maximum

of 500 videos.

Returns:

  • (Yt::Relation<Yt::Video>)

    the public videos of the channel.

See Also:


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 |options|
    items = get '/youtube/v3/search', channel_videos_params(options)
    videos_for items, 'id', options
  end
end