Class: Yt::Models::Video
- Defined in:
- lib/yt/models/video.rb
Overview
Provides methods to interact with YouTube videos.
Instance Attribute Summary collapse
-
#annotations ⇒ Yt::Collections::Annotations
readonly
The video’s annotations.
-
#content_detail ⇒ Yt::Models::ContentDetail
readonly
The video’s content details.
-
#live_streaming_detail ⇒ Yt::Models::LiveStreamingDetail
readonly
Live streaming detail.
-
#rating ⇒ Yt::Models::Rating
readonly
The video’s rating.
-
#resumable_sessions ⇒ Yt::Collections::ResumableSessions
readonly
The sessions used to upload thumbnails using the resumable upload protocol.
-
#statistics_set ⇒ Yt::Models::StatisticsSet
readonly
The statistics for the video.
Attributes inherited from Resource
Instance Method Summary collapse
-
#average_view_duration(options = {}) ⇒ Hash<Date, Float>
The average_view_duration for a range of a days.
-
#average_view_duration_on(date) ⇒ Float
The average_view_duration for a single day.
-
#average_view_percentage(options = {}) ⇒ Hash<Date, Float>
The average_view_percentage for a range of a days.
-
#average_view_percentage_on(date) ⇒ Float
The average_view_percentage for a single day.
-
#comments(options = {}) ⇒ Hash<Date, Float>
The comments for a range of a days.
-
#comments_on(date) ⇒ Float
The comments for a single day.
-
#delete(options = {}) ⇒ Boolean
Deletes the video.
-
#dislike ⇒ Boolean
Dislikes the video on behalf of the authenticated account.
-
#dislikes(options = {}) ⇒ Hash<Date, Float>
The dislikes for a range of a days.
-
#dislikes_on(date) ⇒ Float
The dislikes for a single day.
-
#earnings(options = {}) ⇒ Hash<Date, Float>
The earnings for a range of a days.
-
#earnings_on(date) ⇒ Float
The earnings for a single day.
-
#estimated_minutes_watched(options = {}) ⇒ Hash<Date, Float>
The estimated_minutes_watched for a range of a days.
-
#estimated_minutes_watched_on(date) ⇒ Float
The estimated_minutes_watched for a single day.
- #exists? ⇒ Boolean
-
#favorites_added(options = {}) ⇒ Hash<Date, Float>
The favorites_added for a range of a days.
-
#favorites_added_on(date) ⇒ Float
The favorites_added for a single day.
-
#favorites_removed(options = {}) ⇒ Hash<Date, Float>
The favorites_removed for a range of a days.
-
#favorites_removed_on(date) ⇒ Float
The favorites_removed for a single day.
-
#impressions(options = {}) ⇒ Hash<Date, Float>
The impressions for a range of a days.
-
#impressions_on(date) ⇒ Float
The impressions for a single day.
-
#initialize(options = {}) ⇒ Video
constructor
Override Resource’s new to set statistics and content details as well if the response includes them.
-
#like ⇒ Boolean
Likes the video on behalf of the authenticated account.
-
#liked? ⇒ Boolean
Returns whether the authenticated account likes the video.
-
#likes(options = {}) ⇒ Hash<Date, Float>
The likes for a range of a days.
-
#likes_on(date) ⇒ Float
The likes for a single day.
-
#monetized_playbacks(options = {}) ⇒ Hash<Date, Float>
The monetized_playbacks for a range of a days.
-
#monetized_playbacks_on(date) ⇒ Float
The monetized_playbacks for a single day.
-
#shares(options = {}) ⇒ Hash<Date, Float>
The shares for a range of a days.
-
#shares_on(date) ⇒ Float
The shares for a single day.
-
#subscribers_gained(options = {}) ⇒ Hash<Date, Float>
The subscribers_gained for a range of a days.
-
#subscribers_gained_on(date) ⇒ Float
The subscribers_gained for a single day.
-
#subscribers_lost(options = {}) ⇒ Hash<Date, Float>
The subscribers_lost for a range of a days.
-
#subscribers_lost_on(date) ⇒ Float
The subscribers_lost for a single day.
-
#tags ⇒ Array<Yt::Models::Tag>
Returns the list of keyword tags associated with the video.
-
#unlike ⇒ Boolean
Resets the rating of the video on behalf of the authenticated account.
-
#upload_thumbnail(path_or_url) ⇒ Object
Uploads a thumbnail.
-
#viewer_percentage(filters = {}) ⇒ Float
The percentage of viewer matching the filters.
-
#viewer_percentages ⇒ Hash<Symbol,Hash<String,Float>>
The viewer percentages.
-
#views(options = {}) ⇒ Hash<Date, Float>
The views for a range of a days.
-
#views_on(date) ⇒ Float
The views for a single day.
Methods inherited from Resource
Methods included from Associations::HasReports
Methods included from Associations::HasViewerPercentages
Methods included from Associations::HasOne
Methods included from Associations::HasMany
Methods included from Associations::HasAuthentication
Constructor Details
#initialize(options = {}) ⇒ Video
Override Resource’s new to set statistics and content details as well if the response includes them
108 109 110 111 112 113 114 115 116 |
# File 'lib/yt/models/video.rb', line 108 def initialize( = {}) super if [:statistics] @statistics_set = StatisticsSet.new data: [:statistics] end if [:content_details] @content_detail = ContentDetail.new data: [:content_details] end end |
Instance Attribute Details
#annotations ⇒ Yt::Collections::Annotations (readonly)
Returns the video’s annotations.
41 |
# File 'lib/yt/models/video.rb', line 41 has_many :annotations |
#content_detail ⇒ Yt::Models::ContentDetail (readonly)
Returns the video’s content details.
22 |
# File 'lib/yt/models/video.rb', line 22 has_one :content_detail |
#live_streaming_detail ⇒ Yt::Models::LiveStreamingDetail (readonly)
Returns live streaming detail.
35 |
# File 'lib/yt/models/video.rb', line 35 has_one :live_streaming_detail |
#rating ⇒ Yt::Models::Rating (readonly)
Returns the video’s rating.
31 |
# File 'lib/yt/models/video.rb', line 31 has_one :rating |
#resumable_sessions ⇒ Yt::Collections::ResumableSessions (readonly)
Returns the sessions used to upload thumbnails using the resumable upload protocol.
104 |
# File 'lib/yt/models/video.rb', line 104 has_many :resumable_sessions |
#statistics_set ⇒ Yt::Models::StatisticsSet (readonly)
Returns the statistics for the video.
97 |
# File 'lib/yt/models/video.rb', line 97 has_one :statistics_set |
Instance Method Details
#average_view_duration(options = {}) ⇒ Hash<Date, Float>
Returns the average_view_duration for a range of a days.
81 |
# File 'lib/yt/models/video.rb', line 81 has_report :average_view_duration |
#average_view_duration_on(date) ⇒ Float
Returns the average_view_duration for a single day.
81 |
# File 'lib/yt/models/video.rb', line 81 has_report :average_view_duration |
#average_view_percentage(options = {}) ⇒ Hash<Date, Float>
Returns the average_view_percentage for a range of a days.
84 |
# File 'lib/yt/models/video.rb', line 84 has_report :average_view_percentage |
#average_view_percentage_on(date) ⇒ Float
Returns the average_view_percentage for a single day.
84 |
# File 'lib/yt/models/video.rb', line 84 has_report :average_view_percentage |
#comments(options = {}) ⇒ Hash<Date, Float>
Returns the comments for a range of a days.
50 |
# File 'lib/yt/models/video.rb', line 50 has_report :comments |
#comments_on(date) ⇒ Float
Returns the comments for a single day.
50 |
# File 'lib/yt/models/video.rb', line 50 has_report :comments |
#delete(options = {}) ⇒ Boolean
140 141 142 143 |
# File 'lib/yt/models/video.rb', line 140 def delete( = {}) do_delete {@id = nil} !exists? end |
#dislike ⇒ Boolean
179 180 181 182 |
# File 'lib/yt/models/video.rb', line 179 def dislike .set :dislike !liked? end |
#dislikes(options = {}) ⇒ Hash<Date, Float>
Returns the dislikes for a range of a days.
56 |
# File 'lib/yt/models/video.rb', line 56 has_report :dislikes |
#dislikes_on(date) ⇒ Float
Returns the dislikes for a single day.
56 |
# File 'lib/yt/models/video.rb', line 56 has_report :dislikes |
#earnings(options = {}) ⇒ Hash<Date, Float>
Returns the earnings for a range of a days.
44 |
# File 'lib/yt/models/video.rb', line 44 has_report :earnings |
#earnings_on(date) ⇒ Float
Returns the earnings for a single day.
44 |
# File 'lib/yt/models/video.rb', line 44 has_report :earnings |
#estimated_minutes_watched(options = {}) ⇒ Hash<Date, Float>
Returns the estimated_minutes_watched for a range of a days.
78 |
# File 'lib/yt/models/video.rb', line 78 has_report :estimated_minutes_watched |
#estimated_minutes_watched_on(date) ⇒ Float
Returns the estimated_minutes_watched for a single day.
78 |
# File 'lib/yt/models/video.rb', line 78 has_report :estimated_minutes_watched |
#exists? ⇒ Boolean
145 146 147 |
# File 'lib/yt/models/video.rb', line 145 def exists? !@id.nil? end |
#favorites_added(options = {}) ⇒ Hash<Date, Float>
Returns the favorites_added for a range of a days.
72 |
# File 'lib/yt/models/video.rb', line 72 has_report :favorites_added |
#favorites_added_on(date) ⇒ Float
Returns the favorites_added for a single day.
72 |
# File 'lib/yt/models/video.rb', line 72 has_report :favorites_added |
#favorites_removed(options = {}) ⇒ Hash<Date, Float>
Returns the favorites_removed for a range of a days.
75 |
# File 'lib/yt/models/video.rb', line 75 has_report :favorites_removed |
#favorites_removed_on(date) ⇒ Float
Returns the favorites_removed for a single day.
75 |
# File 'lib/yt/models/video.rb', line 75 has_report :favorites_removed |
#impressions(options = {}) ⇒ Hash<Date, Float>
Returns the impressions for a range of a days.
87 |
# File 'lib/yt/models/video.rb', line 87 has_report :impressions |
#impressions_on(date) ⇒ Float
Returns the impressions for a single day.
87 |
# File 'lib/yt/models/video.rb', line 87 has_report :impressions |
#like ⇒ Boolean
167 168 169 170 |
# File 'lib/yt/models/video.rb', line 167 def like .set :like liked? end |
#liked? ⇒ Boolean
156 157 158 |
# File 'lib/yt/models/video.rb', line 156 def liked? . == :like end |
#likes(options = {}) ⇒ Hash<Date, Float>
Returns the likes for a range of a days.
53 |
# File 'lib/yt/models/video.rb', line 53 has_report :likes |
#likes_on(date) ⇒ Float
Returns the likes for a single day.
53 |
# File 'lib/yt/models/video.rb', line 53 has_report :likes |
#monetized_playbacks(options = {}) ⇒ Hash<Date, Float>
Returns the monetized_playbacks for a range of a days.
90 |
# File 'lib/yt/models/video.rb', line 90 has_report :monetized_playbacks |
#monetized_playbacks_on(date) ⇒ Float
Returns the monetized_playbacks for a single day.
90 |
# File 'lib/yt/models/video.rb', line 90 has_report :monetized_playbacks |
#shares(options = {}) ⇒ Hash<Date, Float>
Returns the shares for a range of a days.
59 |
# File 'lib/yt/models/video.rb', line 59 has_report :shares |
#shares_on(date) ⇒ Float
Returns the shares for a single day.
59 |
# File 'lib/yt/models/video.rb', line 59 has_report :shares |
#subscribers_gained(options = {}) ⇒ Hash<Date, Float>
Returns the subscribers_gained for a range of a days.
64 |
# File 'lib/yt/models/video.rb', line 64 has_report :subscribers_gained |
#subscribers_gained_on(date) ⇒ Float
Returns the subscribers_gained for a single day.
64 |
# File 'lib/yt/models/video.rb', line 64 has_report :subscribers_gained |
#subscribers_lost(options = {}) ⇒ Hash<Date, Float>
Returns the subscribers_lost for a range of a days.
69 |
# File 'lib/yt/models/video.rb', line 69 has_report :subscribers_lost |
#subscribers_lost_on(date) ⇒ Float
Returns the subscribers_lost for a single day.
69 |
# File 'lib/yt/models/video.rb', line 69 has_report :subscribers_lost |
#tags ⇒ Array<Yt::Models::Tag>
Returns the list of keyword tags associated with the video. Since YouTube API only returns tags on Videos#list, the memoized (e.g., by calling account.videos or channel.videos), so that the full snippet (with tags) is loaded, rather than the partial one.
126 127 128 129 130 131 |
# File 'lib/yt/models/video.rb', line 126 def unless snippet..any? || snippet. || @auth.nil? @snippet = nil end snippet. end |
#unlike ⇒ Boolean
191 192 193 194 |
# File 'lib/yt/models/video.rb', line 191 def unlike .set :none !liked? end |
#upload_thumbnail(path_or_url) ⇒ Object
Uploads a thumbnail
203 204 205 206 207 208 209 210 |
# File 'lib/yt/models/video.rb', line 203 def upload_thumbnail(path_or_url) file = open(path_or_url, 'rb') rescue StringIO.new session = resumable_sessions.insert file.size session.update(body: file) do |data| snippet.instance_variable_set :@thumbnails, data['items'].first end end |
#viewer_percentage(filters = {}) ⇒ Float
Returns the percentage of viewer matching the filters.
93 |
# File 'lib/yt/models/video.rb', line 93 has_viewer_percentages |
#viewer_percentages ⇒ Hash<Symbol,Hash<String,Float>>
Returns the viewer percentages. The first-level hash identifies the genres (:female, :male). The second-level hash identifies the age ranges (‘18-24’, ‘25-34’, ‘35-44’, ‘45-54’, ‘55-64’, ‘65-’).
93 |
# File 'lib/yt/models/video.rb', line 93 has_viewer_percentages |
#views(options = {}) ⇒ Hash<Date, Float>
Returns the views for a range of a days.
47 |
# File 'lib/yt/models/video.rb', line 47 has_report :views |
#views_on(date) ⇒ Float
Returns the views for a single day.
47 |
# File 'lib/yt/models/video.rb', line 47 has_report :views |