Commit 6e5905af authored by 神楽坂玲奈's avatar 神楽坂玲奈

fix

parent 5525f86e
...@@ -130,6 +130,7 @@ module Update ...@@ -130,6 +130,7 @@ module Update
require 'net/http/pipeline' require 'net/http/pipeline'
@thumbnails_left = @thumbnails.size @thumbnails_left = @thumbnails.size
@images_left = @images.size @images_left = @images.size
@error_count = 0
threads = 5.times.collect do threads = 5.times.collect do
thread = Thread.new do thread = Thread.new do
Net::HTTP.start uri.host, uri.port do |http| Net::HTTP.start uri.host, uri.port do |http|
...@@ -141,12 +142,17 @@ module Update ...@@ -141,12 +142,17 @@ module Update
ids.replace @thumbnails.pop(100) ids.replace @thumbnails.pop(100)
reqs = ids.reverse.collect { |id| Net::HTTP::Get.new thumbnail_req.gsub(':id', id.to_s) } reqs = ids.reverse.collect { |id| Net::HTTP::Get.new thumbnail_req.gsub(':id', id.to_s) }
http.pipeline reqs do |res| http.pipeline reqs do |res|
@status.replace "正在下载卡图 (剩余: 缩略#{@thumbnails_left} / 完整#{@images_left})" @status.replace "正在下载卡图 (剩余: 缩略#{@thumbnails_left} / 完整#{@images_left} #{"错误: #{@error_count}" if @error_count > 0})"
@thumbnails_left -= 1 @thumbnails_left -= 1
id = ids.pop id = ids.pop
if res.code[0] == '2' #http 2xx
next if File.file? "ygocore/pics/thumbnail/#{id}.jpg" next if File.file? "ygocore/pics/thumbnail/#{id}.jpg"
content = res.body content = res.body
open("ygocore/pics/thumbnail/#{id}.jpg", 'wb') {|local|local.write content} open("ygocore/pics/thumbnail/#{id}.jpg", 'wb') {|local|local.write content}
else
$log.warn("下载缩略卡图#{id}出错"){res}
@error_count += 1
end
end end
end end
list = @images list = @images
...@@ -155,12 +161,17 @@ module Update ...@@ -155,12 +161,17 @@ module Update
ids.replace @images.pop(100) ids.replace @images.pop(100)
reqs = ids.reverse.collect { |id| Net::HTTP::Get.new image_req.gsub(':id', id.to_s) } reqs = ids.reverse.collect { |id| Net::HTTP::Get.new image_req.gsub(':id', id.to_s) }
http.pipeline reqs do |res| http.pipeline reqs do |res|
@status.replace "正在下载卡图 (剩余: 缩略#{@thumbnails_left} / 完整#{@images_left})" @status.replace "正在下载卡图 (剩余: 缩略#{@thumbnails_left} / 完整#{@images_left} #{"错误: #{@error_count}" if @error_count > 0})"
@images_left -= 1 @images_left -= 1
id = ids.pop id = ids.pop
if res.code[0] == '2' #http 2xx
next if File.file? "ygocore/pics/#{id}.jpg" next if File.file? "ygocore/pics/#{id}.jpg"
content = res.body content = res.body
open("ygocore/pics/#{id}.jpg", 'wb') {|local|local.write content} open("ygocore/pics/#{id}.jpg", 'wb') {|local|local.write content}
else
$log.warn("下载完整卡图#{id}出错"){res}
@error_count += 1
end
end end
end end
rescue rescue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment