Class: VgMtvmusic
Instance Method Summary collapse
- #download_url ⇒ Object
- #duration ⇒ Object
- #embed_html(width = 425, height = 344, options = {}) ⇒ Object
- #embed_url ⇒ Object
-
#flv ⇒ Object
this method fails depending on country restrictions.
-
#initialize(url = nil, options = {}) ⇒ VgMtvmusic
constructor
A new instance of VgMtvmusic.
- #service ⇒ Object
- #thumbnail ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(url = nil, options = {}) ⇒ VgMtvmusic
Returns a new instance of VgMtvmusic.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 12 def initialize(url=nil, ={}) @url = url @video_id = @url.query_param('id') || URI.parse(@url).path.split("/")[3] @feed = nil # veeeeeery ugly page = Hpricot(open(url)) searchterms = page.search("//title").first.inner_html.split("Music Video") res = Net::HTTP.get(URI.parse("http://api.mtvnservices.com/1/video/search/?term=#{searchterms[0].gsub(' ', '%20')}")) search = REXML::Document.new(res) entries = search.elements.to_a("//entry") entries.each do |entry| if REXML::XPath.first(entry, "media:content" ).attributes['url'] == "http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:#{@video_id}" @feed = entry end end end |
Instance Method Details
#download_url ⇒ Object
57 58 59 |
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 57 def download_url nil end |
#duration ⇒ Object
38 39 40 |
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 38 def duration nil end |
#embed_html(width = 425, height = 344, options = {}) ⇒ Object
46 47 48 |
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 46 def (width=425, height=344, ={}) "<embed src='#{}' width='#{width}' height='#{height}' type='application/x-shockwave-flash' flashVars='dist=http://www.mtvmusic.com' allowFullScreen='true' AllowScriptAccess='never'></embed>" end |
#embed_url ⇒ Object
42 43 44 |
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 42 def REXML::XPath.first(@feed, "//media:content[@type='application/x-shockwave-flash']").attributes['url'] end |
#flv ⇒ Object
this method fails depending on country restrictions
51 52 53 54 55 |
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 51 def flv res = Net::HTTP.get(URI.parse("http://api-media.mtvnservices.com/player/embed/includes/mediaGen.jhtml?uri=mgid:uma:video:api.mtvnservices.com:#{@video_id}&vid=#{@video_id}&ref=#{CGI::escape "{ref}"}")) search = REXML::Document.new(res) REXML::XPath.first(search, "//rendition/src")[0] end |
#service ⇒ Object
61 62 63 |
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 61 def service "MTV Music" end |
#thumbnail ⇒ Object
34 35 36 |
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 34 def thumbnail REXML::XPath.first(@feed, "//media:thumbnail").attributes['url'] end |
#title ⇒ Object
30 31 32 |
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 30 def title REXML::XPath.first(@feed, "//entry/title")[0].to_s end |