Class: Yt::Models::Video

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

Overview

Provides methods to interact with YouTube videos.

Constant Summary

Constants inherited from Resource

Resource::CHANNEL_PATTERNS, Resource::PLAYLIST_PATTERNS, Resource::VIDEO_PATTERNS

Instance Attribute Summary collapse

Attributes inherited from Resource

#id, #privacy_status

Instance Method Summary collapse

Methods inherited from Resource

#private?, #public?, #unlisted?

Instance Attribute Details

#actual_end_timeTime? (readonly)

The time when a live broadcast ended.

Returns:

  • (Time)

    if the broadcast is over, the time it actually ended.

  • (nil)

    if the broadcast is not over or video is not live.



374
# File 'lib/yt/models/video.rb', line 374

delegate :actual_end_time, to: :live_streaming_detail

#actual_start_timeTime? (readonly)

The time when a live broadcast started.

Returns:

  • (Time)

    if the broadcast has begun, the time it actually started.

  • (nil)

    if the broadcast has not begun or video is not live.



368
# File 'lib/yt/models/video.rb', line 368

delegate :actual_start_time, to: :live_streaming_detail

#ad_formatsArray<String> (readonly)

Returns the list of ad formats that the video is allowed to show. Possible values are: ‘long’, ‘overlay’, ‘standard_instream’, ‘third_party’, ‘trueview_inslate’, ‘trueview_instream’.

Returns:

  • (Array<String>)

    the list of ad formats that the video is allowed to show. Possible values are: ‘long’, ‘overlay’, ‘standard_instream’, ‘third_party’, ‘trueview_inslate’, ‘trueview_instream’.



358
# File 'lib/yt/models/video.rb', line 358

delegate :ad_formats, to: :advertising_options_set

#annotationsYt::Collections::Annotations (readonly)

Returns the video’s annotations.

Returns:



406
# File 'lib/yt/models/video.rb', line 406

has_many :annotations

#channel_idString (readonly)

Returns the ID of the channel that the video belongs to.

Returns:

  • (String)

    the ID of the channel that the video belongs to.



34
# File 'lib/yt/models/video.rb', line 34

delegate :channel_id, to: :snippet

#channel_titleString (readonly)

Returns the title of the channel that the video belongs to.

Returns:

  • (String)

    the title of the channel that the video belongs to.



38
# File 'lib/yt/models/video.rb', line 38

delegate :channel_title, to: :snippet

#claimObject (readonly)



413
414
415
# File 'lib/yt/models/video.rb', line 413

def claim
  @claim
end

#comment_countInteger (readonly)

Returns the number of comments for the video.

Returns:

  • (Integer)

    the number of comments for the video.



525
# File 'lib/yt/models/video.rb', line 525

delegate :comment_count, to: :statistics_set

#comments(options = {}) ⇒ Hash<Date, Integer>, ... (readonly)

Returns the comments grouped by the given dimension.

Examples:

Get the comments for each day of last week:

resource.comments since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the comments for this and last month:

resource.comments since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the comments for the whole last week:

resource.comments since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the comments for the whole last week in France only:

resource.comments since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the comments.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect comments by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the comments to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the comments for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the comments for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the comments for the entire time-range (under the key :total).



402
# File 'lib/yt/models/video.rb', line 402

has_many :comment_threads

#concurrent_viewersInteger? (readonly)

The number of current viewers of a live broadcast.

Returns:

  • (Integer)

    if the broadcast has current viewers and the broadcast owner has not hidden the viewcount for the video, the number of viewers currently watching the broadcast.

  • (nil)

    if the broadcast has ended or the broadcast owner has hidden the viewcount for the video or the video is not live.



397
# File 'lib/yt/models/video.rb', line 397

delegate :concurrent_viewers, to: :live_streaming_detail

#containerString (readonly)

Returns the video container of the uploaded file. (e.g. ‘mov’).

Returns:

  • (String)

    the video container of the uploaded file. (e.g. ‘mov’).



299
# File 'lib/yt/models/video.rb', line 299

delegate :container, to: :file_detail

#descriptionString (readonly)

Returns the video’s description.

Returns:

  • (String)

    the video’s description.



17
# File 'lib/yt/models/video.rb', line 17

delegate :description, to: :snippet

#dislike_countInteger (readonly)

Returns the number of users who disliked the video.

Returns:

  • (Integer)

    the number of users who disliked the video.



517
# File 'lib/yt/models/video.rb', line 517

delegate :dislike_count, to: :statistics_set

#durationString (readonly)

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.



247
# File 'lib/yt/models/video.rb', line 247

delegate :duration, to: :content_detail

#embed_htmlString (readonly)

Returns the HTML code of an <iframe> tag that embeds a player that will play the video.

Returns:

  • (String)

    the HTML code of an <iframe> tag that embeds a player that will play the video.



534
# File 'lib/yt/models/video.rb', line 534

delegate :embed_html, to: :player

#favorite_countInteger (readonly)

Returns the number of users who marked the video as favorite.

Returns:

  • (Integer)

    the number of users who marked the video as favorite.



521
# File 'lib/yt/models/video.rb', line 521

delegate :favorite_count, to: :statistics_set

#file_nameString (readonly)

Returns the name of the uploaded file.

Returns:

  • (String)

    the name of the uploaded file.



286
# File 'lib/yt/models/video.rb', line 286

delegate :file_name, to: :file_detail

#file_sizeInteger (readonly)

Returns the size of the uploaded file (in bytes).

Returns:

  • (Integer)

    the size of the uploaded file (in bytes).



290
# File 'lib/yt/models/video.rb', line 290

delegate :file_size, to: :file_detail

#file_typeString (readonly)

Returns the type of file uploaded. May be one of: archive, audio, document, image, other, project, video.

Returns:

  • (String)

    the type of file uploaded. May be one of: archive, audio, document, image, other, project, video.



295
# File 'lib/yt/models/video.rb', line 295

delegate :file_type, to: :file_detail

#licenseString (readonly)

Returns the video’s license. Possible values are: ‘creativeCommon’, ‘youtube’.

Returns:

  • (String)

    the video’s license. Possible values are: ‘creativeCommon’, ‘youtube’.



197
# File 'lib/yt/models/video.rb', line 197

delegate :license, to: :status

#like_countInteger (readonly)

Returns the number of users who liked the video.

Returns:

  • (Integer)

    the number of users who liked the video.



