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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/rypper/cli.rb', line 25
def self.main()
opts = self.getopt()
argv = ARGV
if argv.count != 2
puts "USAGE: ruby #{$0} <uri> <selector>"
exit 1
end
uri = Rypper::URI.new(argv[0]) uri.parse!
uri.first!
= nil
= Rypper::Extractor.new(argv[1]) counter = uri.counter[uri.order.last]
puts "Processing #{uri.uri} ..."
while true
html_uri = uri.to_uri
puts " * #{html_uri} ..."
html = Rypper::Loader.get(html_uri)
if html.is_a?(String)
.(html_uri, html).each do |image_uri|
if image_uri.is_a?(String)
image_path = uri.to_path(File.extname(image_uri))
if opts.has_key?(:output)
image_path = File.join(opts[:output], image_path)
end
print " * #{image_uri} --> #{image_path} ..."
if !File.exists?(image_path) || opts.has_key?(:overwrite)
Rypper::Loader.mkdir!(File.dirname(image_path))
image_file = File.open(image_path, 'w')
image_file.binmode
image_file.write(Rypper::Loader.get(image_uri))
image_file.close
puts ' OK'
else
puts ' Exists: Skipping'
end
else
puts ' * Imageless'
end
end
else
counter.last!
puts ' * Last'
end
uri.next!
break if uri.first?
end
puts 'OK'
exit 0
end
|