class Dumper::Profiles::MangaHere

Public Instance Methods

dump(url, path, from, to) click to toggle source
# File lib/dumper/profiles/mangahere.rb, line 24
def dump(url, path, from, to)
  from -=  1
  to   -=  1 if to >= -1

  [].tap { |urls|
    Nokogiri::HTML(open(url)).xpath('//div[@class="detail_list"]/ul/li').each { |u|
      urls << u unless u.at_xpath('.//span/a/@href').to_s.strip.empty?
    }
  }.reverse[from..to].each { |p|
    chapter = p.at_xpath('.//span/a/@href').to_s
    name    = p.at_xpath('.//span/a/text()').to_s.strip

    dir = File.join path, name.sanitize_filename
    Dir.mkdir(dir) unless File.directory? dir

    Nokogiri::HTML(open(chapter)).xpath('//select[@class="wid60"]/option').each { |q|
      @pool.process {
        scan = Nokogiri::HTML(open(q['value'])).xpath('//section[@id="viewer"]/a/img/@src')[0].to_s
        Dumper.get dir, scan, { filename: "#{q.text}.png" }
      }
    }
  }
end