Class: WWW::VideoScraper::Dailymotion

Inherits:
Base
  • Object
show all
Defined in:
lib/www/video_scraper/dailymotion.rb

Instance Attribute Summary

Attributes inherited from Base

#embed_tag, #page_url, #thumb_url, #title, #video_url

Instance Method Summary collapse

Methods inherited from Base

#initialize, scrape, url_regex, valid_url?

Constructor Details

This class inherits a constructor from WWW::VideoScraper::Base

Instance Method Details

#scrapeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/www/video_scraper/dailymotion.rb', line 10

def scrape
  uri = URI.parse(@page_url)
  html = http_get(@page_url)
  doc = Hpricot(html.toutf8)
  doc.search('//script').each do |elem|
    if m = elem.inner_html.match(/\.addVariable\("video",\s*"([^"]+)"/i)
      path = CGI.unescape(m[1]).split(/\|\||@@/).first
      @video_url = URI.join("#{uri.scheme}://#{uri.host}", path).to_s
    end
    if m = elem.inner_html.match(/\.addVariable\("preview",\s+"([^"]+)"/)
      path = CGI.unescape(m[1]).split(/\|\||@@/).first
      @thumb_url = URI.join("#{uri.scheme}://#{uri.host}", path).to_s
    end
  end
  @title = doc.at('//h1[@class="nav"]').inner_html rescue nil
  @embed_tag = CGI.unescapeHTML(doc.at('//textarea[@id="video_player_embed_code_text"]').inner_html) rescue nil
end