class Dumper::Profiles::Fakku

Public Instance Methods

dump(url, path, from, to) click to toggle source
# File lib/dumper/profiles/fakku.rb, line 24
def dump(url, path, from, to)
  url    += '/read' unless url.end_with? '/read'
  errors = 0

  js_thumbs_slice = open(url).read.split('window.params.thumbs')[1].split('\/thumbs\/')
  thumbs_count    = js_thumbs_slice[1..-1].count
  cdn             = js_thumbs_slice[0].gsub(/\\\//m, ?/)[5..-1] + '/images/'

  to = thumbs_count if to > thumbs_count
  from.upto(to) { |i|
    return if errors == 3

    file     = "%03d.jpg" % i
    filename =  "#{cdn}#{file}"

    @pool.process {
      unless Dumper.get path, URI.parse(URI.encode(filename, '[]')), { referer: url }
        sleep 3
        errors += 1

        file = File.join(path, file).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
        File.delete(file) if File.exists? file
      end
    }
  }
end