From 58b965c707d43ffbb80faeece567a0165764f606 Mon Sep 17 00:00:00 2001 From: cobodo Date: Mon, 22 Oct 2018 19:37:01 +0900 Subject: [PATCH] =?UTF-8?q?photo=5Fsupport:=20Amazon=E3=81=AE=E5=95=86?= =?UTF-8?q?=E5=93=81URL=E3=81=8B=E3=82=89=E7=94=BB=E5=83=8F=E3=82=92?= =?UTF-8?q?=E5=8F=96=E3=82=8A=E5=87=BA=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/plugin/photo_support/photo_support.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/plugin/photo_support/photo_support.rb b/core/plugin/photo_support/photo_support.rb index f78d04f6..350897c1 100644 --- a/core/plugin/photo_support/photo_support.rb +++ b/core/plugin/photo_support/photo_support.rb @@ -227,4 +227,15 @@ Plugin.create :photo_support do img = Plugin::PhotoSupport.d250g2(display_url) open(img) if img end + + # Amazon + 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]) + end end -- 2.17.1