Class: MTV::Video
Overview
This class represents a music video in MTV’s database.
Instance Attribute Summary collapse
-
#artist ⇒ Object
Returns the artist object for the video.
-
#artist_name ⇒ Object
Returns the value of attribute artist_name.
-
#artist_uri ⇒ Object
Returns the value of attribute artist_uri.
-
#category ⇒ Object
Returns the value of attribute category.
-
#content ⇒ Object
Returns the value of attribute content.
-
#credit ⇒ Object
Returns the value of attribute credit.
-
#media_category ⇒ Object
Returns the value of attribute media_category.
-
#media_credits ⇒ Object
Returns the value of attribute media_credits.
-
#media_description ⇒ Object
Returns the value of attribute media_description.
-
#media_duration ⇒ Object
Returns the value of attribute media_duration.
-
#media_expression ⇒ Object
Returns the value of attribute media_expression.
-
#media_keywords ⇒ Object
Returns the value of attribute media_keywords.
-
#media_medium ⇒ Object
Returns the value of attribute media_medium.
-
#media_player_url ⇒ Object
Returns the value of attribute media_player_url.
-
#media_thumbnails ⇒ Object
Returns the value of attribute media_thumbnails.
-
#media_title ⇒ Object
Returns the value of attribute media_title.
-
#media_type ⇒ Object
Returns the value of attribute media_type.
-
#media_url ⇒ Object
Returns the value of attribute media_url.
-
#published ⇒ Object
Returns the value of attribute published.
-
#thumbnails ⇒ Object
Returns the value of attribute thumbnails.
-
#title ⇒ Object
Returns the value of attribute title.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#updated ⇒ Object
Returns the value of attribute updated.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#vid ⇒ Object
Returns the value of attribute vid.
Class Method Summary collapse
-
.find(uid, options = {}) ⇒ Object
Finds a video based on its unique id.
-
.from_artist(artist) ⇒ Object
Finds all videos from a given artist or artist name.
-
.search(term = nil, options = {}) ⇒ Object
Returns an array of videos that match a given search term.
Instance Method Summary collapse
-
#embed_code(options = {}) ⇒ Object
Returns HTML to embed the Flash player for this video anywhere.
-
#initialize(values = {}) ⇒ Video
constructor
Creates a new video, setting all the given hash keys as attributes.
- #inspect ⇒ Object
Methods inherited from Base
#attribute_for_inspect, request
Constructor Details
#initialize(values = {}) ⇒ Video
Creates a new video, setting all the given hash keys as attributes.
Attributes
-
options
- Possible attributes aretitle
,artist_uri
,artist_name
,<tt>published</tt>, <tt>content</tt>, <tt>uri</tt>, <tt>updated</tt>, <tt>media_category</tt>, <tt>media_credits</tt>, <tt>media_description</tt>, <tt>media_duration</tt>, <tt>media_expression</tt>, <tt>media_keywords</tt>, <tt>media_medium</tt>, <tt>media_player_url</tt>, <tt>media_thumbnails</tt>, <tt>media_title</tt>, <tt>media_type</tt>, <tt>media_url</tt>
138 139 140 141 142 |
# File 'lib/mtv/video.rb', line 138 def initialize(values={}) super(values) self.uid = uri.gsub(self.class.base_url + "/video", '').delete '/' unless @uid self.vid = media_url.split(':').last if media_url end |
Instance Attribute Details
#artist ⇒ Object
Returns the artist object for the video.
Examples
MTV::Video.search('mellow gold').first.artist
> #<MTV::Artist name: "Beck">
150 151 152 |
# File 'lib/mtv/video.rb', line 150 def artist @artist end |
#artist_name ⇒ Object
Returns the value of attribute artist_name.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def artist_name @artist_name end |
#artist_uri ⇒ Object
Returns the value of attribute artist_uri.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def artist_uri @artist_uri end |
#category ⇒ Object
Returns the value of attribute category.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def category @category end |
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def content @content end |
#credit ⇒ Object
Returns the value of attribute credit.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def credit @credit end |
#media_category ⇒ Object
Returns the value of attribute media_category.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_category @media_category end |
#media_credits ⇒ Object
Returns the value of attribute media_credits.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_credits @media_credits end |
#media_description ⇒ Object
Returns the value of attribute media_description.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_description @media_description end |
#media_duration ⇒ Object
Returns the value of attribute media_duration.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_duration @media_duration end |
#media_expression ⇒ Object
Returns the value of attribute media_expression.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_expression @media_expression end |
#media_keywords ⇒ Object
Returns the value of attribute media_keywords.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_keywords @media_keywords end |
#media_medium ⇒ Object
Returns the value of attribute media_medium.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_medium @media_medium end |
#media_player_url ⇒ Object
Returns the value of attribute media_player_url.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_player_url @media_player_url end |
#media_thumbnails ⇒ Object
Returns the value of attribute media_thumbnails.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_thumbnails @media_thumbnails end |
#media_title ⇒ Object
Returns the value of attribute media_title.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_title @media_title end |
#media_type ⇒ Object
Returns the value of attribute media_type.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_type @media_type end |
#media_url ⇒ Object
Returns the value of attribute media_url.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def media_url @media_url end |
#published ⇒ Object
Returns the value of attribute published.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def published @published end |
#thumbnails ⇒ Object
Returns the value of attribute thumbnails.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def thumbnails @thumbnails end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def title @title end |
#uid ⇒ Object
Returns the value of attribute uid.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def uid @uid end |
#updated ⇒ Object
Returns the value of attribute updated.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def updated @updated end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def uri @uri end |
#vid ⇒ Object
Returns the value of attribute vid.
4 5 6 |
# File 'lib/mtv/video.rb', line 4 def vid @vid end |
Class Method Details
.find(uid, options = {}) ⇒ Object
Finds a video based on its unique id. It is unlike the intuitive MTV::Artist.uid
, so you usually have to find a video’s uid first through a search or through the artist.
Examples
MTV::Video.find 'hznHivqrbHHDGDAW'
> #<MTV::Video title: "Loser", artist_uri: "http://api.mtvnservices.com/1/artist/beck/">
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mtv/video.rb', line 22 def find(uid, ={}) return uid if uid.is_a? Artist .symbolize_keys! uid = [:uid] || uid response = request "video/#{uid}/" response = hack_empty_response_case(response) raise Error, "That video not found!" if response.nil? || response.empty? parse_one response end |
.from_artist(artist) ⇒ Object
Finds all videos from a given artist or artist name.
Examples
MTV::Video.from_artist(MTV::Artist.find('beck'))
> #<MTV::Video title: "Gamma Ray", artist_uri: "http://api.mtvnservices.com/1/artist/beck/"> ... ]
MTV::Video.from_artist('beck')
> #<MTV::Video title: "Gamma Ray", artist_uri: "http://api.mtvnservices.com/1/artist/beck/"> ... ]
42 43 44 45 46 47 48 |
# File 'lib/mtv/video.rb', line 42 def from_artist(artist) artist_uid = artist.is_a?(Artist) ? artist.uid : string_to_uid(artist) response = request "artist/#{artist_uid}/videos/" raise Error, "No videos found!" if response.nil? || response.empty? parse_many response end |
.search(term = nil, options = {}) ⇒ Object
Returns an array of videos that match a given search term.
Attributes
-
term
- The search term to find a video -
options
-:max_results
and/or:start_index
for pagination.
Examples
MTV::Video.search 'the golden age', :max_results => 1, :start_index => 1
> [#<MTV::Video title: "The Golden Age", artist_uri: "http://api.mtvnservices.com/1/artist/beck/">]
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mtv/video.rb', line 61 def search(term=nil, ={}) .symbolize_keys! params = { :'max-results' => ([:max_results] || 1), :'start-index' => [:start_index] }.reject { |k,v| v.nil? || v.to_s.empty? }.to_query params = "&#{params}" unless params.empty? term = ([:term] || term).to_query('term') response = request "video/search?#{term}#{params}" raise Error, "No videos not found!" if response.nil? || response.empty? parse_many response end |
Instance Method Details
#embed_code(options = {}) ⇒ Object
Returns HTML to embed the Flash player for this video anywhere
Attributes
-
options
- Takes a combination ofwidth
and/orheight
for the Flash playerto specify a certain size (if one is given, the ratio will be calculated for the other value)
Examples
MTV::Video.search('mellow gold').first.
MTV::Video.search('mellow gold').first.(:width => 100)
MTV::Video.search('mellow gold').first.(:width => 57, :height => 943)
166 167 168 169 170 171 172 173 174 |
# File 'lib/mtv/video.rb', line 166 def (={}) [:width] ||= ([:height] ? (([:height]*448).to_f/366).to_i : 448) [:height] ||= ([:width]==448 ? 366 : (([:width]*366).to_f/448).to_i) <<-EOS <embed src="#{media_url}" type="#{media_type}" width="#{[:width]}" height="#{[:height]}" allowFullScreen="true" allowScriptAccess="always" /> EOS end |
#inspect ⇒ Object
176 177 178 179 |
# File 'lib/mtv/video.rb', line 176 def inspect attrs = [:title, :artist_uri].map { |name| "#{name}: #{attribute_for_inspect(name)}" }.compact.join(", ") "#<#{self.class} #{attrs}>" end |