-
-
Save Demeter/1223458 to your computer and use it in GitHub Desktop.
Sotheby's full-size image ripper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Sothebys full-size image ripper. | |
# Gets the full-size images from the lots listed after __END__. | |
# By Henrik Nyh <http://henrik.nyh.se> 2010-12-23 under the MIT license. | |
require "open-uri" | |
# We get an error page if we do not specify a user agent. | |
USER_AGENT = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Media Center PC 4.0; SLCC1; .NET CLR 3.0.04320)" | |
def read_url(url) | |
open(url, "User-Agent" => USER_AGENT).read | |
end | |
DATA.read.each_line do |url| | |
html = read_url(url) | |
image_base_url = html[%r{(http://s7d2\.scene7\.com/is/image/Sothebys/.+?)\?\$}, 1] | |
local_file = "/tmp/sothebys-#{File.basename(image_base_url)}.jpg" | |
# We're not allowed to request larger images than 4000 * 4000 px. | |
image_url = "#{image_base_url}?req=tile&rect=0,0,4000,4000" | |
File.open(local_file, "w") { |f| f.write read_url(image_url) } | |
# ImageMagick - trim background color around image | |
system("convert", local_file, "-trim", local_file) | |
puts "Done: #{local_file}" | |
end | |
__END__ | |
http://www.sothebys.com/app/live/lot/LotDetail.jsp?lot_id=159428750 | |
http://www.sothebys.com/app/live/lot/LotDetail.jsp?lot_id=159377074 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment