Class: Yt::Models::Annotation
- Inherits:
-
Object
- Object
- Yt::Models::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.
12 13 14 |
# File 'lib/yt/models/annotation.rb', line 12 def initialize( = {}) @data = [:data] end |
Instance Method Details
#above?(y) ⇒ Boolean
Checks whether the entire annotation box remains above y
21 22 23 |
# File 'lib/yt/models/annotation.rb', line 21 def above?(y) top && top < y end |
#below?(y) ⇒ Boolean
Checks whether the entire annotation box remains below y
30 31 32 |
# File 'lib/yt/models/annotation.rb', line 30 def below?(y) bottom && bottom > y end |
#has_invideo_programming? ⇒ Boolean
Checks whether the annotation comes from InVideo Programming
68 69 70 |
# File 'lib/yt/models/annotation.rb', line 68 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
54 55 56 |
# File 'lib/yt/models/annotation.rb', line 54 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.
61 62 63 |
# File 'lib/yt/models/annotation.rb', line 61 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?
38 39 40 |
# File 'lib/yt/models/annotation.rb', line 38 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
46 47 48 |
# File 'lib/yt/models/annotation.rb', line 46 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
75 76 77 |
# File 'lib/yt/models/annotation.rb', line 75 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
82 83 84 |
# File 'lib/yt/models/annotation.rb', line 82 def starts_before?(seconds) .first < seconds if .any? end |