Module: WWW::VideoScraper

Defined in:
lib/www/video_scraper.rb,
lib/www/video_scraper/base.rb,
lib/www/video_scraper/veoh.rb,
lib/www/video_scraper/tube8.rb,
lib/www/video_scraper/pornhub.rb,
lib/www/video_scraper/age_sage.rb,
lib/www/video_scraper/eic_book.rb,
lib/www/video_scraper/red_tube.rb,
lib/www/video_scraper/you_porn.rb,
lib/www/video_scraper/you_tube.rb,
lib/www/video_scraper/moro_tube.rb,
lib/www/video_scraper/pornotube.rb,
lib/www/video_scraper/nico_video.rb,
lib/www/video_scraper/dailymotion.rb,
lib/www/video_scraper/ameba_vision.rb,
lib/www/video_scraper/your_file_host.rb,
lib/www/video_scraper/adult_satellites.rb

Defined Under Namespace

Classes: AdultSatellites, AgeSage, AmebaVision, Base, Dailymotion, EicBook, FileNotFound, MoroTube, NicoVideo, NullLogger, Pornhub, Pornotube, RedTube, TryAgainLater, Tube8, Veoh, YouPorn, YouTube, YourFileHost

Constant Summary collapse

VERSION =
'1.0.5'
MODULES_NAME =
%w(adult_satellites age_sage ameba_vision dailymotion eic_book
moro_tube nico_video pornhub pornotube red_tube tube8 veoh
you_porn you_tube your_file_host)
@@modules =
MODULES_NAME.map do |name|
  require File.expand_path(File.join(File.dirname(__FILE__), 'video_scraper', name))
  const_get( name.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } )
end
@@options =
{
  :logger => nil,
  :cache => nil,
}

Class Method Summary collapse

Class Method Details

.configure {|@@options| ... } ⇒ Object

Yields:

Raises:

  • (ArgumentError)


47
48
49
50
# File 'lib/www/video_scraper.rb', line 47

def configure(&proc)
  raise ArgumentError, "Block is required." unless block_given?
  yield @@options
end

.find_module(url) ⇒ Object



52
53
54
# File 'lib/www/video_scraper.rb', line 52

def find_module(url)
  @@modules.find { |mod| mod.valid_url?(url) }
end

.modulesObject



35
36
37
# File 'lib/www/video_scraper.rb', line 35

def modules
  @@nodules
end

.optionsObject



39
40
41
# File 'lib/www/video_scraper.rb', line 39

def options
  @@options
end

.options=(opts) ⇒ Object



43
44
45
# File 'lib/www/video_scraper.rb', line 43

def options=(opts)
  @@options = opts
end

.scrape(url, opt = nil) ⇒ Object

与えられた URL を処理できるモジュールを @@modules から検索して実行する



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/www/video_scraper.rb', line 57

def scrape(url, opt = nil)
  opt = @@options.merge(opt || {})
  opt[:logger] ||= logger
  raise StandardError, "url param is requred" unless url

  logger.info "url: #{url}"
  if mod = find_module(url)
    logger.info "found module: #{mod.to_s}"
    return mod.scrape(url, opt)
  end
  logger.info "unsupport url."
  return nil
rescue TimeoutError, Timeout::Error, Errno::ETIMEDOUT => e
  logger.warn "  Timeout : #{e.to_s}"
  raise TryAgainLater, e.to_s
rescue OpenURI::HTTPError => e
  raise TryAgainLater, e.to_s if e.to_s.match(/50\d/)
  raise FileNotFound, e.to_s if e.to_s.match(/40\d/)
  raise
rescue Exception => e
  logger.error "#{e.class}: #{e.to_s}"
  raise e
end