513
# File 'lib/yt/models/video.rb', line 513

delegate :like_count, to: :statistics_set

#live_broadcast_contentString (readonly)

Returns the type of live broadcast that the video contains. Possible values are: ‘live’, ‘none’, ‘upcoming’.

Returns:

  • (String)

    the type of live broadcast that the video contains. Possible values are: ‘live’, ‘none’, ‘upcoming’.



48
# File 'lib/yt/models/video.rb', line 48

delegate :live_broadcast_content, to: :snippet

#published_atTime (readonly)

Returns the date and time that the video was published.

Returns:

  • (Time)

    the date and time that the video was published.



30
# File 'lib/yt/models/video.rb', line 30

delegate :published_at, to: :snippet

#scheduled_end_timeTime? (readonly)

The time when a live broadcast is scheduled to end.

Returns:

  • (Time)

    if the broadcast is scheduled to end, the time it is scheduled to end.

  • (nil)

    if the broadcast is scheduled to continue indefinitely or the video is not live.



388
# File 'lib/yt/models/video.rb', line 388

delegate :scheduled_end_time, to: :live_streaming_detail

#scheduled_start_timeTime? (readonly)

The time when a live broadcast is scheduled to start.

Returns:

  • (Time)

    the time that the broadcast is scheduled to begin.

  • (nil)

    if video is not live.



380
# File 'lib/yt/models/video.rb', line 380

delegate :scheduled_start_time, to: :live_streaming_detail

#titleString (readonly)

Returns the video’s title.

Returns:

  • (String)

    the video’s title.



13
# File 'lib/yt/models/video.rb', line 13

delegate :title, to: :snippet

#view_countInteger (readonly)

Returns the number of times the video has been viewed.

Returns:

  • (Integer)

    the number of times the video has been viewed.



509
# File 'lib/yt/models/video.rb', line 509

delegate :view_count, to: :statistics_set

Instance Method Details

#aborted?Boolean

Returns whether the video failed to upload to YouTube because the uploading process was aborted.

Returns:

  • (Boolean)

    whether the video failed to upload to YouTube because the uploading process was aborted.



121
122
123
# File 'lib/yt/models/video.rb', line 121

def aborted?
  status.failure_reason == 'uploadAborted'
end

#ad_impressions(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the ad_impressions grouped by the given dimension.

Examples:

Get the ad_impressions for each day of last week:

resource.ad_impressions since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the ad_impressions for this and last month:

resource.ad_impressions since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the ad_impressions for the whole last week:

resource.ad_impressions since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the ad_impressions for the whole last week in France only:

resource.ad_impressions since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the ad_impressions.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect ad_impressions by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the ad_impressions to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the ad_impressions for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the ad_impressions for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the ad_impressions for the entire time-range (under the key :total).



495
# File 'lib/yt/models/video.rb', line 495

has_report :ad_impressions, Integer

#age_restricted?Boolean

Returns whether the video is identified by YouTube as age-restricted content.

Returns:

  • (Boolean)

    whether the video is identified by YouTube as age-restricted content.



276
277
278
# File 'lib/yt/models/video.rb', line 276

def age_restricted?
  content_detail.youtube_rating == 'ytAgeRestricted'
end

#annotation_click_through_rate(options = {}) ⇒ Hash<Date, Float>, ...

Returns the annotation_click_through_rate grouped by the given dimension.

Examples:

Get the annotation_click_through_rate for each day of last week:

resource.annotation_click_through_rate since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the annotation_click_through_rate for this and last month:

resource.annotation_click_through_rate since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the annotation_click_through_rate for the whole last week:

resource.annotation_click_through_rate since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the annotation_click_through_rate for the whole last week in Texas only:

resource.annotation_click_through_rate since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the annotation_click_through_rate.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect annotation_click_through_rate by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the annotation_click_through_rate to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Float>)

    if grouped by day, the annotation_click_through_rate for each day in the time-range.

  • (Hash<Range<Date, Date>, Float>)

    if grouped by month, the annotation_click_through_rate for each month in the time-range.

  • (Hash<Symbol, Float>)

    if grouped by range, the annotation_click_through_rate for the entire time-range (under the key :total).



468
# File 'lib/yt/models/video.rb', line 468

has_report :annotation_click_through_rate, Float

#annotation_clicks(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the annotation_clicks grouped by the given dimension.

Examples:

Get the annotation_clicks for each day of last week:

resource.annotation_clicks since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the annotation_clicks for this and last month:

resource.annotation_clicks since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the annotation_clicks for the whole last week:

resource.annotation_clicks since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the annotation_clicks for the whole last week in Texas only:

resource.annotation_clicks since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the annotation_clicks.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect annotation_clicks by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the annotation_clicks to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the annotation_clicks for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the annotation_clicks for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the annotation_clicks for the entire time-range (under the key :total).



465
# File 'lib/yt/models/video.rb', line 465

has_report :annotation_clicks, Integer

#annotation_close_rate(options = {}) ⇒ Hash<Date, Float>, ...

Returns the annotation_close_rate grouped by the given dimension.

Examples:

Get the annotation_close_rate for each day of last week:

resource.annotation_close_rate since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the annotation_close_rate for this and last month:

resource.annotation_close_rate since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the annotation_close_rate for the whole last week:

resource.annotation_close_rate since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the annotation_close_rate for the whole last week in Texas only:

resource.annotation_close_rate since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the annotation_close_rate.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect annotation_close_rate by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the annotation_close_rate to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Float>)

    if grouped by day, the annotation_close_rate for each day in the time-range.

  • (Hash<Range<Date, Date>, Float>)

    if grouped by month, the annotation_close_rate for each month in the time-range.

  • (Hash<Symbol, Float>)

    if grouped by range, the annotation_close_rate for the entire time-range (under the key :total).



471
# File 'lib/yt/models/video.rb', line 471

has_report :annotation_close_rate, Float

#average_view_duration(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the average_view_duration grouped by the given dimension.

Examples:

Get the average_view_duration for each day of last week:

resource.average_view_duration since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the average_view_duration for this and last month:

resource.average_view_duration since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the average_view_duration for the whole last week:

resource.average_view_duration since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the average_view_duration for the whole last week in Texas only:

resource.average_view_duration since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the average_view_duration.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect average_view_duration by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the average_view_duration to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the average_view_duration for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the average_view_duration for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the average_view_duration for the entire time-range (under the key :total).



