Class: WWW::VideoScraper::YourFileHost
- Defined in:
- lib/www/video_scraper/your_file_host.rb
Defined Under Namespace
Classes: BandwidthAllowanceExceeded, MaximumVideoPlaysReached, NoFileCategory
Instance Attribute Summary
Attributes inherited from Base
#embed_tag, #page_url, #thumb_url, #video_url
Instance Method Summary collapse
- #filename ⇒ Object (also: #title)
- #scrape ⇒ Object
Methods inherited from Base
#initialize, scrape, url_regex, valid_url?
Constructor Details
This class inherits a constructor from WWW::VideoScraper::Base
Instance Method Details
#filename ⇒ Object Also known as: title
14 15 16 17 18 |
# File 'lib/www/video_scraper/your_file_host.rb', line 14 def filename uri = URI.parse(@page_url) q = CGI.parse(uri.query) q['file'][0] end |
#scrape ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/www/video_scraper/your_file_host.rb', line 21 def scrape html = http_get(@page_url) doc = Hpricot(html.toutf8) if elem = doc.at('//object[@id="objectPlayer"] //param[@name="movie"]') value = elem.attributes['value'] raise StandardError, 'video information is not found' unless value v = CGI::parse(value) if request_url = v['video'][0] response_body = http_get(request_url) q = CGI::parse(response_body) @thumb_url = q['photo'][0] rescue '' @video_url = q['video_id'][0] rescue '' end elsif elem = doc.at('//object[@id="VIDEO"] //param[@name="URL"]') @video_url = elem.attributes['value'] else if html =~ /MAXIMUM VIDEO PLAYS REACHED/i raise MaximumVideoPlaysReached, 'MAXIMUM VIDEO PLAYS REACHED' elsif html =~ /Bandwidth Allowance exceeded/i raise BandwidthAllowanceExceeded, 'Bandwidth Allowance exceeded' elsif html =~ /url=error\.php\?err=8/i raise FileNotFound, 'file not found' elsif html =~ /url=error\.php\?err=5/i or html =~ /no file category/i raise NoFileCategory, 'no file category' elsif html =~ /File not found/i raise FileNotFound, 'file not found' else raise TryAgainLater, 'scrape failed' end end end |