Class: Yt::Video
Overview
Provides methods to interact with YouTube videos.
Constant Summary collapse
- CATEGORIES =
Returns the list of YouTube video categories.
{ 1 => 'Film & Animation', 2 => 'Autos & Vehicles', 10 => 'Music', 15 => 'Pets & Animals', 17 => 'Sports', 18 => 'Short Movies', 19 => 'Travel & Events', 20 => 'Gaming', 21 => 'Videoblogging', 22 => 'People & Blogs', 23 => 'Comedy', 24 => 'Entertainment', 25 => 'News & Politics', 26 => 'Howto & Style', 27 => 'Education', 28 => 'Science & Technology', 29 => 'Nonprofits & Activism', 30 => 'Movies', 31 => 'Anime/Animation', 32 => 'Action/Adventure', 33 => 'Classics', 34 => 'Comedy', 35 => 'Documentary', 36 => 'Drama', 37 => 'Family', 38 => 'Foreign', 39 => 'Horror', 40 => 'Sci-Fi/Fantasy', 41 => 'Thriller', 42 => 'Shorts', 43 => 'Shows', 44 => 'Trailers', }
Instance Attribute Summary collapse
-
#caption ⇒ Boolean
readonly
Whether captions are available for the video.
-
#category_id ⇒ Integer
readonly
The ID of the associated YouTube video category.
-
#channel_id ⇒ String
readonly
The ID of the channel that the video was uploaded to.
-
#channel_title ⇒ String
readonly
The title of the channel that the video was uploaded to.
-
#comment_count ⇒ <Integer>
readonly
The number of comments for the video.
-
#definition ⇒ String
readonly
Whether the video is available in high definition or only in standard definition.
-
#description ⇒ String
readonly
The video’s description.
-
#dimension ⇒ String
readonly
Whether the video is available in 3D or in 2D.
-
#dislike_count ⇒ <Integer>
readonly
The number of users who have disliked the video.
-
#duration ⇒ <String>
readonly
The length of the video as an ISO 8601 duration.
-
#embeddable ⇒ Boolean
readonly
Whether the video can be embedded on another website.
-
#license ⇒ String
readonly
The video’s license.
-
#licensed_content ⇒ Boolean
readonly
Whether the video represents licensed content, which means that the content was uploaded to a channel linked to a YouTube content partner and then claimed by that partner.
-
#like_count ⇒ <Integer>
readonly
The number of users who have liked the video.
-
#live_broadcast_content ⇒ String
readonly
Whether the video is an upcoming/active live broadcast.
-
#privacy_status ⇒ String
readonly
The video’s privacy status.
-
#projection ⇒ String
readonly
The projection format of the video.
-
#public_stats_viewable ⇒ Boolean
readonly
Whether the extended video statistics on the video’s watch page are publicly viewable.
-
#published_at ⇒ Time
readonly
The date and time that the video was published.
-
#tags ⇒ Array<String>
readonly
The list of tags associated with the video.
-
#thumbnails ⇒ Hash<String, Hash>
readonly
The thumbnails associated with the video.
-
#title ⇒ String
readonly
The video’s title.
-
#upload_status ⇒ String
readonly
The status of the uploaded video.
-
#view_count ⇒ <Integer>
readonly
The number of times the video has been viewed.
Attributes inherited from Resource
Instance Method Summary collapse
-
#canonical_url ⇒ String
The canonical form of the video’s URL.
-
#category_title ⇒ String
The title of the associated YouTube video category.
-
#channel ⇒ Yt::Channel
The channel the video belongs to.
-
#length ⇒ <String>
The length of the video as an ISO 8601 time, HH:MM:SS.
-
#seconds ⇒ <Integer>
The length of the video in seconds.
-
#threads ⇒ Yt::Relation<Yt::CommentThread>
The threads of the video.
-
#thumbnail_url(size = :default) ⇒ String?
Returns the URL of the video’s thumbnail.
Methods inherited from Resource
#id, #initialize, #inspect, #select, where
Constructor Details
This class inherits a constructor from Yt::Resource
Instance Attribute Details
#caption ⇒ Boolean (readonly)
Returns whether captions are available for the video.
113 114 115 |
# File 'lib/yt/video.rb', line 113 has_attribute :caption, in: :content_details do || == 'true' end |
#category_id ⇒ Integer (readonly)
Returns the ID of the associated YouTube video category.
42 |
# File 'lib/yt/video.rb', line 42 has_attribute :category_id, in: :snippet, type: Integer |
#channel_id ⇒ String (readonly)
Returns the ID of the channel that the video was uploaded to.
29 |
# File 'lib/yt/video.rb', line 29 has_attribute :channel_id, in: :snippet |
#channel_title ⇒ String (readonly)
Returns the title of the channel that the video was uploaded to.
33 |
# File 'lib/yt/video.rb', line 33 has_attribute :channel_title, in: :snippet |
#comment_count ⇒ <Integer> (readonly)
Returns the number of comments for the video.
95 |
# File 'lib/yt/video.rb', line 95 has_attribute :comment_count, in: :statistics, type: Integer |
#definition ⇒ String (readonly)
Returns whether the video is available in high definition or only in standard definition. Valid values are: “sd” and +“hd”.
109 |
# File 'lib/yt/video.rb', line 109 has_attribute :definition, in: :content_details |
#description ⇒ String (readonly)
Returns the video’s description. Has a maximum length of 5000 bytes and may contain all valid UTF-8 characters except < and >.
13 |
# File 'lib/yt/video.rb', line 13 has_attribute :description, in: :snippet |
#dimension ⇒ String (readonly)
Returns whether the video is available in 3D or in 2D. Valid values are: “2d” and +“3d”.
104 |
# File 'lib/yt/video.rb', line 104 has_attribute :dimension, in: :content_details |
#dislike_count ⇒ <Integer> (readonly)
Returns the number of users who have disliked the video.
91 |
# File 'lib/yt/video.rb', line 91 has_attribute :dislike_count, in: :statistics, type: Integer |
#duration ⇒ <String> (readonly)
Returns the length of the video as an ISO 8601 duration.
99 |
# File 'lib/yt/video.rb', line 99 has_attribute :duration, in: :content_details |
#embeddable ⇒ Boolean (readonly)
Returns whether the video can be embedded on another website.
70 |
# File 'lib/yt/video.rb', line 70 has_attribute :embeddable, in: :status |
#license ⇒ String (readonly)
Returns the video’s license. Valid values are: “creative_common” and “youtube”.
66 |
# File 'lib/yt/video.rb', line 66 has_attribute :license, in: :status |
#licensed_content ⇒ Boolean (readonly)
Returns whether the video represents licensed content, which means that the content was uploaded to a channel linked to a YouTube content partner and then claimed by that partner.
121 |
# File 'lib/yt/video.rb', line 121 has_attribute :licensed_content, in: :content_details |
#like_count ⇒ <Integer> (readonly)
Returns the number of users who have liked the video.
87 |
# File 'lib/yt/video.rb', line 87 has_attribute :like_count, in: :statistics, type: Integer |
#live_broadcast_content ⇒ String (readonly)
Returns whether the video is an upcoming/active live broadcast. Valid values are: “live”, “none”, “upcoming”.
47 |
# File 'lib/yt/video.rb', line 47 has_attribute :live_broadcast_content, in: :snippet |
#privacy_status ⇒ String (readonly)
Returns the video’s privacy status. Valid values are: “private”, “public”, and “unlisted”.
61 |
# File 'lib/yt/video.rb', line 61 has_attribute :privacy_status, in: :status |
#projection ⇒ String (readonly)
Returns the projection format of the video. Valid values are: “360” and +“rectangular”.
126 |
# File 'lib/yt/video.rb', line 126 has_attribute :projection, in: :content_details |
#public_stats_viewable ⇒ Boolean (readonly)
Returns whether the extended video statistics on the video’s watch page are publicly viewable.
75 |
# File 'lib/yt/video.rb', line 75 has_attribute :public_stats_viewable, in: :status |
#published_at ⇒ Time (readonly)
Returns the date and time that the video was published. Note that this time might be different than the time that the video was uploaded. For example, if a video is uploaded as a private video and then made public at a later time, this property will specify the time that the video was made public.
21 |
# File 'lib/yt/video.rb', line 21 has_attribute :published_at, in: :snippet, type: Time |
#tags ⇒ Array<String> (readonly)
Returns the list of tags associated with the video.
37 |
# File 'lib/yt/video.rb', line 37 has_attribute :tags, in: :snippet, default: [] |
#thumbnails ⇒ Hash<String, Hash> (readonly)
Returns the thumbnails associated with the video.
25 |
# File 'lib/yt/video.rb', line 25 has_attribute :thumbnails, in: :snippet |
#title ⇒ String (readonly)
Returns the video’s title. Has a maximum length of 100 characters and may contain all valid UTF-8 characters except < and >.
8 |
# File 'lib/yt/video.rb', line 8 has_attribute :title, in: :snippet |
#upload_status ⇒ String (readonly)
Returns the status of the uploaded video. Valid values are: “deleted”, “failed”, “processed”, “rejected”, and “unlisted”.
56 |
# File 'lib/yt/video.rb', line 56 has_attribute :upload_status, in: :status |
#view_count ⇒ <Integer> (readonly)
Returns the number of times the video has been viewed.
83 |
# File 'lib/yt/video.rb', line 83 has_attribute :view_count, in: :statistics, type: Integer |
Instance Method Details
#canonical_url ⇒ String
Returns the canonical form of the video’s URL.
144 145 146 |
# File 'lib/yt/video.rb', line 144 def canonical_url "https://www.youtube.com/watch?v=#{id}" end |
#category_title ⇒ String
Returns the title of the associated YouTube video category.
163 164 165 |
# File 'lib/yt/video.rb', line 163 def category_title CATEGORIES[category_id] end |
#channel ⇒ Yt::Channel
Returns the channel the video belongs to.
179 180 181 |
# File 'lib/yt/video.rb', line 179 def channel @channel ||= Channel.new id: channel_id end |
#length ⇒ <String>
Returns the length of the video as an ISO 8601 time, HH:MM:SS.
173 174 175 176 |
# File 'lib/yt/video.rb', line 173 def length hh, mm, ss = seconds / 3600, seconds / 60 % 60, seconds % 60 [hh, mm, ss].map{|t| t.to_s.rjust(2,'0')}.join(':') end |
#seconds ⇒ <Integer>
Returns the length of the video in seconds.
168 169 170 |
# File 'lib/yt/video.rb', line 168 def seconds to_seconds duration end |
#threads ⇒ Yt::Relation<Yt::CommentThread>
Returns the threads of the video.
184 185 186 187 188 |
# File 'lib/yt/video.rb', line 184 def threads @threads ||= Relation.new(CommentThread, video_id: id) do || get '/youtube/v3/commentThreads', video_threads_params() end end |
#thumbnail_url(size = :default) ⇒ String?
Returns the URL of the video’s thumbnail.
139 140 141 |
# File 'lib/yt/video.rb', line 139 def thumbnail_url(size = :default) thumbnails.fetch(size.to_s, {})['url'] end |