459
# File 'lib/yt/models/video.rb', line 459

has_report :average_view_duration, Integer

#average_view_percentage(options = {}) ⇒ Hash<Date, Float>, ...

Returns the average_view_percentage grouped by the given dimension.

Examples:

Get the average_view_percentage for each day of last week:

resource.average_view_percentage since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the average_view_percentage for this and last month:

resource.average_view_percentage since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the average_view_percentage for the whole last week:

resource.average_view_percentage since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the average_view_percentage for the whole last week in Texas only:

resource.average_view_percentage since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the average_view_percentage.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect average_view_percentage by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the average_view_percentage to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Float>)

    if grouped by day, the average_view_percentage for each day in the time-range.

  • (Hash<Range<Date, Date>, Float>)

    if grouped by month, the average_view_percentage for each month in the time-range.

  • (Hash<Symbol, Float>)

    if grouped by range, the average_view_percentage for the entire time-range (under the key :total).



462
# File 'lib/yt/models/video.rb', line 462

has_report :average_view_percentage, Float

#belongs_to_closed_account?Boolean

Returns whether the video was rejected by YouTube because the account that uploaded the video has been closed.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube because the account that uploaded the video has been closed.



171
172
173
# File 'lib/yt/models/video.rb', line 171

def belongs_to_closed_account?
  status.rejection_reason == 'uploaderAccountClosed'
end

#belongs_to_suspended_account?Boolean

Returns whether the video was rejected by YouTube because the account that uploaded the video has been suspended.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube because the account that uploaded the video has been suspended.



177
178
179
# File 'lib/yt/models/video.rb', line 177

def belongs_to_suspended_account?
  status.rejection_reason == 'uploaderAccountSuspended'
end

#captioned?Boolean

Returns whether captions are available for the video.

Returns:

  • (Boolean)

    whether captions are available for the video.



264
265
266
# File 'lib/yt/models/video.rb', line 264

def captioned?
  content_detail.caption == 'true'
end

#card_click_rate(options = {}) ⇒ Hash<Date, Float>, ...

Returns the card_click_rate grouped by the given dimension.

Examples:

Get the card_click_rate for each day of last week:

resource.card_click_rate since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the card_click_rate for this and last month:

resource.card_click_rate since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the card_click_rate for the whole last week:

resource.card_click_rate since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the card_click_rate for the whole last week in Texas only:

resource.card_click_rate since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the card_click_rate.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect card_click_rate by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the card_click_rate to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Float>)

    if grouped by day, the card_click_rate for each day in the time-range.

  • (Hash<Range<Date, Date>, Float>)

    if grouped by month, the card_click_rate for each month in the time-range.

  • (Hash<Symbol, Float>)

    if grouped by range, the card_click_rate for the entire time-range (under the key :total).



480
# File 'lib/yt/models/video.rb', line 480

has_report :card_click_rate, Float

#card_clicks(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the card_clicks grouped by the given dimension.

Examples:

Get the card_clicks for each day of last week:

resource.card_clicks since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the card_clicks for this and last month:

resource.card_clicks since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the card_clicks for the whole last week:

resource.card_clicks since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the card_clicks for the whole last week in Texas only:

resource.card_clicks since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the card_clicks.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect card_clicks by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the card_clicks to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the card_clicks for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the card_clicks for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the card_clicks for the entire time-range (under the key :total).



477
# File 'lib/yt/models/video.rb', line 477

has_report :card_clicks, Integer

#card_impressions(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the card_impressions grouped by the given dimension.

Examples:

Get the card_impressions for each day of last week:

resource.card_impressions since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the card_impressions for this and last month:

resource.card_impressions since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the card_impressions for the whole last week:

resource.card_impressions since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the card_impressions for the whole last week in Texas only:

resource.card_impressions since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the card_impressions.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect card_impressions by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the card_impressions to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the card_impressions for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the card_impressions for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the card_impressions for the entire time-range (under the key :total).



474
# File 'lib/yt/models/video.rb', line 474

has_report :card_impressions, Integer

#card_teaser_click_rate(options = {}) ⇒ Hash<Date, Float>, ...

Returns the card_teaser_click_rate grouped by the given dimension.

Examples:

Get the card_teaser_click_rate for each day of last week:

resource.card_teaser_click_rate since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the card_teaser_click_rate for this and last month:

resource.card_teaser_click_rate since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the card_teaser_click_rate for the whole last week:

resource.card_teaser_click_rate since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the card_teaser_click_rate for the whole last week in Texas only:

resource.card_teaser_click_rate since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the card_teaser_click_rate.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect card_teaser_click_rate by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the card_teaser_click_rate to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Float>)

    if grouped by day, the card_teaser_click_rate for each day in the time-range.

  • (Hash<Range<Date, Date>, Float>)

    if grouped by month, the card_teaser_click_rate for each month in the time-range.

  • (Hash<Symbol, Float>)

    if grouped by range, the card_teaser_click_rate for the entire time-range (under the key :total).



489
# File 'lib/yt/models/video.rb', line 489

has_report :card_teaser_click_rate, Float

#card_teaser_clicks(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the card_teaser_clicks grouped by the given dimension.

Examples:

Get the card_teaser_clicks for each day of last week:

resource.card_teaser_clicks since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the card_teaser_clicks for this and last month:

resource.card_teaser_clicks since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the card_teaser_clicks for the whole last week:

resource.card_teaser_clicks since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the card_teaser_clicks for the whole last week in Texas only:

resource.card_teaser_clicks since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the card_teaser_clicks.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect card_teaser_clicks by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the card_teaser_clicks to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the card_teaser_clicks for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the card_teaser_clicks for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the card_teaser_clicks for the entire time-range (under the key :total).



486
# File 'lib/yt/models/video.rb', line 486

has_report :card_teaser_clicks, Integer

#card_teaser_impressions(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the card_teaser_impressions grouped by the given dimension.

Examples:

Get the card_teaser_impressions for each day of last week:

resource.card_teaser_impressions since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the card_teaser_impressions for this and last month:

resource.card_teaser_impressions since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the card_teaser_impressions for the whole last week:

resource.card_teaser_impressions since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the card_teaser_impressions for the whole last week in Texas only:

resource.card_teaser_impressions since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the card_teaser_impressions.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect card_teaser_impressions by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the card_teaser_impressions to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the card_teaser_impressions for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the card_teaser_impressions for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the card_teaser_impressions for the entire time-range (under the key :total).



