Instantly share code, notes, and snippets.

Embed
What would you like to do?
# https://rudk.ws/2016/10/17/reverse-engineering-by-using-chrome/
require 'open-uri'
require 'uri'
require 'rmagick'
class PhotoDownloader
RESOURCE = 'http://access.nypl.org/image.php/'.freeze
def initialize(id, zoom)
@id = id
@zoom = zoom
@width = @height = 0
end
def save
array = []
loop do
begin
array[@height] = [] unless array[@height]
array[@height] << form_url(@height, @width).read
rescue OpenURI::HTTPError
if array[@height].length.zero?
array.delete_at(@height)
break
end
@height += 1
@width = 0
retry
end
@width += 1
end
array
end
def combine
@image_list = Magick::ImageList.new
@tiles ||= save
verticals = @tiles.map do |tiles|
image_list = Magick::ImageList.new
tiles.each do |tile|
image_list.push(Magick::Image.from_blob(tile).first)
end
@image_list.push(image_list.append(true))
end
@image_list.append(false).write("#{@zoom}_#{@id}.png")
end
private
def form_url(x, y)
uri = URI.join(RESOURCE, "#{@id}/", fetch_tile(x, y))
puts uri
uri
end
def fetch_tile(x = 0, y = 0)
"tiles/0/#{@zoom}/#{x}_#{y}.png"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment