Last active
October 22, 2018 10:26
-
-
Save cobodo/a462f32cf2b633a98ca19137589e7d6b to your computer and use it in GitHub Desktop.
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
Plugin.create(:photo_support) do | |
amazon_json_regex = %r!'colorImages': { 'initial': (\[.*MAIN.*\])!.freeze | |
defimageopener('Amazon', %r<\Ahttps?://www\.amazon\.(?:co\.jp|com)/(?:.*/)?(?:dp/|gp/product/)[0-9A-Za-z_]+>) do |url| | |
html = HTTPClient.new.get_content(url, [], [['User-Agent', 'mikutter']]) | |
m = amazon_json_regex.match(html) | |
next nil unless m | |
arr = JSON.parse(m[1], symbolize_names: true) | |
main = arr.find {|v| v[:variant] == "MAIN" } | |
open(main[:large]) # :hiRes, :thumb, :large, :lowRes (all variations might be nullable). :main is an array containing other variations of [{url => [width, height]}] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment