pull/50/head
naquad 11 years ago
parent 6d23cd241a
commit 94ff7609bc

@ -11,6 +11,7 @@ class Downloader < SimpleDelegator
def initialize(*args) def initialize(*args)
super(Hydra.new(*args)) super(Hydra.new(*args))
@counter = 0
end end
def processor(&block) def processor(&block)
@ -53,7 +54,7 @@ class Downloader < SimpleDelegator
def queue(*args, &block) def queue(*args, &block)
run while queue_size > MAX_QUEUE_SIZE run while queue_size > MAX_QUEUE_SIZE
__getobj__(*args, &block) __getobj__.queue *args, &block
end end
def page(src, target) def page(src, target)
@ -82,6 +83,20 @@ class Downloader < SimpleDelegator
end end
end end
base_dir = File.dirname(path)
doc.css('a[href]').each do |a|
href = a['href']
next if href =~ %r{^(?:[^:]+:|[#?]|$)}
href = CGI.unescape(href)
np = File.join(base_dir, href)
if File.exists?("#{np}.html")
href << '.html'
end
a['href'] = href
end
doc.css('style').each do |style| doc.css('style').each do |style|
style.content = process_stylesheet(src, style.content, rdir) style.content = process_stylesheet(src, style.content, rdir)
end end
@ -145,8 +160,6 @@ class Downloader < SimpleDelegator
prefix = 1 prefix = 1
tfile = rfile tfile = rfile
puts rfile
loop do loop do
path = File.join(dir, tfile) path = File.join(dir, tfile)
break path unless File.exists?(path) break path unless File.exists?(path)

Loading…
Cancel
Save