Class: Yt::Models::Annotation
- Inherits:
-
Base
- Object
- Base
- Yt::Models::Annotation
- Defined in:
- lib/yt/models/annotation.rb
Overview
YouTube API V3 does not provide access to video annotations, therefore a legacy XML endpoint is used to retrieve annotations.
Provides methods to interact with YouTube annotations.
Instance Method Summary collapse
-
#above?(y) ⇒ Boolean
Whether the text box surrounding the annotation is completely in the top y% of the video frame.
-
#below?(y) ⇒ Boolean
Whether the text box surrounding the annotation is completely in the bottom y% of the video frame.
-
#has_invideo_programming? ⇒ Boolean
Whether the annotation is an “InVideo Programming”.
-
#has_link_to_playlist? ⇒ Boolean
Whether the annotation includes a link to a playlist, or to a video embedded in a playlist.
-
#has_link_to_same_window? ⇒ Boolean
Whether the annotation includes a link that will open in the current browser window.
-
#has_link_to_subscribe?(options = {}) ⇒ Boolean
Whether the annotation includes a link to subscribe.
-
#has_link_to_video?(options = {}) ⇒ Boolean
Whether the annotation includes a link to a video, either directly in the text, or as an “Invideo featured video”.
-
#initialize(options = {}) ⇒ Annotation
constructor
A new instance of Annotation.
-
#starts_after?(seconds) ⇒ Boolean
Whether the annotation starts after the number of seconds indicated.
-
#starts_before?(seconds) ⇒ Boolean
Whether the annotation starts before the number of seconds indicated.
-
#text ⇒ String
The textual content of the annotation.
Constructor Details
#initialize(options = {}) ⇒ Annotation
Returns a new instance of Annotation.
10 11 12 |
# File 'lib/yt/models/annotation.rb', line 10 def initialize( = {}) @data = [:data] end |
Instance Method Details
#above?(y) ⇒ Boolean
Returns whether the text box surrounding the annotation is completely in the top y% of the video frame.
17 18 19 |
# File 'lib/yt/models/annotation.rb', line 17 def above?(y) top && top < y end |
#below?(y) ⇒ Boolean
Returns whether the text box surrounding the annotation is completely in the bottom y% of the video frame.
24 25 26 |
# File 'lib/yt/models/annotation.rb', line 24 def below?(y) bottom && bottom > y end |
#has_invideo_programming? ⇒ Boolean
Returns whether the annotation is an “InVideo Programming”.
52 53 54 |
# File 'lib/yt/models/annotation.rb', line 52 def has_invideo_programming? type == 'promotion' || type == 'branding' end |
#has_link_to_playlist? ⇒ Boolean
Returns whether the annotation includes a link to a playlist, or to a video embedded in a playlist.
41 42 43 |
# File 'lib/yt/models/annotation.rb', line 41 def has_link_to_playlist? link_class == '2' || text.include?('&list=') end |
#has_link_to_same_window? ⇒ Boolean
Returns whether the annotation includes a link that will open in the current browser window.
47 48 49 |
# File 'lib/yt/models/annotation.rb', line 47 def has_link_to_same_window? link_target == 'current' end |
#has_link_to_subscribe?(options = {}) ⇒ Boolean
Returns whether the annotation includes a link to subscribe.
29 30 31 |
# File 'lib/yt/models/annotation.rb', line 29 def has_link_to_subscribe?( = {}) # TODO: options for which videos link_class == '5' end |
#has_link_to_video?(options = {}) ⇒ Boolean
Returns whether the annotation includes a link to a video, either directly in the text, or as an “Invideo featured video”.
35 36 37 |
# File 'lib/yt/models/annotation.rb', line 35 def has_link_to_video?( = {}) # TODO: options for which videos link_class == '1' || type == 'promotion' end |
#starts_after?(seconds) ⇒ Boolean
This is broken for invideo programming, because they do not have the timestamp in the region, but in the “data” field
Returns whether the annotation starts after the number of seconds indicated.
61 62 63 |
# File 'lib/yt/models/annotation.rb', line 61 def starts_after?(seconds) .first > seconds if .any? end |
#starts_before?(seconds) ⇒ Boolean
This is broken for invideo programming, because they do not have the timestamp in the region, but in the “data” field
Returns whether the annotation starts before the number of seconds indicated.
70 71 72 |
# File 'lib/yt/models/annotation.rb', line 70 def starts_before?(seconds) .first < seconds if .any? end |
#text ⇒ String
Returns the textual content of the annotation.
75 76 77 |
# File 'lib/yt/models/annotation.rb', line 75 def text @text ||= @data['TEXT'] || '' end |