Class: VgMtvmusic

Inherits:
Object show all
Defined in:
lib/acts_as_unvlogable/vg_mtvmusic.rb

Instance Method Summary collapse

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, options={})
  @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_urlObject



57
58
59
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 57

def download_url
  nil
end

#durationObject



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 embed_html(width=425, height=344, options={})
  "<embed src='#{embed_url}' width='#{width}' height='#{height}' type='application/x-shockwave-flash' flashVars='dist=http://www.mtvmusic.com' allowFullScreen='true' AllowScriptAccess='never'></embed>"
end

#embed_urlObject



42
43
44
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 42

def embed_url
  REXML::XPath.first(@feed, "//media:content[@type='application/x-shockwave-flash']").attributes['url']
end

#flvObject

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

#serviceObject



61
62
63
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 61

def service
  "MTV Music"
end

#thumbnailObject



34
35
36
# File 'lib/acts_as_unvlogable/vg_mtvmusic.rb', line 34

def thumbnail
  REXML::XPath.first(@feed, "//media:thumbnail").attributes['url']
end

#titleObject



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