Class: WWW::VideoScraper::YouTube

Inherits:
Base
  • Object
show all
Defined in:
lib/www/video_scraper/you_tube.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

Raises:



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

def scrape
  page = pass_verify_age
  @title = page.root.at('//head/title').inner_html.sub(/^YouTube[\s-]*/, '') rescue ''
  @embed_tag = page.root.at('//input[@id="embed_code"]').attributes['value'] rescue nil
  page.root.search('//script').each do |script|
    if m = script.inner_html.match(/var\s+swfArgs\s*=\s*([^;]+);/)
      swf_args = JSON::parse(m[1])
      uri = URI.parse(@page_url)
      uri.path = '/get_video'
      uri.query = "video_id=#{swf_args['video_id']}&t=#{swf_args['t']}"
      @video_url = uri.to_s
      @thumb_url = "http://i.ytimg.com/vi/#{swf_args['video_id']}/default.jpg"
    end
  end
  raise FileNotFound, 'file not found' if @video_url.nil?
end