483
# File 'lib/yt/models/video.rb', line 483

has_report :card_teaser_impressions, Integer

#category_idString

Returns ID of the YouTube category associated with the video.

Returns:

  • (String)

    ID of the YouTube category associated with the video.



56
57
58
# File 'lib/yt/models/video.rb', line 56

def category_id
  ensure_complete_snippet :category_id
end

#category_titleString

Returns the video category’s title.

Returns:

  • (String)

    the video category’s title.



345
346
347
# File 'lib/yt/models/video.rb', line 345

def category_title
  video_category.title
end

#channel_url<String>

Returns the URL of the channel that the video belongs to.

Returns:

  • (<String>)

    the URL of the channel that the video belongs to.



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

def channel_url
  "https://www.youtube.com/channel/#{channel_id}"
end

#claimed?Boolean

Returns whether the video was rejected by YouTube because the video was claimed by a different account.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube because the video was claimed by a different account.



127
128
129
# File 'lib/yt/models/video.rb', line 127

def claimed?
  status.rejection_reason == 'claim'
end

#delete(options = {}) ⇒ Boolean

Deletes the video on behalf of the authenticated account.

Returns:

  • (Boolean)

    whether the video does not exist anymore.

Raises:



557
558
559
560
# File 'lib/yt/models/video.rb', line 557

def delete(options = {})
  do_delete {@id = nil}
  !exists?
end

#deleted?Boolean

Returns whether the video was deleted by the user.

Returns:

  • (Boolean)

    whether the video was deleted by the user.



63
64
65
# File 'lib/yt/models/video.rb', line 63

def deleted?
  status.upload_status == 'deleted'
end

#dislikeBoolean

Dislikes the video on behalf of the authenticated account.

Returns:

  • (Boolean)

    whether the account does not like the video.

Raises:



326
327
328
329
# File 'lib/yt/models/video.rb', line 326

def dislike
  rating.set :dislike
  !liked?
end

#dislikes(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the dislikes grouped by the given dimension.

Examples:

Get the dislikes for each day of last week:

resource.dislikes since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the dislikes for this and last month:

resource.dislikes since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the dislikes for the whole last week:

resource.dislikes since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the dislikes for the whole last week in France only:

resource.dislikes since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the dislikes.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect dislikes by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the dislikes to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the dislikes for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the dislikes for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the dislikes for the entire time-range (under the key :total).



437
# File 'lib/yt/models/video.rb', line 437

has_report :dislikes, Integer

#duplicate?Boolean

Returns whether the video was rejected by YouTube because the video is a duplicate of another video.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube because the video is a duplicate of another video.



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

def duplicate?
  status.rejection_reason == 'duplicate'
end

#embeddable?Boolean

Returns whether the video can be embedded on other websites.

Returns:

  • (Boolean)

    whether the video can be embedded on other websites.



222
223
224
# File 'lib/yt/models/video.rb', line 222

def embeddable?
  status.embeddable
end

#empty?Boolean

Returns whether the video failed to upload to YouTube because the video file is empty.

Returns:

  • (Boolean)

    whether the video failed to upload to YouTube because the video file is empty.



102
103
104
# File 'lib/yt/models/video.rb', line 102

def empty?
  status.failure_reason == 'emptyFile'
end

#estimated_minutes_watched(options = {}) ⇒ Hash<Symbol, Integer>, ...

Returns the estimated_minutes_watched grouped by the given dimension.

Examples:

Get yesterday’s estimated_minutes_watched by embedded player location:

resource.estimated_minutes_watched since: 1.day.ago, until: 1.day.ago, by: :embedded_player_location
# => {"fullscreen.net" => 92.0, "yahoo.com" => 14.0, …}

Get yesterday’s estimated_minutes_watched grouped by playback location:

resource.estimated_minutes_watched since: 1.day.ago, until: 1.day.ago, by: :playback_location
# => {embedded: 53.0, watch: 467.0, …}
Get yesterday’s estimated_minutes_watched by related video, eager-loading the snippet of each video
resource.estimated_minutes_watched since: 1.day.ago, until: 1.day.ago, by: :related_video, includes: [:snippet]
# => {#<Yt::Video @id=…> => 33.0, #<Yt::Video @id=…> => 12.0, …}

Get yesterday’s estimated_minutes_watched by search term:

resource.estimated_minutes_watched since: 1.day.ago, until: 1.day.ago, by: :search_term
# => {"fullscreen" => 33.0, "good music" => 12.0, …}

Get yesterday’s estimated_minutes_watched by URL that referred to the resource:

resource.estimated_minutes_watched since: 1.day.ago, until: 1.day.ago, by: :referrer
# => {"Google Search" => 33.0, "ytimg.com" => 12.0, …}

Get yesterday’s estimated_minutes_watched by device type:

resource.estimated_minutes_watched since: 1.day.ago, until: 1.day.ago, by: :device_type
# => {mobile: 133.0, tv: 412.0, …}

Get yesterday’s estimated_minutes_watched by traffic source:

resource.estimated_minutes_watched since: 1.day.ago, until: 1.day.ago, by: :traffic_source
# => {advertising: 543.0, playlist: 92.0, …}

Get the estimated_minutes_watched for each day of last week:

resource.estimated_minutes_watched since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the estimated_minutes_watched for this and last month:

resource.estimated_minutes_watched since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the estimated_minutes_watched for the whole last week:

resource.estimated_minutes_watched since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the estimated_minutes_watched for the whole last week in Texas only:

resource.estimated_minutes_watched since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the estimated_minutes_watched.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect estimated_minutes_watched by. Accepted values are: :day, :month, :range, :traffic_source,:search_term, :playback_location, :related_video, :embedded_player_location.

  • :includes (Array<Symbol>) — default: [:id]

    if grouped by related video, the parts of each video to eager-load. Accepted values are: :id, :snippet, :status, :statistics, :content_details.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the estimated_minutes_watched to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Symbol, Integer>)

    if grouped by embedded player location, the estimated_minutes_watched for each embedded player location.

  • (Hash<Symbol, Integer>)

    if grouped by playback location, the estimated_minutes_watched for each traffic playback location.

  • (Hash<Yt::Video, Integer>)

    if grouped by related video, the estimated_minutes_watched for each related video.

  • (Hash<Symbol, Integer>)

    if grouped by device type, the estimated_minutes_watched for each device type.

  • (Hash<String, Integer>)

    if grouped by search term, the estimated_minutes_watched for each search term that led viewers to the content.

  • (Hash<String, Integer>)

    if grouped by search term, the estimated_minutes_watched for each search term that led viewers to the content.

  • (Hash<Symbol, Integer>)

    if grouped by traffic source, the estimated_minutes_watched for each traffic source.

  • (Hash<Date, Integer>)

    if grouped by day, the estimated_minutes_watched for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the estimated_minutes_watched for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the estimated_minutes_watched for the entire time-range (under the key :total).



