Class: Yt::Annotation
- Inherits:
-
Object
- Object
- Yt::Annotation
- Defined in:
- lib/yt/models/annotation.rb
Overview
Provides methods to access and analyze a single YouTube annotation.
Instance Method Summary collapse
-
#above?(y) ⇒ Boolean
Checks whether the entire annotation box remains above y.
-
#below?(y) ⇒ Boolean
Checks whether the entire annotation box remains below y.
-
#has_invideo_programming? ⇒ Boolean
Checks whether the annotation comes from InVideo Programming.
-
#has_link_to_playlist? ⇒ Boolean
Checks whether there is a link to a playlist.
-
#has_link_to_same_window? ⇒ Boolean
Checks whether the link opens in the same window.
-
#has_link_to_subscribe?(options = {}) ⇒ Boolean
Checks whether there is a link to subscribe.
-
#has_link_to_video?(options = {}) ⇒ Boolean
Checks whether there is a link to a video.
-
#initialize(options = {}) ⇒ Annotation
constructor
Instantiate an Annotation object from its YouTube XML representation.
-
#starts_after?(seconds) ⇒ Boolean
have the timestamp in the region, but in the “data” field.
-
#starts_before?(seconds) ⇒ Boolean
have the timestamp in the region, but in the “data” field.
Constructor Details
#initialize(options = {}) ⇒ Annotation
There is no documented way to access annotations through API. There is an endpoint that returns an XML in an undocumented format, which is here parsed into a comprehensible set of attributes.
Instantiate an Annotation object from its YouTube XML representation.
11 12 13 |
# File 'lib/yt/models/annotation.rb', line 11 def initialize( = {}) @data = [:data] end |
Instance Method Details
#above?(y) ⇒ Boolean
Checks whether the entire annotation box remains above y
20 21 22 |
# File 'lib/yt/models/annotation.rb', line 20 def above?(y) top && top < y end |
#below?(y) ⇒ Boolean
Checks whether the entire annotation box remains below y
29 30 31 |
# File 'lib/yt/models/annotation.rb', line 29 def below?(y) bottom && bottom > y end |
#has_invideo_programming? ⇒ Boolean
Checks whether the annotation comes from InVideo Programming
67 68 69 |
# File 'lib/yt/models/annotation.rb', line 67 def has_invideo_programming? type == 'promotion' || type == 'branding' end |
#has_link_to_playlist? ⇒ Boolean
Checks whether there is a link to a playlist. A link to a video with the playlist in the URL also counts
53 54 55 |
# File 'lib/yt/models/annotation.rb', line 53 def has_link_to_playlist? link_class == '2' || text.include?('&list=') end |
#has_link_to_same_window? ⇒ Boolean
Checks whether the link opens in the same window.
60 61 62 |
# File 'lib/yt/models/annotation.rb', line 60 def has_link_to_same_window? link_target == 'current' end |
#has_link_to_subscribe?(options = {}) ⇒ Boolean
Checks whether there is a link to subscribe. Should a branding watermark also counts, because it links to the channel?
37 38 39 |
# File 'lib/yt/models/annotation.rb', line 37 def has_link_to_subscribe?( = {}) # TODO: options for which videos link_class == '5' end |
#has_link_to_video?(options = {}) ⇒ Boolean
Checks whether there is a link to a video. An Invideo featured video also counts
45 46 47 |
# File 'lib/yt/models/annotation.rb', line 45 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
74 75 76 |
# File 'lib/yt/models/annotation.rb', line 74 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
81 82 83 |
# File 'lib/yt/models/annotation.rb', line 81 def starts_before?(seconds) .first < seconds if .any? end |