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


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

has_attribute :banner_image_url, in: %i(branding_settings image)

#comment_count<Integer> (readonly)


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

has_attribute :comment_count, in: :statistics, type: Integer

#custom_url<String, nil> (readonly)


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

has_attribute :custom_url, in: :snippet

#descriptionString (readonly)


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

has_attribute :description, in: :snippet

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

has_attribute :featured_channels_title, in: %i(branding_settings channel)

#hidden_subscriber_count<Boolean> (readonly)


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

has_attribute :hidden_subscriber_count, in: :statistics

#is_linkedBoolean (readonly)


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

has_attribute :is_linked, in: :status

#keywordsArray<String> (readonly)


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


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

has_attribute :long_uploads_status, in: :status

#privacy_statusString (readonly)


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

has_attribute :privacy_status, in: :status

#published_atTime (readonly)


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

has_attribute :published_at, in: :snippet, type: Time

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

has_attribute :related_playlists, in: :content_details

#subscriber_count<Integer> (readonly)


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

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

#thumbnailsHash<String, Hash> (readonly)


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

has_attribute :thumbnails, in: :snippet

#titleString (readonly)


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

has_attribute :title, in: :snippet

#unsubscribed_trailer<String, nil> (readonly)


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

has_attribute :unsubscribed_trailer, in: %i(branding_settings channel)

#video_count<Integer> (readonly)


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

has_attribute :video_count, in: :statistics, type: Integer

#view_count<Integer> (readonly)


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

has_attribute :view_count, in: :statistics, type: Integer

Class Method Details

.mineYt::Channel


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


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.


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>


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>


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.


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

#videosYt::Relation<Yt::Video>

Note:

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