425
# File 'lib/yt/models/video.rb', line 425

has_report :estimated_minutes_watched, Integer

#estimated_revenue(options = {}) ⇒ Hash<Date, Float>, ...

Returns the estimated_revenue grouped by the given dimension.

Examples:

Get the estimated_revenue for each day of last week:

resource.estimated_revenue since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the estimated_revenue for this and last month:

resource.estimated_revenue since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the estimated_revenue for the whole last week:

resource.estimated_revenue since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the estimated_revenue for the whole last week in France only:

resource.estimated_revenue since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the estimated_revenue.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect estimated_revenue by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the estimated_revenue to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Float>)

    if grouped by day, the estimated_revenue for each day in the time-range.

  • (Hash<Range<Date, Date>, Float>)

    if grouped by month, the estimated_revenue for each month in the time-range.

  • (Hash<Symbol, Float>)

    if grouped by range, the estimated_revenue for the entire time-range (under the key :total).



492
# File 'lib/yt/models/video.rb', line 492

has_report :estimated_revenue, Float

#failed?Boolean

Returns whether the video failed to upload.

Returns:

  • (Boolean)

    whether the video failed to upload.



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

def failed?
  status.upload_status == 'failed'
end

#has_failed_conversion?Boolean

Returns whether the video failed to upload to YouTube because YouTube was unable to convert the video.

Returns:

  • (Boolean)

    whether the video failed to upload to YouTube because YouTube was unable to convert the video.



96
97
98
# File 'lib/yt/models/video.rb', line 96

def has_failed_conversion?
  status.failure_reason == 'conversion'
end

#has_public_stats_viewable?Boolean

Returns whether the video statistics are publicly viewable.

Returns:

  • (Boolean)

    if the resource is a video, whether the extended video statistics on the video’s watch page are publicly viewable. By default, those statistics are viewable, and statistics like a video’s viewcount and ratings will still be publicly visible even if this property’s value is set to false.



217
218
219
# File 'lib/yt/models/video.rb', line 217

def has_public_stats_viewable?
  status.public_stats_viewable
end

#hd?Boolean

Returns whether the video is available in high definition.

Returns:

  • (Boolean)

    whether the video is available in high definition.



259
260
261
# File 'lib/yt/models/video.rb', line 259

def hd?
  content_detail.definition == 'hd'
end

#inappropriate?Boolean

Returns whether the video was rejected by YouTube because the video contains inappropriate content.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube because the video contains inappropriate content.



145
146
147
# File 'lib/yt/models/video.rb', line 145

def inappropriate?
  status.rejection_reason == 'inappropriate'
end

#infringes_copyright?Boolean

Returns whether the video was rejected by YouTube because the video commits a copyright infringement.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube because the video commits a copyright infringement.



133
134
135
# File 'lib/yt/models/video.rb', line 133

def infringes_copyright?
  status.rejection_reason == 'copyright'
end

#infringes_trademark?Boolean

Returns whether the video was rejected by YouTube because the video infringes a trademark.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube because the video infringes a trademark.

See Also:



165
166
167
# File 'lib/yt/models/video.rb', line 165

def infringes_trademark?
  status.rejection_reason == 'trademark'
end

#invalid?Boolean

Returns whether the video failed to upload to YouTube because the video uses an unsupported file format.

Returns:

  • (Boolean)

    whether the video failed to upload to YouTube because the video uses an unsupported file format.

See Also:



109
110
111
# File 'lib/yt/models/video.rb', line 109

def invalid?
  status.failure_reason == 'invalidFile'
end

#licensed?Boolean

Returns whether the video represents licensed content, which means that the content has been claimed by a YouTube content partner.

Returns:

  • (Boolean)

    whether the video represents licensed content, which means that the content has been claimed by a YouTube content partner.



270
271
272
# File 'lib/yt/models/video.rb', line 270

def licensed?
  content_detail.licensed_content || false
end

#licensed_as_creative_commons?Boolean

Returns whether the video uses a Creative Commons license.

Returns:

  • (Boolean)

    whether the video uses a Creative Commons license.

See Also:



207
208
209
# File 'lib/yt/models/video.rb', line 207

def licensed_as_creative_commons?
  license == 'creativeCommon'
end

#licensed_as_standard_youtube?Boolean

Returns whether the video uses the Standard YouTube license.

Returns:

  • (Boolean)

    whether the video uses the Standard YouTube license.

See Also:



201
202
203
# File 'lib/yt/models/video.rb', line 201

def licensed_as_standard_youtube?
  license == 'youtube'
end

#likeBoolean

Likes the video on behalf of the authenticated account.

Returns:

  • (Boolean)

    whether the authenticated account likes the video.

Raises:



317
318
319
320
# File 'lib/yt/models/video.rb', line 317

def like
  rating.set :like
  liked?
end

#liked?Boolean

Returns whether the authenticated account likes the video.

Returns:

  • (Boolean)

    whether the authenticated account likes the video.

Raises:



309
310
311
# File 'lib/yt/models/video.rb', line 309

def liked?
  rating.rating == :like
end

#likes(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the likes grouped by the given dimension.

Examples:

Get the likes for each day of last week:

resource.likes since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the likes for this and last month:

resource.likes since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the likes for the whole last week:

resource.likes since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the likes for the whole last week in France only:

resource.likes since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the likes.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect likes by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the likes to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the likes for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the likes for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the likes for the entire time-range (under the key :total).



434
# File 'lib/yt/models/video.rb', line 434

has_report :likes, Integer

#made_for_kids?Boolean

@return [Boolean, nil] This value indicates whether the video is

designated as child-directed, and it contains the current "made for
kids" status of the video.

Returns:

  • (Boolean)


229
230
231
# File 'lib/yt/models/video.rb', line 229

