Use response.body, not response.body_io, which is nil when you pass in HTTPClient for some reason.

pull/12/head
Prad Nelluru 3 years ago
parent 4e435dd3ab
commit 2206c41228
  1. 4
      src/fetch.cr
  2. 11
      src/muse-dl.cr

@ -64,7 +64,7 @@ module Muse::Dl
if content_type.is_a? String
if /html/.match content_type
puts response
response.body_io.each_line do |line|
response.body.each_line do |line|
# https://muse.jhu.edu/chapter/2383438/pdf
# https://muse.jhu.edu/book/67393
# Errors are Unable to determine page runs / Unable to construct chapter PDF
@ -75,7 +75,7 @@ module Muse::Dl
end
end
File.open(tmp_pdf_file, "w") do |file|
IO.copy(response.body_io, file)
file << response.body
if file.size == 0
raise Muse::Dl::Errors::DownloadError.new("Error: downloaded chapter file size is zero. Response Content-Length header was #{headers["Content-Length"]}")
end

@ -78,19 +78,12 @@ module Muse::Dl
if delay_secs >= 2
delay_secs /= 2
end
rescue ex : Muse::Dl::Errors::DownloadError
rescue ex
puts ex.message
puts ex.backtrace.join("\n ")
puts "Download error. Skipping book: #{url}. Waiting for #{delay_secs} seconds before continuing."
# Sleep to prevent hammering the server.
puts "Error. Skipping book: #{url}. Waiting for #{delay_secs} seconds before continuing."
sleep(delay_secs)
delay_secs *= 2
rescue ex
puts ex.message
puts ex.backtrace.join("\n ")
pp ex
puts "Non-download error. Skipping book: #{url}."
sleep(1)
end
end
elsif parser.url

Loading…
Cancel
Save