require 'cgi' require 'openssl' require 'base64' require 'open-uri' access_id = 'YOUR_ACCESS_ID' secret_id = 'YOUR_SECRET_ID' source_url = ARGV.first timestamp = Time.now.strftime("%Y-%m-%dT%H:%M:%SZ") sig = Base64.encode64(OpenSSL::HMAC::digest(OpenSSL::Digest::Digest.new('SHA1'), secret_id, 'Thumbnail' + timestamp)).strip url = "http://ast.amazonaws.com/Xino?Action=Thumbnail&AWSAccessKeyId=" + access_id url << "&Signature=" + CGI.escape(sig) url << "&Timestamp=" + CGI.escape(timestamp) url << "&Url=" + source_url begin doc = open(url).read rescue puts "Could not access AWS" exit end m = doc.match(/\<aws:thumbnail[^\>]+exists=\"true\"\>(.+?)\<\//i) if m && m[1] thumb_url = m[1] thumb_url.gsub!(/\&/, '&') File.open("#{source_url}.jpg", "w") { |f| f.write open(thumb_url).read } puts "Saved to #{source_url}.jpg" elsif m && m.match(/exists=\"false\"/) puts "No thumbnail for #{source_url}" else puts "Error" end
In other words:
timestamp = Time.now.gmtime.strftime("%Y-%m-%dT%H:%M:%SZ")</timestamp>
Even with this change I'm getting an authentication error; I need to double check my access keys but also the code for computing signatures.
By the way, I can't find the snippets source anymore - I'll trade you the source for a patch for favorites ;)