def made_for_kids?
  status.made_for_kids
end

#monetized_playbacks(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the monetized_playbacks grouped by the given dimension.

Examples:

Get the monetized_playbacks for each day of last week:

resource.monetized_playbacks since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the monetized_playbacks for this and last month:

resource.monetized_playbacks since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the monetized_playbacks for the whole last week:

resource.monetized_playbacks since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the monetized_playbacks for the whole last week in France only:

resource.monetized_playbacks since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the monetized_playbacks.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect monetized_playbacks by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the monetized_playbacks to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the monetized_playbacks for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the monetized_playbacks for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the monetized_playbacks for the entire time-range (under the key :total).



498
# File 'lib/yt/models/video.rb', line 498

has_report :monetized_playbacks, Integer

#playback_based_cpm(options = {}) ⇒ Hash<Date, Float>, ...

Returns the playback_based_cpm grouped by the given dimension.

Examples:

Get the playback_based_cpm for each day of last week:

resource.playback_based_cpm since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the playback_based_cpm for this and last month:

resource.playback_based_cpm since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the playback_based_cpm for the whole last week:

resource.playback_based_cpm since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the playback_based_cpm for the whole last week in France only:

resource.playback_based_cpm since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the playback_based_cpm.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect playback_based_cpm by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the playback_based_cpm to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Float>)

    if grouped by day, the playback_based_cpm for each day in the time-range.

  • (Hash<Range<Date, Date>, Float>)

    if grouped by month, the playback_based_cpm for each month in the time-range.

  • (Hash<Symbol, Float>)

    if grouped by range, the playback_based_cpm for the entire time-range (under the key :total).



501
# File 'lib/yt/models/video.rb', line 501

has_report :playback_based_cpm, Float

#processed?Boolean

Returns whether the video has been fully processed by YouTube.

Returns:

  • (Boolean)

    whether the video has been fully processed by YouTube.



73
74
75
# File 'lib/yt/models/video.rb', line 73

def processed?
  status.upload_status == 'processed'
end

#rejected?Boolean

Returns whether the video was rejected by YouTube.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube.



78
79
80
# File 'lib/yt/models/video.rb', line 78

def rejected?
  status.upload_status == 'rejected'
end

#reports(options = {}) ⇒ Hash<Symbol, Hash>

Returns the reports for the given metrics grouped by the given dimension.

Examples:

Get the views and estimated minutes watched by day for last week:

resource.reports only: [:views, :estimated_minutes_watched] since: 1.week.ago, by: :day
# => {views: {Wed, 8 May 2014 => 12, Thu, 9 May 2014 => 34, …}, estimated_minutes_watched: {Wed, 8 May 2014 => 9, Thu, 9 May 2014 => 6, …}}

Parameters:

  • options (Hash) (defaults to: {})

    the metrics, time-range and dimensions for the reports.

Options Hash (options):

  • :only (Array<Symbol>)

    The metrics to generate reports for.

  • :by (Symbol) — default: :day

    The dimension to collect metrics by. Accepted values are: :day, :month.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

Returns:

  • (Hash<Symbol, Hash>)

    the reports for each metric specified.



# File 'lib/yt/models/video.rb', line 419

#scheduled?Boolean

Returns whether the video is scheduled to be published.

Returns:

  • (Boolean)

    whether the video is scheduled to be published.



190
191
192
# File 'lib/yt/models/video.rb', line 190

def scheduled?
  private? && status.publish_at
end

#scheduled_atTime?

Returns the time when a video is scheduled to be published.

Returns:

  • (Time)

    if the video is scheduled to be published, the time when it will become public.

  • (nil)

    if the video is not scheduled to be published.



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

def scheduled_at
  status.publish_at if scheduled?
end

#self_declared_made_for_kids?Boolean

@return [Boolean, nil] In a videos.insert or videos.update request,

this property allows the channel owner to designate the video as
being child-directed. In a videos.list request, the property value
is only returned if the channel owner authorized the API request.

Returns:

  • (Boolean)


237
238
239
# File 'lib/yt/models/video.rb', line 237

def self_declared_made_for_kids?
  status.self_declared_made_for_kids
end

#shares(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the shares grouped by the given dimension.

Examples:

Get the shares for each day of last week:

resource.shares since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the shares for this and last month:

resource.shares since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the shares for the whole last week:

resource.shares since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the shares for the whole last week in France only:

resource.shares since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the shares.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect shares by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the shares to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the shares for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the shares for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the shares for the entire time-range (under the key :total).



440
# File 'lib/yt/models/video.rb', line 440

has_report :shares, Integer

#stereoscopic?Boolean

Returns whether the video is available in 3D.

Returns:

  • (Boolean)

    whether the video is available in 3D.



254
255
256
# File 'lib/yt/models/video.rb', line 254

def stereoscopic?
  content_detail.dimension == '3d'
end

#subscribers_gained(options = {}) ⇒ Hash<Date, Integer>, ...

Note:

This is not the total number of subscribers gained by the video’s channel, but the subscribers gained from the video’s page.

Returns the subscribers_gained grouped by the given dimension.

Examples:

Get the subscribers_gained for each day of last week:

resource.subscribers_gained since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the subscribers_gained for this and last month:

resource.subscribers_gained since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the subscribers_gained for the whole last week:

resource.subscribers_gained since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the subscribers_gained for the whole last week in France only:

resource.subscribers_gained since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the subscribers_gained.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect subscribers_gained by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the subscribers_gained to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the subscribers_gained for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the subscribers_gained for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the subscribers_gained for the entire time-range (under the key :total).



445
# File 'lib/yt/models/video.rb', line 445

has_report :subscribers_gained, Integer

#subscribers_lost(options = {}) ⇒ Hash<Date, Integer>, ...

Note:

This is not the total number of subscribers lost by the video’s channel, but the subscribers lost from the video’s page.

Returns the subscribers_lost grouped by the given dimension.

Examples:

Get the subscribers_lost for each day of last week:

resource.subscribers_lost since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the subscribers_lost for this and last month:

resource.subscribers_lost since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the subscribers_lost for the whole last week:

resource.subscribers_lost since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the subscribers_lost for the whole last week in France only:

resource.subscribers_lost since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the subscribers_lost.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect subscribers_lost by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the subscribers_lost to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the subscribers_lost for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the subscribers_lost for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the subscribers_lost for the entire time-range (under the key :total).



