mirror of https://github.com/captn3m0/muse-dl.git
Use response.body, not response.body_io, which is nil when you pass in HTTPClient for some reason.
This commit is contained in:
parent
4e435dd3ab
commit
2206c41228
|
@ -64,7 +64,7 @@ module Muse::Dl
|
||||||
if content_type.is_a? String
|
if content_type.is_a? String
|
||||||
if /html/.match content_type
|
if /html/.match content_type
|
||||||
puts response
|
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/chapter/2383438/pdf
|
||||||
# https://muse.jhu.edu/book/67393
|
# https://muse.jhu.edu/book/67393
|
||||||
# Errors are Unable to determine page runs / Unable to construct chapter PDF
|
# Errors are Unable to determine page runs / Unable to construct chapter PDF
|
||||||
|
@ -75,7 +75,7 @@ module Muse::Dl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
File.open(tmp_pdf_file, "w") do |file|
|
File.open(tmp_pdf_file, "w") do |file|
|
||||||
IO.copy(response.body_io, file)
|
file << response.body
|
||||||
if file.size == 0
|
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"]}")
|
raise Muse::Dl::Errors::DownloadError.new("Error: downloaded chapter file size is zero. Response Content-Length header was #{headers["Content-Length"]}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,19 +78,12 @@ module Muse::Dl
|
||||||
if delay_secs >= 2
|
if delay_secs >= 2
|
||||||
delay_secs /= 2
|
delay_secs /= 2
|
||||||
end
|
end
|
||||||
rescue ex : Muse::Dl::Errors::DownloadError
|
|
||||||
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.
|
|
||||||
sleep(delay_secs)
|
|
||||||
delay_secs *= 2
|
|
||||||
rescue ex
|
rescue ex
|
||||||
puts ex.message
|
puts ex.message
|
||||||
puts ex.backtrace.join("\n ")
|
puts ex.backtrace.join("\n ")
|
||||||
pp ex
|
puts "Error. Skipping book: #{url}. Waiting for #{delay_secs} seconds before continuing."
|
||||||
puts "Non-download error. Skipping book: #{url}."
|
sleep(delay_secs)
|
||||||
sleep(1)
|
delay_secs *= 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif parser.url
|
elsif parser.url
|
||||||
|
|
Loading…
Reference in New Issue