Class: Yt::Video

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

Overview

Provides methods to interact with YouTube videos.

Constant Summary collapse

CATEGORIES =

Returns the list of YouTube video categories.

Returns:

  • (Hash<Integer, String>)

    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

Attributes inherited from Resource

#data

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

#captionBoolean (readonly)

Returns whether captions are available for the video.

Returns:

  • (Boolean)

    whether captions are available for the video.



113
114
115
# File 'lib/yt/video.rb', line 113

has_attribute :caption, in: :content_details do |captioned|
  captioned == 'true'
end

#category_idInteger (readonly)

Returns the ID of the associated YouTube video category.

Returns:

  • (Integer)

    the ID of the associated YouTube video category.

See Also:



42
# File 'lib/yt/video.rb', line 42

has_attribute :category_id, in: :snippet, type: Integer

#channel_idString (readonly)

Returns the ID of the channel that the video was uploaded to.

Returns:

  • (String)

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

Returns the title of the channel that the video was uploaded to.

Returns:

  • (String)

    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.

Returns:

  • (<Integer>)

    the number of comments for the video.



95
# File 'lib/yt/video.rb', line 95

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

#definitionString (readonly)

Returns whether the video is available in high definition or only in standard definition. Valid values are: “sd” and +“hd”.

Returns:

  • (String)

    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

#descriptionString (readonly)

Returns the video’s description. Has a maximum length of 5000 bytes and may contain all valid UTF-8 characters except < and >.

Returns:

  • (String)

    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

#dimensionString (readonly)

Returns whether the video is available in 3D or in 2D. Valid values are: “2d” and +“3d”.

Returns:

  • (String)

    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.

Returns:

  • (<Integer>)

    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.

Returns:

  • (<String>)

    the length of the video as an ISO 8601 duration.



99
# File 'lib/yt/video.rb', line 99

has_attribute :duration, in: :content_details

#embeddableBoolean (readonly)

Returns whether the video can be embedded on another website.

Returns:

  • (Boolean)

    whether the video can be embedded on another website.



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

has_attribute :embeddable, in: :status

#licenseString (readonly)

Returns the video’s license. Valid values are: “creative_common” and “youtube”.

Returns:

  • (String)

    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_contentBoolean (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.

Returns:

  • (Boolean)

    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.

Returns:

  • (<Integer>)

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

Returns whether the video is an upcoming/active live broadcast. Valid values are: “live”, “none”, “upcoming”.

Returns:

  • (String)

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

Returns the video’s privacy status. Valid values are: “private”, “public”, and “unlisted”.

Returns:

  • (String)

    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

#projectionString (readonly)

Returns the projection format of the video. Valid values are: “360” and +“rectangular”.

Returns:

  • (String)

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

Returns whether the extended video statistics on the video’s watch page are publicly viewable.

Returns:

  • (Boolean)

    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_atTime (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.

Returns:

  • (Time)

    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

#tagsArray<String> (readonly)

Returns the list of tags associated with the video.

Returns:

  • (Array<String>)

    the list of tags associated with the video.



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

has_attribute :tags, in: :snippet, default: []

#thumbnailsHash<String, Hash> (readonly)

Returns the thumbnails associated with the video.

Returns:

  • (Hash<String, Hash>)

    the thumbnails associated with the video.



25
# File 'lib/yt/video.rb', line 25

has_attribute :thumbnails, in: :snippet

#titleString (readonly)

Returns the video’s title. Has a maximum length of 100 characters and may contain all valid UTF-8 characters except < and >.

Returns:

  • (String)

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

Returns the status of the uploaded video. Valid values are: “deleted”, “failed”, “processed”, “rejected”, and “unlisted”.

Returns:

  • (String)

    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.

Returns:

  • (<Integer>)

    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_urlString

Returns the canonical form of the video’s URL.

Returns:

  • (String)

    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_titleString

Returns the title of the associated YouTube video category.

Returns:

  • (String)

    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

#channelYt::Channel

Returns the channel the video belongs to.

Returns:



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.

Returns:

  • (<String>)

    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.

Returns:

  • (<Integer>)

    the length of the video in seconds.



168
169
170
# File 'lib/yt/video.rb', line 168

def seconds
  to_seconds duration
end

#threadsYt::Relation<Yt::CommentThread>

Returns the threads of the video.

Returns:



184
185
186
187
188
# File 'lib/yt/video.rb', line 184

def threads
  @threads ||= Relation.new(CommentThread, video_id: id) do |options|
    get '/youtube/v3/commentThreads', video_threads_params(options)
  end
end

#thumbnail_url(size = :default) ⇒ String?

Returns the URL of the video’s thumbnail.

Parameters:

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

    The size of the video’s thumbnail.

Returns:

  • (String)

    if size is :default, the URL of a 120x90px image.

  • (String)

    if size is :medium, the URL of a 320x180px image.

  • (String)

    if size is :high, the URL of a 480x360px image.

  • (String)

    if size is :standard, the URL of a 640x480px image.

  • (String)

    if size is :maxres, the URL of a 1280x720px image.

  • (nil)

    if the size is none of the above.



139
140
141
# File 'lib/yt/video.rb', line 139

def thumbnail_url(size = :default)
  thumbnails.fetch(size.to_s, {})['url']
end