450
# File 'lib/yt/models/video.rb', line 450

has_report :subscribers_lost, Integer

#tagsArray<String>

Returns the list of tags attached to the video.

Returns:

  • (Array<String>)

    the list of tags attached to the video.



51
52
53
# File 'lib/yt/models/video.rb', line 51

def tags
  ensure_complete_snippet :tags
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.

  • (nil)

    if the size is not default, medium or high.



26
# File 'lib/yt/models/video.rb', line 26

delegate :thumbnail_url, to: :snippet

#too_long?Boolean

Returns whether the video was rejected by YouTube because the video exceeds the maximum duration for YouTube.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube because the video exceeds the maximum duration for YouTube.

See Also:



152
153
154
# File 'lib/yt/models/video.rb', line 152

def too_long?
  status.rejection_reason == 'length'
end

#too_small?Boolean

Returns whether the video failed to upload to YouTube because the video file is too small for YouTube.

Returns:

  • (Boolean)

    whether the video failed to upload to YouTube because the video file is too small for YouTube.



115
116
117
# File 'lib/yt/models/video.rb', line 115

def too_small?
  status.failure_reason == 'tooSmall'
end

#unlikeBoolean

Resets the rating of the video on behalf of the authenticated account.

Returns:

  • (Boolean)

    whether the account does not like the video.

Raises:



335
336
337
338
# File 'lib/yt/models/video.rb', line 335

def unlike
  rating.set :none
  !liked?
end

#update(attributes = {}) ⇒ Boolean

Updates the attributes of a video.

Examples:

Update title and description of a video.

video.update title: 'New title', description: 'New description'

Update tags and category ID of a video.

video.update tags: ['new', 'tags'], category_id: '22'

Update status of a video.

video.update privacy_status: 'public', public_stats_viewable: true

Update visibility/license of a video.

video.update embeddable: true, license: :youtube

Update the time when a private video will become public.

video.update publish_at: 3.days.from_now.utc.iso8601(3)

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to update.

Options Hash (attributes):

  • :title (String)

    The new video’s title. Cannot have more than 100 characters. Can include the characters < and >, which are replaced to ‹ › in order to be accepted by YouTube.

  • :description (String)

    The new video’s description. Cannot have more than 5000 bytes. Can include the characters < and >, which are replaced to ‹ › in order to be accepted by YouTube.

  • :tags (Array<String>)

    The new video’s tags. Cannot have more than 500 characters. Can include the characters < and >, which are replaced to ‹ › in order to be accepted by YouTube.

  • :category_id (String)

    The new video’s category ID.

  • :privacy_status (String)

    The new video’s privacy status. Must be one of: private, unscheduled, public.

  • :embeddable (Boolean)

    The new value to specify whether the video can be embedded on other websites.

  • :license (String)

    The new video’s license. Must be one of: youtube, creativeCommon.

  • :public_stats_viewable (Boolean)

    The new value to specify whether the video’s statistics are publicly viewable.

  • :publish_at (Object)

    The new timestamp when the video will be made public. Must be in ISO 8601 format (YYYY-MM-DDThh:mm:ss.sZ).

Returns:

  • (Boolean)

    whether the video was successfully updated.

Raises:



597
598
599
# File 'lib/yt/models/video.rb', line 597

def update(attributes = {})
  super
end

#upload_thumbnail(path_or_url) ⇒ Object

Uploads a thumbnail

Parameters:

  • path_or_url (String)

    the image to upload. Can either be the path of a local file or the URL of a remote file.

Returns:

  • the new thumbnail resource for the given image.

Raises:



544
545
546
547
548
549
550
551
# File 'lib/yt/models/video.rb', line 544

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

#uploading?Boolean

Returns whether the video is being uploaded to YouTube.

Returns:

  • (Boolean)

    whether the video is being uploaded to YouTube.



83
84
85
# File 'lib/yt/models/video.rb', line 83

def uploading?
  status.upload_status == 'uploaded'
end

#uses_unsupported_codec?Boolean

Returns whether the video failed to upload to YouTube because of an unsupported codec.

Returns:

  • (Boolean)

    whether the video failed to upload to YouTube because of an unsupported codec.

See Also:



90
91
92
# File 'lib/yt/models/video.rb', line 90

def uses_unsupported_codec?
  status.failure_reason == 'codec'
end

#videos_added_to_playlists(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the videos_added_to_playlists grouped by the given dimension.

Examples:

Get the videos_added_to_playlists for each day of last week:

resource.videos_added_to_playlists since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the videos_added_to_playlists for this and last month:

resource.videos_added_to_playlists since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the videos_added_to_playlists for the whole last week:

resource.videos_added_to_playlists since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the videos_added_to_playlists for the whole last week in France only:

resource.videos_added_to_playlists since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the videos_added_to_playlists.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect videos_added_to_playlists by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the videos_added_to_playlists to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the videos_added_to_playlists for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the videos_added_to_playlists for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the videos_added_to_playlists for the entire time-range (under the key :total).



453
# File 'lib/yt/models/video.rb', line 453

has_report :videos_added_to_playlists, Integer

#videos_removed_from_playlists(options = {}) ⇒ Hash<Date, Integer>, ...

Returns the videos_removed_from_playlists grouped by the given dimension.

Examples:

Get the videos_removed_from_playlists for each day of last week:

resource.videos_removed_from_playlists since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the videos_removed_from_playlists for this and last month:

resource.videos_removed_from_playlists since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the videos_removed_from_playlists for the whole last week:

resource.videos_removed_from_playlists since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the videos_removed_from_playlists for the whole last week in France only:

resource.videos_removed_from_playlists since: 2.weeks.ago, until: 1.week.ago, by: :range, in: 'FR'
# => {total: 44.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the videos_removed_from_playlists.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect videos_removed_from_playlists by. Accepted values are: :day, :month, :range.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The country to limit the videos_removed_from_playlists to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash with the code in the :country key, such as {country: “US”}.

Returns:

  • (Hash<Date, Integer>)

    if grouped by day, the videos_removed_from_playlists for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the videos_removed_from_playlists for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the videos_removed_from_playlists for the entire time-range (under the key :total).



456
# File 'lib/yt/models/video.rb', line 456

has_report :videos_removed_from_playlists, Integer

#viewer_percentage(options = {}) ⇒ Hash<Symbol, Float>, ...

