Class: Dumper::Profiles::Fakku

Inherits:
Profile
  • Object
show all
Defined in:
lib/dumper/profiles/fakku.rb

Instance Method Summary collapse

Instance Method Details

#dump(url, path, from, to) ⇒ Object



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
# 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