Returns the viewer_percentage grouped by the given dimension.

Examples:

Get yesterday’s viewer percentage by gender:

resource.viewer_percentage since: 1.day.ago, until: 1.day.ago, by: :gender
# => {female: 53.0, male: 47.0}

Get yesterday’s viewer_percentage grouped by age group:

resource.viewer_percentage since: 1.day.ago, until: 1.day.ago, by: :age_group
# => {"18-24" => 4.54, "35-24" => 12.31, "45-34" => 8.92, …}

Get yesterday’s viewer_percentage by gender and age group:

resource.viewer_percentage since: 1.day.ago, until: 1.day.ago
# => {female: {"18-24" => 12.12, "25-34" => 16.16, …}, male:…}

Get yesterday’s viewer_percentage by gender and age group in France only:

resource.viewer_percentage since: 1.day.ago, until: 1.day.ago, in: 'FR'
# => {female: {"18-24" => 16.12, "25-34" => 13.16, …}, male:…}

Get the viewer_percentage for the whole last week in Texas only:

resource.viewer_percentage since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the viewer_percentage.

Options Hash (options):

  • :by (Symbol) — default: :gender_age_group

    The dimension to show viewer percentage by. Accepted values are: :gender, :age_group, :gender_age_group.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the viewer_percentage to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Symbol, Float>)

    if grouped by gender, the viewer percentage by gender.

  • (Hash<String, Float>)

    if grouped by age group, the viewer percentage by age group.

  • (Hash<Symbol, [Hash<String, Float>]>)

    if grouped by gender and age group, the viewer percentage by gender/age group.



428
# File 'lib/yt/models/video.rb', line 428

has_report :viewer_percentage, Float

#views(options = {}) ⇒ Hash<Symbol, Integer>, ...

Returns the views grouped by the given dimension.

Examples:

Get yesterday’s views by embedded player location:

resource.views since: 1.day.ago, until: 1.day.ago, by: :embedded_player_location
# => {"fullscreen.net" => 92.0, "yahoo.com" => 14.0, …}

Get yesterday’s views grouped by playback location:

resource.views since: 1.day.ago, until: 1.day.ago, by: :playback_location
# => {embedded: 53.0, watch: 467.0, …}
Get yesterday’s views by related video, eager-loading the snippet of each video
resource.views since: 1.day.ago, until: 1.day.ago, by: :related_video, includes: [:snippet]
# => {#<Yt::Video @id=…> => 33.0, #<Yt::Video @id=…> => 12.0, …}

Get yesterday’s views by search term:

resource.views since: 1.day.ago, until: 1.day.ago, by: :search_term
# => {"fullscreen" => 33.0, "good music" => 12.0, …}

Get yesterday’s views by URL that referred to the resource:

resource.views since: 1.day.ago, until: 1.day.ago, by: :referrer
# => {"Google Search" => 33.0, "ytimg.com" => 12.0, …}

Get yesterday’s views by device type:

resource.views since: 1.day.ago, until: 1.day.ago, by: :device_type
# => {mobile: 133.0, tv: 412.0, …}

Get yesterday’s views by traffic source:

resource.views since: 1.day.ago, until: 1.day.ago, by: :traffic_source
# => {advertising: 543.0, playlist: 92.0, …}

Get the views for each day of last week:

resource.views since: 2.weeks.ago, until: 1.week.ago, by: :day
# => {Wed, 8 May 2014 => 12.0, Thu, 9 May 2014 => 34.0, …}

Get the views for this and last month:

resource.views since: 1.month.ago, by: :month
# => {Wed, 01 Apr 2014..Thu, 30 Apr 2014 => 12.0, Fri, 01 May 2014..Sun, 31 May 2014 => 34.0, …}

Get the views for the whole last week:

resource.views since: 2.weeks.ago, until: 1.week.ago, by: :range
# => {total: 564.0}

Get the views for the whole last week in Texas only:

resource.views since: 2.weeks.ago, until: 1.week.ago, by: :range, in: {state: 'TX'}
# => {total: 19.0}

Parameters:

  • options (Hash) (defaults to: {})

    the time-range and dimensions for the views.

Options Hash (options):

  • :by (Symbol) — default: :day

    The dimension to collect views by. Accepted values are: :day, :month, :range, :traffic_source,:search_term, :playback_location, :related_video, :embedded_player_location.

  • :includes (Array<Symbol>) — default: [:id]

    if grouped by related video, the parts of each video to eager-load. Accepted values are: :id, :snippet, :status, :statistics, :content_details.

  • :since (#to_date)

    The first day of the time-range. Also aliased as :from.

  • :until (#to_date)

    The last day of the time-range. Also aliased as :to.

  • :in (<String, Hash>)

    The location to limit the views to. Can either be the two-letter ISO-3166-1 code of a country, such as “US”, or a Hash that either contains the :country key, such as {country: “US”} or the :state key, such as {state: “TX”}. Note that YouTube API only provides data for US states.

Returns:

  • (Hash<Symbol, Integer>)

    if grouped by embedded player location, the views for each embedded player location.

  • (Hash<Symbol, Integer>)

    if grouped by playback location, the views for each traffic playback location.

  • (Hash<Yt::Video, Integer>)

    if grouped by related video, the views for each related video.

  • (Hash<Symbol, Integer>)

    if grouped by device type, the views for each device type.

  • (Hash<String, Integer>)

    if grouped by search term, the views for each search term that led viewers to the content.

  • (Hash<String, Integer>)

    if grouped by search term, the views for each search term that led viewers to the content.

  • (Hash<Symbol, Integer>)

    if grouped by traffic source, the views for each traffic source.

  • (Hash<Date, Integer>)

    if grouped by day, the views for each day in the time-range.

  • (Hash<Range<Date, Date>, Integer>)

    if grouped by month, the views for each month in the time-range.

  • (Hash<Symbol, Integer>)

    if grouped by range, the views for the entire time-range (under the key :total).



422
# File 'lib/yt/models/video.rb', line 422

has_report :views, Integer

#violates_terms_of_use?Boolean

Returns whether the video was rejected by YouTube because the video violates the Terms of Use.

Returns:

  • (Boolean)

    whether the video was rejected by YouTube because the video violates the Terms of Use.



158
159
160
# File 'lib/yt/models/video.rb', line 158

def violates_terms_of_use?
  status.rejection_reason == 'termsOfUse'
end